<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>three.js从入门到精通系列教程037 - 采用混合材质制作圆环节</title>
<script src="ThreeJS/three.js"></script>
<script src="ThreeJS/jquery.js"></script>
<script src="ThreeJS/SceneUtils.js"></script>
</head>
<body>
<center id="myContainer"></center>
<script>
//创建渲染器
var myRenderer = new THREE.WebGLRenderer({ antialias: true });
myRenderer.setSize(window.innerWidth, window.innerHeight);
myRenderer.setClearColor('white', 1.0);
$("#myContainer").append(myRenderer.domElement);
var myScene = new THREE.Scene();
var myCamera = new THREE.PerspectiveCamera(45,
window.innerWidth / window.innerHeight, 0.1, 1000);
myCamera.near = 30;
myCamera.far = 50;
myCamera.updateProjectionMatrix();
myCamera.position.set(-20, 8.4, 37.6);
myCamera.lookAt(new THREE.Vector3(0, 0, 0));
//创建圆环结
var myGeometry = new THREE.TorusKnotGeometry(8, 3, 500, 60, 2, 7);
//创建深度材质
var myMeshDepthMaterial = new THREE.MeshDepthMaterial();
//创建绿色材质
var myMeshBasicMaterial = new THREE.MeshBasicMaterial({
color: 0x00ff00, transparent: true, blending: THREE.MultiplyBlending
});
//混合两种材质
var myMesh = new THREE.SceneUtils.createMultiMaterialObject(
myGeometry, [myMeshDepthMaterial, myMeshBasicMaterial]);
myScene.add(myMesh);
//渲染圆环结
myRenderer.render(myScene, myCamera);
</script>
</body>
</html>