Light problem with loaded “obj” file.

Software: Away3D 4.x

erroneous seth, Newbie
Posted: 16 October 2011 09:09 PM   Total Posts: 28

Hello to everyone,

I load an “obj” model exported by Blender. The model is rendered just fine.

However, when I try to apply lighting a problem occurs. Specifically:

1. I create a PointLight,
2. I create a ColorMaterial for the model
3. apply the light to the material (material.lights = [light])

When I run the application the error #2007 (parameter data must be non-null) occurs.

I am pretty sure that there is something wrong with the model. Could someone please help me?

I have attached: the source code, the “obj” & “blend” files, the (detailed) error message.


Thanks a lot!

 

File Attachments
track_test.rar  (File Size: 58KB - Downloads: 0)
   

erroneous seth, Newbie
Posted: 17 October 2011 01:13 AM   Total Posts: 28   [ # 1 ]

The debugger of FlashBuilder shows that in the method “calcDependencies” of class “DefaultScreenPass” the variable “_numLights” is 1 so the loop starts.

But, for some reason, the reference “_lights[0]” is null.

Don’t take the above into account. My bad.

   

Richard Olsson, Administrator
Posted: 17 October 2011 09:52 AM   Total Posts: 1192   [ # 2 ]

Sounds like (without looking at the code/file) your file does not have vertex normals, and for some reason they’re not being calculated automatically. Can you try manually setting the autoDeriveVertexNormals and autoDeriveVertexTangents properties to true on each sub-geometry in each geometry of the meshes that get loaded?

for (i=0; i<myMesh.geometry.subGeometries.length; i++)
  myMesh.geometry.subGeometries.autoDeriveVertexNormals = true;

   

erroneous seth, Newbie
Posted: 17 October 2011 08:52 PM   Total Posts: 28   [ # 3 ]

Thank you for your answer.

It works. “autoDeriveVertexNormals” works.

However, as I understand, the framerate drops because the engine has to calculate the normals.

So, I should probably have Blender create the normals and put them in the “.obj” file. What I don’t understand is why didn’t this happen in the first place.

Well, anyway… thanks, again! I’ll try with Blender. Now that I know the source of the problem:-)

   

Avatar
Choons, Sr. Member
Posted: 17 October 2011 09:08 PM   Total Posts: 281   [ # 4 ]

in the original post you say you are using a ColorMaterial. Unless things have changed, it’s my understanding that ColorMaterial is always flat shading?

   

erroneous seth, Newbie
Posted: 18 October 2011 01:07 AM   Total Posts: 28   [ # 5 ]
Richard Olsson - 17 October 2011 09:52 AM

your file does not have vertex normals

The problem is solved. It was my big mistake to not make Blender export the normals in the “.obj” file:shut: Thank you and sorry!

   

erroneous seth, Newbie
Posted: 18 October 2011 01:11 AM   Total Posts: 28   [ # 6 ]
Choons - 17 October 2011 09:08 PM

it’s my understanding that ColorMaterial is always flat shading

Yes, I guess you are right.

However, the line of code that reported an error was:

material.lights [light]

Adding a light to the material caused an error. That was because the material was, later, assigned to a loaded model of the “.obj” format with no normals in the “.obj” file:bug:

A silly mistake on my part:red:

   

Richard Olsson, Administrator
Posted: 18 October 2011 07:29 AM   Total Posts: 1192   [ # 7 ]

ColorMaterials have (roughly) the same shading possibilities as BitmapMaterial. It’s not always flat shading (as in per-polygon shading).

The autoDeriveVertexNormals property should not slow down your framerate, because it only happens once (as long as the geometry never changes.) However, lighting might affect your framerate somewhat, depending on what kind of hardware you have. So you should be seeing the same framerate regardless of whether your normals came from the original model (the OBJ file) or through autoDeriveVertexNormals.

Please let us know (and post demos) if this isn’t the case.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X