THREE.ExtrudeGeometryの表面と裏面と側面にTextureを貼りたいのですがうまくいきません。単なる単色になってしまいます。ググるとUVGeneratorを指定するみたいなことが書いてありTHREE.ExtrudeGeometry.BoundingBoxUVGeneratorを指定したのですが相変わらず単なる単色です。どうすればTextureをうまく張ることができるでしょうか?
下記は歪なハート型のshapeです。テクスチャがちゃんと張り付かないコードです。どこが間違っているでしょうか?
javascript
1<script type="text/javascript"> 2function init() { 3 var scene = new THREE.Scene(); 4 var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000); 5 var webGLRenderer = new THREE.WebGLRenderer(); 6 webGLRenderer.setClearColor(new THREE.Color(0xEEEEEE)); 7 webGLRenderer.setSize(window.innerWidth, window.innerHeight); 8 webGLRenderer.shadowMap.enabled = true; 9 10 var options = { 11 amount: 2, 12 bevelThickness: 2, 13 bevelSize: 0.5, 14 bevelEnabled: true, 15 bevelSegments: 3, 16 bevelEnabled: true, 17 curveSegments: 12, 18 steps: 1 19 }; 20 21 shape = createMesh(new THREE.ExtrudeGeometry(drawShape(), options)); 22 23 scene.add(shape); 24 25 camera.position.x = -80; 26 camera.position.y = 54; 27 camera.position.z = 80; 28 camera.lookAt(new THREE.Vector3(60, -60, 0)); 29 30 var ambientLight = new THREE.AmbientLight(0x0c0c0c); 31 scene.add(ambientLight); 32 33 var spotLight = new THREE.SpotLight(0xffffff); 34 spotLight.position.set(-70, -20, 170); 35 spotLight.castShadow = true; 36 scene.add(spotLight); 37 38 spotLight.target = shape; 39 40 scene.add(spotLight); 41 42 document.getElementById("WebGL-output").appendChild(webGLRenderer.domElement); 43 44 orbit = new THREE.OrbitControls(camera, webGLRenderer.domElement); 45 46 var step = 0; 47 48 render(); 49 50 function drawShape() { 51 var xy = new Array(); 52 xy.push(["M", 75, 40]); 53 xy.push(["C", 75, 37, 70, 25, 50, 25]); 54 xy.push(["C", 20, 25, 20, 62.5, 20, 62.5]); 55 xy.push(["C", 20, 80, 40, 102, 75, 120]); 56 xy.push(["C", 110, 102, 130, 80, 130, 62.5]); 57 xy.push(["C", 130, 62.5, 130, 25, 100, 25]); 58 xy.push(["C", 85, 25, 75, 37, 75, 40]); 59 xy.push(["Z", 75, 40]); 60 61 var shapepath = new THREE.Shape(); 62 for (var i = 0; i < xy.length; i++) { 63 if (xy[i][0] == "M") { 64 shapepath.moveTo(xy[i][1], xy[i][2]); 65 } else if (xy[i][0] == "L") { 66 shapepath.lineTo(xy[i][1], xy[i][2]); 67 } else if (xy[i][0] == "C") { 68 shapepath.bezierCurveTo(xy[i][1], xy[i][2], xy[i][3], xy[i][4], xy[i][5], xy[i][6]); 69 } else { //Z 70 shapepath.lineTo(xy[0][1], xy[0][2]); 71 } 72 } 73 return shapepath; 74 } 75 76 function createMesh(geom) { 77 geom.applyMatrix(new THREE.Matrix4().makeTranslation(-75, -70, 0)); 78 const texture = new THREE.TextureLoader().load('abc.jpg'); 79 const mat = new THREE.MeshBasicMaterial({ 80 map: texture 81 }); 82 var mesh = new THREE.Mesh(geom, mat); 83 mesh.rotation.z = Math.PI; 84 return mesh; 85 } 86 87 function render() { 88 shape.rotation.y = step += 0.005; 89 requestAnimationFrame(render); 90 webGLRenderer.render(scene, camera); 91 } 92 93} 94window.onload = init; 95</script>
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/12/12 13:48