encima / jsc3d

Automatically exported from code.google.com/p/jsc3d
0 stars 0 forks source link

Set color by loading a object #56

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?
I want to set the color of a object, when the object is loading

What version of the product are you using? On what operating system?

Please provide any additional information below.

viewer = new JSC3D.Viewer(document.getElementById('canvas'));
    viewer.setParameter('SceneUrl', '../duckie/' + duckAccessoires);
    viewer.setParameter('ModelColor', '#FFFFFF');
    viewer.setParameter('BackgroundColor1', '#FFFFFF');
    viewer.setParameter('BackgroundColor2', '#FFFFFF');
    viewer.setParameter('RenderMode', 'textureSmooth');
    viewer.setParameter('setDefinition', 'high');

    viewer.init();

            getDuckColor();

function getDuckColor (){
              color= #FFFFFF;

                var setColor = new JSC3D.Material('', 0, color, 0, true);
                setColor.onready = function() {
                    var scene = viewer.getScene();
                    var myMesh = scene.getChildren()[0];
                    myMesh.setMaterial(this);
                    viewer.update();
                }
            }

Original issue reported on code.google.com by papa...@gmail.com on 12 Jan 2014 at 12:34

GoogleCodeExporter commented 9 years ago
Simply override viewer.onloadingcomplete() method, in which create a new 
material with the given color and set it to your mesh:

  viewer.onloadingcomplete = function() {
    // this assumes your scene contains only a single mesh
    var mesh = viewer.getScene().getChildren()[0];
    mesh.setMaterial(new JSC3D.Material('', 0, the_given_color, 0, true));
  };

and it will be ok.

Original comment by Humu2...@gmail.com on 13 Jan 2014 at 9:07