mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.09k stars 35.34k forks source link

Collada Shader/Lighting Question #1184

Closed jayfield1979 closed 12 years ago

jayfield1979 commented 12 years ago

Thanks for the Collada export advice... works perfectly but it leads me to another question:

http://ix3.lincoln.ac.uk/js3d/Development/test4.html

The scene above has been created in MAX and exported as OpenCollada format. The issue is with the lighting/surface properties. The 2 boxes are separate meshes but positioned right next to each other and I want them to appear "connected" but as you move them around, the lighting/shading is causing them to appear as 2 separate boxes. I need to maintain their independence so I can animate the one while the other stays still.

Any suggestions as how I can approach either modelling, exporting, materials, lighting to achieve the desired result?

alteredq commented 12 years ago

Looks like your vertex normals are smooth shaded.

Try making them flat shaded in Max, or override material shading propery to THREE.FlatShading after loading model in JS.

jayfield1979 commented 12 years ago

Thanks for the reply. Flat shading did fix the issue however I think I provided an overly simplified example as I actually need smoothing. Try this:

http://ix3.lincoln.ac.uk/js3d/Development/test4.html

There's now a model which highlights the problem better. It's a little Lego car that was built piece by piece and, after some optimisation (removing no-visible polygons), all the pieces were attached to become a single mesh with the exception of the doors, steering wheel and wheel (as I need these to animate).

For example, the doors should feature the same shading as the solid block of white underneath them (except for when the curve of the door starts towards the hinge).

Basically I want to recreate this:

http://ix3.lincoln.ac.uk/js3d/Development/car.png

Even if I import the models separately, the issue will still apply. I love this 3D JS implementation and if I can get a solution to this issue I can start working on my project.

alteredq commented 12 years ago

Seems like your vertex normals are getting messed up somewhere. This model has mixture of flat and smooth shaded normals, so you must preserve originally baked vertex normals, they cannot be recomputed automatically.

You can try to import your model in some other software (e.g. Blender or MeshLab) to see if the problem is in Collada exporter or in Collada loader.

alteredq commented 12 years ago

Also see #347

jayfield1979 commented 12 years ago

I have imported the model into Blender and it looks fine. I have followed the instructions for exporting from Blender to OBJ (from the Python script read me) but I have no idea how to run the Python script sorry... I am a designer and new to this. Can you give me a few tips on how to execute the convert_obj_three.py script please?

alteredq commented 12 years ago

First you need to get Python working on your computer (we use version 2.x):

http://python.org/download/

Then you should be able to run the script from the command line like this:

python convert_obj_three.py -i infile.obj -o outfile.js

(assuming your OBJ + MTL files are in the same folder as converter script)

jayfield1979 commented 12 years ago

Thanks! That seems to be better!