Directional lights are always tricky, because if they don’t hit the target, it looks like they don’t work. My advice, use PositionLight, at least for testing.
The things I’ve altered are as follows:
1. The lights direction ((-1000000, -1000000, -1000000) !!!!!)
Away is expecting a normalised vector, values -1 to 1
2. The lights position. I suspect the light was inside you model (0,0,0), as you haven’t given it any position.
3. I’ve applied the light to the material.
4. Changed light’s diffuse and specular levels, just to make the lighting effect easier to see.
If that doesn’t work, there may be something wrong with you .obj file.
Good Luck!
rgbox, Newbie Posted: 03 October 2011 09:59 AM Total Posts: 12
[ # 2 ]
Thank you, theMightyAtom!
Unfortunately your varaint works the same - only if light is not attached to the material. If light is attached to the material - the error appears.
Still I’m not sure how to give new material to all loaded object parts.
For some other simple models this code works fine, with and without lights. Current model works without lights only.
theMightyAtom, Sr. Member Posted: 03 October 2011 11:27 AM Total Posts: 669
[ # 3 ]
Everything points towards a parsing error of the model, i.e. the variant of .obj exported by Cinema 4D differs from the .obj format expected by Away3D.
I had some issues with 3D Studio, until I changed to another .obj exporter.
When you export from Cinema 4D, what options do you have?
Make sure you don’t export materials, if you are applying them in away3D.
(that could be a cause of your current problem). And make sure you are exporting to triangles, although you wouldn’t even be getting this far if you didn’t
I have a deadline myself this afternoon, but I will try and check your source later,
Cheers!
rgbox, Newbie Posted: 03 October 2011 11:33 AM Total Posts: 12
[ # 4 ]
In fact, the model exported from Cinema 4D does not work at all. I import it to 3d max and export back to OBJ.
theMightyAtom, Sr. Member Posted: 03 October 2011 11:34 AM Total Posts: 669
[ # 5 ]
Couldn’t resist taking a peak!
Should it look like the screenshot attached?
Compiled and ran without problems, and it does use the material library correctly. Incidentally the model seems to be from 3D studio…
Make sure you are using the latest build of Away3D and the latest Flash player!
Cheers
rgbox, Newbie Posted: 03 October 2011 11:39 AM Total Posts: 12
[ # 6 ]
Did you turn the lights on? - uncommented the line:
// mtr.lights = [_light3];
Yes, this model was reexported from 3d max
rgbox, Newbie Posted: 03 October 2011 11:41 AM Total Posts: 12
[ # 7 ]
Yes that is the correct model.
I wonder why new material is not applied (it should be all blue)
theMightyAtom, Sr. Member Posted: 03 October 2011 11:57 AM Total Posts: 669
[ # 8 ]
A quick scan in 3D studio and I can see the problem. The model is corrupt.
Some faces are facing one way, some the other. you could repair it, but it would take hours as there’s no “automatic repair” button :(
I tried other models with your code and they work fine. Although this is a complex shape, it is a single mesh and would normally be quite simple to use in Away3D.
Sorry I can’t be more helpful, but if 3D Studio can’t render it correctly, there’s not much hope for Away3D to render it either.
You could try exporting from Cinema4D in a different format (Collada maybe?) as it can be that the obj exporter is causing the issue.
Good Luck!
(notice missing triangles and inverted faces (dark ones))
rgbox, Newbie Posted: 03 October 2011 12:01 PM Total Posts: 12
[ # 9 ]
theMightyAtom,
Thank you very much!
Your help is very important to me!
I’ll look for other options to export models
80prozent, Sr. Member Posted: 03 October 2011 12:10 PM Total Posts: 430
[ # 10 ]
hi
if you use cinema 4d r10 or earlier, you can try exporting via riptide-pro-obj-plugin (its free for this versions. its available for later versions too, but not for free).
hope that helps
rgbox, Newbie Posted: 12 October 2011 06:00 AM Total Posts: 12
[ # 11 ]
One problem I found and solved was normals.
Setting autoDeriveVertexNormals=true makes this model work with lights.
Another problem not solved:
I do not know how to apply new material if loaded file contains a number of objects. I made a recursion setSub(Msh), but it does not work for all objects - some parts do not obtain new material. Can you suggest a solution?
private function setSub(Msh) { var mtr = new ColorMaterial(0x0000ff, 1) mtr.ambientColor = 0x0000ff mtr.lights = [_light3]; var nc = Msh.numChildren if (nc>0) { for (var i=0; i<nc; i++) { var subMesh = Mesh(Msh.getChildAt(i)); subMesh.material = mtr; for (var sg=0; sg<subMesh.geometry.subGeometries.length; sg++) { subMesh.geometry.subGeometries[sg].autoDeriveVertexNormals = true; } setSub(subMesh) } } }
theMightyAtom, Sr. Member Posted: 12 October 2011 06:12 AM Total Posts: 669
[ # 12 ]
Firstly, realise that _container is not a Mesh.
That makes your code read funny, although it would still work.
So what you are calling a subMesh, is actually just a Mesh, inside your loader.
Apart from that, I can’t see the problem. Applying a material to a Mesh, should apply the material to all it’s submeshes.
I suspect again that it is the model, rather than the code that is causing the trouble.
rgbox, Newbie Posted: 12 October 2011 03:16 PM Total Posts: 12
[ # 13 ]
subMesh starts on _container (that is a Loader3D) children. That is correct. The problem is that some of details cannot be found as _container children, at least their material does not change.