A 帧 - 光线投射 Three.JS 3D 对象
A-Frame - Raycast Three.JS 3D Object
我在 A 帧场景中有两个对象,一个圆柱体和一个多边形,代表一个 Three.js 3D 对象。我想要的只是多边形在悬停时发生变化,就像圆柱体一样。
我这里有一个工作演示:Demo
当光标悬停在圆柱体上时,屏幕上会出现HOVERED字样,圆柱体的颜色也会发生变化,使用了Raycaster组件。我怎样才能对多边形做同样的事情?
多边形是这样创建的:
AFRAME.registerComponent('foo', {
init: function() {
let points = [];
points.push(new THREE.Vector2(0, 0));
points.push(new THREE.Vector2(1.5, 0));
points.push(new THREE.Vector2(2.5, 1));
points.push(new THREE.Vector2(2.5, 2.5));
points.push(new THREE.Vector2(1, 3.5));
for (let i = 0; i < points.length; i++) {
points[i].multiplyScalar(0.25);
}
let shape = new THREE.Shape(points);
let extrudedGeometry = new THREE.ExtrudeGeometry(shape, {
amount: 1,
bevelEnabled: false
});
// Geometry doesn't do much on its own, we need to create a Mesh from it
let extrudedMesh = new THREE.Mesh(extrudedGeometry, new THREE.MeshPhongMaterial({
color: 0xff0000
}));
this.el.object3D.add(extrudedMesh);
let geometry = new THREE.ShapeGeometry(shape);
let material = new THREE.MeshBasicMaterial({
color: 0x00ff00
});
let mesh = new THREE.Mesh(geometry, material);
this.el.object3D.add(mesh);
}
});
谢谢。
Raycaster 向实体的网格投射光线。你用 setObject3D 设置它。做:
let mesh = new THREE.Mesh(geometry, material);
this.el.setObject3D('mesh', mesh);
我在 A 帧场景中有两个对象,一个圆柱体和一个多边形,代表一个 Three.js 3D 对象。我想要的只是多边形在悬停时发生变化,就像圆柱体一样。
我这里有一个工作演示:Demo
当光标悬停在圆柱体上时,屏幕上会出现HOVERED字样,圆柱体的颜色也会发生变化,使用了Raycaster组件。我怎样才能对多边形做同样的事情?
多边形是这样创建的:
AFRAME.registerComponent('foo', {
init: function() {
let points = [];
points.push(new THREE.Vector2(0, 0));
points.push(new THREE.Vector2(1.5, 0));
points.push(new THREE.Vector2(2.5, 1));
points.push(new THREE.Vector2(2.5, 2.5));
points.push(new THREE.Vector2(1, 3.5));
for (let i = 0; i < points.length; i++) {
points[i].multiplyScalar(0.25);
}
let shape = new THREE.Shape(points);
let extrudedGeometry = new THREE.ExtrudeGeometry(shape, {
amount: 1,
bevelEnabled: false
});
// Geometry doesn't do much on its own, we need to create a Mesh from it
let extrudedMesh = new THREE.Mesh(extrudedGeometry, new THREE.MeshPhongMaterial({
color: 0xff0000
}));
this.el.object3D.add(extrudedMesh);
let geometry = new THREE.ShapeGeometry(shape);
let material = new THREE.MeshBasicMaterial({
color: 0x00ff00
});
let mesh = new THREE.Mesh(geometry, material);
this.el.object3D.add(mesh);
}
});
谢谢。
Raycaster 向实体的网格投射光线。你用 setObject3D 设置它。做:
let mesh = new THREE.Mesh(geometry, material);
this.el.setObject3D('mesh', mesh);