質問編集履歴
1
変更したから
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
ThreejsでTHREE.BoxGeometryの1面にだけTextureを貼るには
|
test
CHANGED
@@ -1,43 +1,149 @@
|
|
1
|
-
下記の
|
1
|
+
下記なのですが、canvasをtextureに使用しています。BoxGeometryの6面すべてにtextureが表示されていますが、これを前面(1面)のみにしたいのですがどうすればいいでしょうか?
|
2
2
|
|
3
|
-
```h
|
3
|
+
```threejs
|
4
4
|
|
5
|
-
<
|
5
|
+
<!DOCTYPE html>
|
6
6
|
|
7
|
-
|
7
|
+
<head>
|
8
8
|
|
9
|
-
|
9
|
+
<meta charset="utf-8">
|
10
10
|
|
11
|
-
|
11
|
+
<script src="https://d3js.org/d3.v5.min.js"></script>
|
12
12
|
|
13
|
-
|
13
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/105/three.min.js"></script>
|
14
14
|
|
15
|
-
|
15
|
+
</head>
|
16
16
|
|
17
|
-
d
|
17
|
+
<body>
|
18
18
|
|
19
|
-
|
19
|
+
<script>
|
20
20
|
|
21
|
-
|
21
|
+
var camera, scene, renderer, geometry, texture, mesh;
|
22
|
-
|
23
|
-
.on("drag", dragged)
|
24
|
-
|
25
|
-
.on("end", dragended)
|
26
|
-
|
27
|
-
);
|
28
|
-
|
29
|
-
```
|
30
|
-
|
31
|
-
そして大きくしたり小さくしたりした後に、
|
32
|
-
|
33
|
-
元の動作のドラックでブラウザがスクロールに戻したいのですが、どうすればいいでしょうか?
|
34
22
|
|
35
23
|
|
36
24
|
|
37
|
-
|
25
|
+
function makeCanvas(){
|
38
26
|
|
27
|
+
const width = 200;
|
28
|
+
|
29
|
+
const height = 200;
|
30
|
+
|
31
|
+
const canvas = d3.create("canvas")
|
32
|
+
|
33
|
+
.attr("width", width)
|
34
|
+
|
35
|
+
.attr("height", height)
|
36
|
+
|
37
|
+
.attr("style","background-color:#ffd700")
|
38
|
+
|
39
|
+
const context = canvas.node().getContext("2d");
|
40
|
+
|
41
|
+
context.fillStyle = "#000000";
|
42
|
+
|
43
|
+
context.fillRect(0, 0, width, height);
|
44
|
+
|
45
|
+
context.fillStyle = "#ffd700";
|
46
|
+
|
47
|
+
context.fillRect(1, 1, width-2, height-2);
|
48
|
+
|
49
|
+
context.textAlign = "center";
|
50
|
+
|
51
|
+
context.textBaseline = "middle";
|
52
|
+
|
53
|
+
context.fillStyle = "#C19F4F";
|
54
|
+
|
55
|
+
context.font = "bold 20px 'MS ゴシック'";
|
56
|
+
|
57
|
+
context.fillText("999.9", width/2, height/2-40, width);
|
58
|
+
|
59
|
+
context.font = "bold 50px 'MS ゴシック'";
|
60
|
+
|
39
|
-
|
61
|
+
context.fillText("GOLD", width/2, height/2, width);
|
40
62
|
|
41
63
|
|
42
64
|
|
65
|
+
return canvas.node();
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
function init() {
|
72
|
+
|
73
|
+
var width = window.innerWidth, height = window.innerHeight;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
renderer = new THREE.WebGLRenderer();
|
78
|
+
|
79
|
+
renderer.setSize(width, height);
|
80
|
+
|
81
|
+
document.body.appendChild(renderer.domElement);
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
scene = new THREE.Scene();
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
camera = new THREE.PerspectiveCamera(70, width / height, 1, 1000);
|
90
|
+
|
91
|
+
camera.position.z = 400;
|
92
|
+
|
93
|
+
camera.position.y = 200;
|
94
|
+
|
95
|
+
camera.position.x = 10;
|
96
|
+
|
97
|
+
camera.lookAt(scene.position);
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
scene.add(camera);
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
texture = new THREE.Texture(makeCanvas());
|
106
|
+
|
43
|
-
|
107
|
+
texture.minFilter = THREE.LinearFilter;
|
108
|
+
|
109
|
+
var material = new THREE.MeshBasicMaterial({ map: texture});
|
110
|
+
|
111
|
+
geometry = new THREE.BoxGeometry( 200, 200, 200 );
|
112
|
+
|
113
|
+
mesh = new THREE.Mesh( geometry, material );
|
114
|
+
|
115
|
+
scene.add( mesh );
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
animate();
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
function animate() {
|
126
|
+
|
127
|
+
requestAnimationFrame(animate);
|
128
|
+
|
129
|
+
texture.needsUpdate = true;
|
130
|
+
|
131
|
+
mesh.rotation.y += 0.01;
|
132
|
+
|
133
|
+
renderer.render(scene, camera);
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
window.onload = init;
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
</script>
|
144
|
+
|
145
|
+
</body>
|
146
|
+
|
147
|
+
</html>
|
148
|
+
|
149
|
+
```
|