当使用jquery将转换为.DAE文件的3D模型加载到页面中心的目标div中时,div中会显示单词和数字列表而不是3D模型。
我正在尝试使用jquery将3D模型(.DAE文件)加载到目标div中,当按下左下方的一个按钮时,然后当按下另一个按钮时我想让div中显示的模型改变
按下两个按钮的屏幕截图如下所示。 - 3D模型应显示在div中,而不是显示的文本列表中。
Screenshot of when Load Blood Cell button is pressed
Screenshot of when Load Egg Cell button is pressed
我正在使用的代码如下所示。任何帮助都非常感激。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#LBC').click(function() {
$('#target').load('blood.DAE');
});
$('#LEC').click(function() {
$('#target').load('egg2.DAE');
});
});
</script>
<title>Visualising Cells</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<script src="three.js"></script>
<script src="ColladaLoader.js"></script>
</head>
<body>
<script src="js/controls/OrbitControls.js"></script>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.01, 500 );
camera.position.z = 0.16;
camera.position.x = 0;
camera.position.y = 0;
scene.add(camera);
var renderer=new THREE.WebGLRenderer();
renderer.setSize(width,height);
document.body.appendChild(renderer.domElement);
renderer.render(scene,camera);
renderer.setClearColor("rgb(181,181,181)");
light = new THREE.DirectionalLight(0xffffff);
light.position.set(1, 1, 1);
scene.add(light);
light = new THREE.DirectionalLight(0xffffff);
light.position.set(0, 0, 0.14);
scene.add(light);
var loader = new THREE.ColladaLoader();
loader.load('blood.DAE', function (collada) {
object = collada.scene;
object.position.x = 0;
object.position.y = 0;
object.position.z = 0;
object.updateMatrix();
}
);
document.addEventListener('keydown', function(event) {
console.log("Up Arrow Pressed");
console.log(camera.position.z);
if (event.keyCode == 38) {
if (camera.position.z >= 0.1) {
camera.position.z = camera.position.z - 0.01;
}
}
else if (event.keyCode == 40) {
console.log("Down Arrow Pressed")
if (camera.position.z < 0.2) {
camera.position.z = camera.position.z + 0.01;
}
}
}, true);
render = function () {
requestAnimationFrame(render);
object.rotation.x += 0.01;
object.rotation.y += 0.01;
renderer.render(scene, camera);
};
render();
</script>
<div class="float-btn">
<button type="button" id="LBC">Load Red Blood Cell</button>
<button type="button" id="LEC">Load Egg Cell</button>
</div>
<div class="float-txt">
<div style="color:#000000">
<div style="font-family: Arial">
<div style="font-size: 18px">
<div style="text-decoration: underline">
<h1>Visualising Microscopic Cells</h1>
</div>
<div class="instructions">
<div style="color:#000000">
<div style="font-family: Arial">
<div style="font-size: 16px">
<div style="text-decoration: underline">
<h2>Instructions</h2>
</div>
<div class="instruction-txt">
<div style="color:#000000">
<div style="font-family: Arial">
<div style="font-size: 14px">
<p><u>Zoom In:</u> <strong>Up Arrow</strong> <br><u>Zoom Out:</u> <strong>Down Arrow</strong></br></p>
</div>
<div class="Model-Location" id="target">
</div>
</body>
</html>