Collada import normals issue
by Matthew Genge · in Torque 3D Professional · 07/07/2012 (11:13 am) · 7 replies
Dear All,
I am trying to import a Collada model into Torque3D but am having some difficulties. Specifically the normals are rendered incorrectly (the model is mostly inside out). The model was generated by some code I wrote (so the problem is of my own making). However, the definition of the mesh appears to be compliant with Collada 1.4.1 and it imports just fine into Blender, just not into Torque3d.
Anyway, I am relatively new to Collada and have probably messed up my export function somewhere. The geometry definition is shown below. It doesn't throw any errors when imported into Torque3d. You can see I am using a polylist element with each vertex having its own normals and UV coordinates (the later are fine). This is the simplest method to export the data...but perhaps it isn't correct? If you are a Collada expert and have any suggestions...you could help end several days of frustration.
Many thanks,
Matt
I am trying to import a Collada model into Torque3D but am having some difficulties. Specifically the normals are rendered incorrectly (the model is mostly inside out). The model was generated by some code I wrote (so the problem is of my own making). However, the definition of the mesh appears to be compliant with Collada 1.4.1 and it imports just fine into Blender, just not into Torque3d.
Anyway, I am relatively new to Collada and have probably messed up my export function somewhere. The geometry definition is shown below. It doesn't throw any errors when imported into Torque3d. You can see I am using a polylist element with each vertex having its own normals and UV coordinates (the later are fine). This is the simplest method to export the data...but perhaps it isn't correct? If you are a Collada expert and have any suggestions...you could help end several days of frustration.
<library_geometries>
<geometry id="branch0-mesh" name="branch0">
<mesh>
<source id="branch0-Pos">
<float_array id="branch0-Pos-array" count="60">
0.000000 0.000000 -0.500000
0.980000 0.000000 0.000000
0.481000 0.833116 0.000000
-0.542000 0.938771 0.000000
-0.966000 -0.000000 0.000000
-0.415000 -0.718801 0.000000
0.525000 -0.909327 0.000000
0.377653 0.101132 9.999793
0.100124 0.367905 10.010077
-0.302327 0.301959 10.011292
-0.367024 -0.101186 9.999612
-0.081476 -0.318830 9.990750
0.298033 -0.293974 9.988476
0.083303 -0.302851 19.994808
0.082603 -0.302179 19.994835
0.081588 -0.302345 19.994839
0.081425 -0.303362 19.994808
0.082145 -0.303911 19.994785
0.083102 -0.303848 19.994781
0.082358 -0.303108 19.994808
</float_array>
<technique_common>
<accessor source="#branch0-Pos-array" count="20" stride="3">
<param name="X" type="float" />
<param name="Y" type="float" />
<param name="Z" type="float" />
</accessor>
</technique_common>
</source>
<source id="branch0-Normal">
<float_array id="branch0-Normal-array" count="180">
0.000000 0.000000 -1.000000
0.999695 -0.024706 0.000000
0.502668 0.864479 0.000000
-0.516979 0.855998 0.000000
-0.999699 -0.024529 0.000000
-0.497077 -0.867707 0.000000
0.482777 -0.875743 0.000000
0.999695 -0.024706 0.000000
0.502668 0.864479 0.000000
-0.516980 0.855998 0.000000
-0.999699 -0.024529 0.000000
-0.497077 -0.867707 0.000000
0.482777 -0.875743 0.000000
0.999695 -0.024706 0.000000
0.502668 0.864479 0.000000
-0.516980 0.855998 0.000000
-0.999699 -0.024529 0.000000
-0.497077 -0.867707 0.000000
0.482777 -0.875743 0.000000
0.000000 0.000000 1.000000
</float_array>
<technique_common>
<accessor source="#branch0-Normal-array" count="20" stride="3">
<param name="X" type="float" />
<param name="Y" type="float" />
<param name="Z" type="float" />
</accessor>
</technique_common>
</source>
<source id="branch0-map">
<float_array id="branch0-map-array" count="40">
0.500000 0.500000
-1.000000 0.000000
-0.666667 0.000000
-0.333333 0.000000
0.000000 0.000000
-0.333333 0.000000
-0.666667 0.000000
-1.000000 3.183193
-0.666667 3.183193
-0.333333 3.183193
0.000000 3.183193
-0.333333 3.183193
-0.666667 3.183193
-1.000000 6.366385
-0.666667 6.366385
-0.333333 6.366385
0.000000 6.366385
-0.333333 6.366385
-0.666667 6.366385
0.500000 0.500000
</float_array>
<technique_common>
<accessor source="#branch0-mesh-array" count="20" stride="2">
<param name="S" type="float" />
<param name="T" type="float" />
</accessor>
</technique_common>
</source>
<vertices id="branch0-Vtx">
<input semantic="POSITION" source="#branch0-Pos"/>
</vertices>
<polylist count="30" material="Material0-branch-polys">
<input semantic="VERTEX" source="#branch0-Vtx" offset="0"/>
<input semantic="NORMAL" source="#branch0-Normal" offset="1"/>
<input semantic="TEXCOORD" source="#branch0-map" offset="2" set="0"/>
<vcount>3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3</vcount>
<p>0 0 0 2 2 2 1 1 1 0 0 0 3 3 3 2 2 2 0 0 0 4 4 4 3 3 3 0 0 0 5 5 5 4 4 4 0 0 0 6 6 6 5 5 5 0 0 0 1 1 1 6 6 6 1 1 1 2 2 2 7 7 7 2 2 2 8 8 8 7 7 7 2 2 2 3 3 3 8 8 8 3 3 3 9 9 9 8 8 8 3 3 3 4 4 4 9 9 9 4 4 4 10 10 10 9 9 9 4 4 4 5 5 5 10 10 10 5 5 5 11 11 11 10 10 10 5 5 5 6 6 6 11 11 11 6 6 6 12 12 12 11 11 11 6 6 6 1 1 1 12 12 12 1 1 1 7 7 7 12 12 12 7 7 7 8 8 8 13 13 13 8 8 8 14 14 14 13 13 13 8 8 8 9 9 9 14 14 14 9 9 9 15 15 15 14 14 14 9 9 9 10 10 10 15 15 15 10 10 10 16 16 16 15 15 15 10 10 10 11 11 11 16 16 16 11 11 11 17 17 17 16 16 16 11 11 11 12 12 12 17 17 17 12 12 12 18 18 18 17 17 17 12 12 12 7 7 7 18 18 18 7 7 7 13 13 13 18 18 18</p>
</polylist>
</mesh>
</geometry>
</library_geometries>Many thanks,
Matt
About the author
I am an Earth Scientist who likes writing games for fun.
#2
07/07/2012 (8:39 pm)
Yes, you will want single sided or you end up with potentially rendering polygons you cannot see. So it is a good idea to make sure the face normals are facing outward.
#3
07/08/2012 (3:11 am)
As he says the model is being generated by code, it's a coding problem not a modeling problem.
#4
Many thanks. Yes, I've written my own code to generate the meshes and then export them as collada.
It turns out the materials were being created automatically on import as double-sided by default. All I needed to do was manually set them as single-sided and they display fine. Cheers for the solution.
Best,
Matt
07/08/2012 (4:34 am)
Guys,Many thanks. Yes, I've written my own code to generate the meshes and then export them as collada.
It turns out the materials were being created automatically on import as double-sided by default. All I needed to do was manually set them as single-sided and they display fine. Cheers for the solution.
Best,
Matt
#5
Also, I know you are generating the model, but you could also import into Blender to troubleshoot your models. It has a large number of tools that are much more sophisticated than the tools in T3D.
This sounds cool. What kind of meshes are you generating?
07/08/2012 (3:40 pm)
Is that something you can correct in your code?Also, I know you are generating the model, but you could also import into Blender to troubleshoot your models. It has a large number of tools that are much more sophisticated than the tools in T3D.
This sounds cool. What kind of meshes are you generating?
#6
07/08/2012 (10:19 pm)
Also, if normals are reversed polysoup collisions may not work as expected.... Or, I guess they will work as expected, but it might not be what you want.
#7
I found that removing the following lines in the material library definitions in the collada file ensure the model is imported properly. Apparantley torque3d creates materials using this definition if there is no materials.cs file.
and
My app is to create tree meshes.
07/09/2012 (3:13 am)
Hi All,I found that removing the following lines in the material library definitions in the collada file ensure the model is imported properly. Apparantley torque3d creates materials using this definition if there is no materials.cs file.
<transparent>
<color sid="transparent">1.000000 1.000000 1.000000 1.000000</color>
</transparent>
<transparency>
<float sid="transparency">0.000000</float>
</transparency>and
<extra><technique profile="MAX3D"><double_sided>1</double_sided></technique></extra>
My app is to create tree meshes.
Torque Owner DreamPharaoh
Gods and Nemesis
You can also go into the materials editor in Torque and select double sided for the material you assigned to the model and it should fix it visually, but this may come back to haunt you later if you don't just find the culprit normals in blender and flip them to begin with, assuming you are using blender.