jackyoyyf / jsc3d

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

Change color with button #58

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 change the modelcolor with a button.

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

Please provide any additional information below.

<canvas id="cv" width="350" height="350" ></canvas></br>
<button id="yellow" onclick="modelcolor('#FFFF00');" 
style="background-color:#FFFF00;width:30px;height:30px;border-color:#cccccc;bord
er-width:1px;"></button>
<button id="red" onclick="modelcolor('#FF0000');" 
style="background-color:#FF0000;width:30px;height:30px;border-color:#cccccc;bord
er-width:1px;"></button></br>
Render quality:
<button id="low_quality" onclick="setDefinition('low');">Low</button>
<button id="standard_quality" 
onclick="setDefinition('standard');">Standard</button>
<button id="high_quality" onclick="setDefinition('high');">High</button></br>

<script type="text/javascript" 
src="http://jsc3d.googlecode.com/svn/trunk/jsc3d/jsc3d.js"></script>
    <script type="text/javascript" src="http://jsc3d.googlecode.com/svn/trunk/jsc3d/jsc3d.touch.js"></script>
    <script type="text/javascript">
    var canvas = document.getElementById('cv');
    var viewer = new JSC3D.Viewer(canvas);
    viewer.setParameter('SceneUrl', '3d/model.stl');
    viewer.setParameter('InitRotationX', 40);
    viewer.setParameter('InitRotationY', 40);
    viewer.setParameter('InitRotationZ', 30);
    viewer.setParameter('ModelColor', '#004B91');
    viewer.setParameter('BackgroundColor1', '#F6f6f6');
    viewer.setParameter('BackgroundColor2', '#CCCCCC');
    viewer.setParameter('RenderMode', 'texturesmooth');
    viewer.init();
    viewer.update();

    function modelcolor(color) {
        var mesh = viewer.getScene().getChildren()[0];
            mesh.setMaterial(new JSC3D.Material('', 0, color, 0, true));
        viewer.update();
    };

    function setDefinition(definition) {
        if(viewer.getScene()) {
            viewer.setDefinition(definition);
            viewer.update();
        }
    };
  </script>

Original issue reported on code.google.com by ilse...@gmail.com on 27 Jan 2014 at 11:27

GoogleCodeExporter commented 9 years ago
Your color value should be a number rather than a string:

  onclick="modelcolor('#FFFF00');"

  =>

  onclick="modelcolor(0xFFFF00);"

Original comment by Humu2...@gmail.com on 28 Jan 2014 at 4:13

GoogleCodeExporter commented 9 years ago
It works! Thanks for helping me out!

Original comment by ilse...@gmail.com on 28 Jan 2014 at 7:51