I am currently working with two different objects in my A-Frame scene, a cylinder and a polygon, both representing Three.js 3D Objects. I would like to make it so that the polygon changes when hovered over, similar to how the cylinder does.
If you'd like to see a demo of what I have so far, please check out: Demo
When hovering over the cylinder, the text "HOVERED" appears on the screen and the color of the cylinder changes, thanks to the Raycaster component. How can I achieve the same effect for the polygon?
The polygon was created using the following code:
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);
}
});
Any suggestions or help would be greatly appreciated. Thank you!