Skip to content

Commit

Permalink
Merge pull request #37 from yosuke/master
Browse files Browse the repository at this point in the history
convert material for primitive shapes (ref #36)
  • Loading branch information
fkanehiro committed Sep 4, 2015
2 parents 3da33e5 + 091b9d8 commit 735c1db
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
29 changes: 29 additions & 0 deletions simtrans/sdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,35 @@ def readShape(self, d):
m.data.radius = float(g.find('radius').text)
else:
raise Exception('unsupported shape type: %s' % g.tag)
materiald = d.find('material')
if materiald is not None:
material = model.MaterialModel()
diffuseset = False
ambient = materiald.find('ambient')
if ambient is not None:
material.ambient = numpy.array([float(v) for v in re.split(' +', ambient.text.strip(' '))])
diffuse = materiald.find('diffuse')
if diffuse is not None:
material.diffuse = numpy.array([float(v) for v in re.split(' +', diffuse.text.strip(' '))])
diffuseset = True
specular = materiald.find('specular')
if specular is not None:
material.specular = numpy.array([float(v) for v in re.split(' +', specular.text.strip(' '))])
emission = materiald.find('emission')
if emission is not None:
material.emission = numpy.array([float(v) for v in re.split(' +', emission.text.strip(' '))])
if diffuseset == False:
if emission is not None:
material.diffuse = material.emission
logging.warn("diffuse color not set. use emission color instead")
elif specular is not None:
material.diffuse = material.specular
logging.warn("diffuse color not set. use specular color instead")
elif ambient is not None:
material.diffuse = material.ambient
logging.warn("diffuse color not set. use ambient color instead")
if type(m.data) not in [model.MeshData]:
m.data.material = material
return m


Expand Down
30 changes: 23 additions & 7 deletions simtrans/template/vrml.wrl
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,40 @@ Transform {
Inline {
url "{{shapefilemap[v.name]}}"
}
{%- elif v.shapeType == ShapeModel.SP_SPHERE %}
{%- else %}
Shape {
{%- if v.data.material is not none %}
appearance Appearance {
material Material {
diffuseColor {{v.data.material.diffuse[0]}} {{v.data.material.diffuse[1]}} {{v.data.material.diffuse[2]}}
{%- if v.data.material.specular is not none %}
specularColor {{v.data.material.specular[0]}} {{v.data.material.specular[1]}} {{v.data.material.specular[2]}}
{%- endif %}
{%- if v.data.material.emission is not none %}
emissiveColor {{v.data.material.emission[0]}} {{v.data.material.emission[1]}} {{v.data.material.emission[2]}}
{%- endif %}
}
{%- if v.data.material.texture is not none %}
texture ImageTexture {
url "{{v.data.material.texture}}"
}
{%- endif %}
}
{%- endif %}
{%- if v.shapeType == ShapeModel.SP_SPHERE %}
geometry Sphere {
radius {{v.data.radius}}
}
}
{%- elif v.shapeType == ShapeModel.SP_BOX %}
Shape {
{%- elif v.shapeType == ShapeModel.SP_BOX %}
geometry Box {
size {{v.data.x}} {{v.data.y}} {{v.data.z}}
}
}
{%- elif v.shapeType == ShapeModel.SP_CYLINDER %}
Shape {
{%- elif v.shapeType == ShapeModel.SP_CYLINDER %}
geometry Cylinder {
radius {{v.data.radius}}
height {{v.data.height}}
}
{%- endif %}
}
{%- endif %}
]
Expand Down

0 comments on commit 735c1db

Please sign in to comment.