场景
new THREE.Scene()
相机
new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000)
渲染器
new THREE.WebGLRenderer()
坐标轴
new THREE.AxesHelper(20)
平面
new THREE.PlaneGeometry(60, 20, 1, 1)
// 设置投影
plane.receiveShadow = true;
物体(三个)
new THREE.BoxGeometry(4, 4, 4)
new THREE.MeshLambertMaterial( { color: 0x00ff00} )
new THREE.Mesh( geometry, material )
// 设置投影
cube.castShadow = true;
光源
new THREE.SpotLight( 0xffffff )
// 设置投影
spotLight.castShadow = true;
methods: {
getTextCanvas(text) {
var width = 512, height = 256;
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#C3C3C3';
ctx.fillRect(0, 0, width, height);
ctx.font = 50 + 'px " bold';
ctx.fillStyle = '#2891FF';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(text, width / 2, height / 2);
return canvas;
},
},
mounted() {
......
this.material = [
new THREE.MeshBasicMaterial({ color: '#fff' }), // right
new THREE.MeshBasicMaterial({ map: texture, }), // left
new THREE.MeshBasicMaterial({ map: new THREE.CanvasTexture(this.getTextCanvas('Leo Test Label')) }), // top
new THREE.MeshBasicMaterial({ color: 'black' }), // bottom
new THREE.MeshBasicMaterial({ map: texture, }), // back
new THREE.MeshBasicMaterial({ color: 'red' }) // front
];
.......
}