我已经将3ds max中的3D模型转换为collada文件,然后使用three.js和collada加载器我希望将其导入我的网站。这样做时,模型的形状会出现但材质不会出现,它是空白的。我不知道为什么它不工作,任何帮助都非常感激。我到目前为止的代码可以在下面看到。
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#button').click(function() {
$('blood.DAE').toggle();
});
});
</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>
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('egg.DAE', function (collada) {
object = collada.scene;
object.position.x = 0;
object.position.y = 0;
object.position.z = 0;
object.updateMatrix();
scene.add(object);
}
);
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">Load Red Blood Cell</button>
<button type="button">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>
</body>
</html>