#!/usr/bin/env python
# -*- coding: utf-8 -*-


from enum import Enum

import numpy as np


class Status(Enum):
    material = 1
    point = 2
    index = 3


class Vrml(object):
    def __init__(self):
        self.diffuse_color = None
        self.specular_color = None
        self.ambient_intensity = None
        self.shininess = None
        self.points = []
        self.indexes = []

    def load(self, fp):
        """VRML ファイルを読み込む処理"""
        status = Status.material
        self.points = []
        self.indexes = []
        for l in fp:
            # コメント行の読み飛ばし
            l = l.strip()
            if l.startswith('#'):
                continue
            items = tuple(filter(lambda i: i != '', l.split(' ')))
            if len(items) == 0:
                continue

            if items[0] in ('diffuseColor', 'specularColor',
                            'ambientIntensity', 'shininess',):
                if items[0] == 'diffuseColor':
                    self.diffuse_color = np.array(
                        tuple(map(float, items[1:4])), dtype=np.float64)
                elif items[0] == 'specularColor':
                    self.specular_color = np.array(
                        tuple(map(float, items[1:4])), dtype=np.float64)
                elif items[0] == 'shininess':
                    self.shininess = float(items[1])
                elif items[0] == 'ambientIntensity':
                    self.ambient_intensity = float(items[1])
            elif items[0] == 'point':
                status = Status.point
                continue
            elif items[0] == 'coordIndex':
                status = Status.index
                continue

            if (status is Status.point and
                    len(items) == 3 and
                    items[2].endswith(',')):
                l = [float(i.replace(',', '')) for i in items]
                self.points.append(np.array(l, dtype=np.float64))

            if status is Status.index and len(items) == 4:
                self.indexes.append(
                    [int(i.replace(',', '')) for i in items[:3]])
@@ -85,16 +85,38 @@
 as np%0A%0A%0A
+DOUBLE = np.float64%0A%0A%0A
 class St
@@ -822,115 +822,383 @@
  if 
-items%5B0%5D in ('diffuseColor', 'specularColor',%0A                            'ambientIntensity', 'shininess',)
+status is Status.point and len(items) == 3:%0A                l = %5Bfloat(i.replace(',', '')) for i in items%5D%0A                self.points.append(np.array(l, dtype=DOUBLE))%0A            elif status is Status.index and len(items) == 4:%0A                self.indexes.append(%0A                    %5Bint(i.replace(',', '')) for i in items%5B:3%5D%5D)%0A            elif status is Status.material
 :%0A  
@@ -1350,34 +1350,30 @@
 4%5D)), dtype=
-np.float64
+DOUBLE
 )%0A          
@@ -1525,26 +1525,22 @@
 , dtype=
-np.float64
+DOUBLE
 )%0A      
@@ -1750,34 +1750,32 @@
 1%5D)%0A            
-el
 if items%5B0%5D == '
@@ -1836,35 +1836,8 @@
     
-    continue%0A            el
 if i
@@ -1902,450 +1902,4 @@
 ndex
-%0A                continue%0A%0A            if (status is Status.point and%0A                    len(items) == 3 and%0A                    items%5B2%5D.endswith(',')):%0A                l = %5Bfloat(i.replace(',', '')) for i in items%5D%0A                self.points.append(np.array(l, dtype=np.float64))%0A%0A            if status is Status.index and len(items) == 4:%0A                self.indexes.append(%0A                    %5Bint(i.replace(',', '')) for i in items%5B:3%5D%5D)

Update Vrml