three.js从入门到精通系列教程037 - 采用混合材质制作圆环节

发布时间:2024年01月22日
<!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>

文章来源:https://blog.csdn.net/smartsmile2012/article/details/135743333
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。