-1
我是jsc3d的新用戶。我在互聯網上沒有找到任何工作示例。 我想在jsc3d中隱藏或顯示stl模型並點擊chechbutton。任何人都可以幫我完成我的代碼。用chechbutton隱藏/顯示模型(jsc3d)
非常感謝。
這裏是我的代碼: https://github.com/humu2009/jsc3d/issues/174
感謝您的答覆。但是下面的代碼仍然不起作用。你有什麼想法,爲什麼?
</HEAD>
<script src="/m/raw-attachment/wiki/WikiStart/jsc3d.min.js"></script>
<script src="/m/raw-attachment/wiki/WikiStart/jsc3d.touch.js"></script>
<script src="/m/raw-attachment/wiki/WikiStart/jsc3d.webgl.js"></script>
</HEAD>
<BODY>
<div style="width:800px; margin:auto; position:relative;">
<canvas id="cv" style="border: 1px solid;" width="750" height="400">
</canvas>
<form action="">
<label>
<input type='checkbox' onclick='toggleShapeGreen(this.checked);'>Toggle Shape Green
</label>
<label>
<input type='checkbox' onclick='toggleShapeBlueViolet(this.checked);'>Toggle Shape Blue Violet
</label>
<label>
<input type='checkbox' onclick='toggleShapeBlue2(this.checked);'>Toggle Shape Blue 2
</label>
</form>
</div>
<script type="text/javascript">
var canvas = document.getElementById('cv');
var viewer = new JSC3D.Viewer(canvas);
var components = ['/m/raw-attachment/wiki/WikiStart/shape_green.stl', '/m/raw-attachment/wiki/WikiStart/shape_blue_violet.stl', '/m/raw-attachment/wiki/WikiStart/shape_blue.2.stl'];
var colors = [0xff0000, 0x0000ff, 0x00ff00, 0xffff00, 0x00ffff];
var theScene = new JSC3D.Scene;
var numOfLoaded = 0;
var onModelLoaded = function(scene) {
var meshes = scene.getChildren();
for (var i=0; i<meshes.length; i++) {
meshes[i].name = scene.srcUrl;
theScene.addChild(meshes[i]);
if (meshes.length > 0)
meshes[0].setMaterial(new JSC3D.Material('red-material', 0, colors[numOfLoaded]));
}
if (++numOfLoaded == components.length)
viewer.replaceScene(theScene);
};
function getMeshIndexByName(name) {
var meshes = viewer.scene.getChildren();
for (var i=0, l=meshes.length; i<l; i++) {
if (meshes[i].name == name) {
return i;
}
}
return null;
}
function toggleShapeGreen(checked) {
viewer.scene.children[0].visible = checked;
viewer.update();
}
function toggleShapeBlueViolet(checked) {
viewer.scene.children[1].visible = checked;
viewer.update();
}
function toggleShapeBlue2(checked) {
viewer.scene.children[2].visible = checked;
viewer.update();
}
function toggleShapeGreen(checked) {
viewer.scene.children[getMeshIndexByName("shape_green.stl")].visible = checked;
viewer.update();
}
function toggleShapeBlueViolet(checked) {
viewer.scene.children[getMeshIndexByName("shape_blue_violet.stl")].visible = checked;
viewer.update();
}
function toggleShapeBlue2(checked) {
viewer.scene.children[getMeshIndexByName("shape_blue.2.stl")].visible = checked;
viewer.update();
}
viewer.setParameter('ModelColor', '#FF0000');
viewer.setParameter('BackgroundColor1', '#E5D7BA');
viewer.setParameter('BackgroundColor2', '#383840');
viewer.setParameter('RenderMode', 'flat');
viewer.setParameter('Renderer', 'webgl');
viewer.init();
viewer.update();
</script>
</BODY>
看看我的新問題。謝謝。 – medo93