Skip to content

Instantly share code, notes, and snippets.

@JacobMJones
Created March 3, 2019 04:43
Show Gist options
  • Save JacobMJones/d5b53b85bafc676a66cd239d28f6627e to your computer and use it in GitHub Desktop.
Save JacobMJones/d5b53b85bafc676a66cd239d28f6627e to your computer and use it in GitHub Desktop.
with click developed marble
import * as THREE from "three";
import alphaTexture from "./Images/clean-grey-gradient.jpg";
import { Vector3 } from "three";
export default scene => {
var raycaster = new THREE.Raycaster();
var lastMouse;
const group = new THREE.Group();
var speed = .1;
const subjectGeometry = deformGeometry(new THREE.IcosahedronGeometry(14, 4));
const subjectMaterial = new THREE.MeshStandardMaterial({
color: "blue",
transparent: true,
side: THREE.DoubleSide,
alphaTest: 0.3
});
subjectMaterial.alphaMap = new THREE.TextureLoader().load(alphaTexture);
subjectMaterial.alphaMap.magFilter = THREE.NearestFilter;
subjectMaterial.alphaMap.wrapT = THREE.RepeatWrapping;
subjectMaterial.alphaMap.repeat.y = 5;
const subjectMesh = new THREE.Mesh(subjectGeometry, subjectMaterial);
subjectMesh.callback = function() {
console.log("clicked");
};
console.log(subjectMesh);
group.add(subjectMesh);
// group.add(subjectWireframe);
scene.add(group);
subjectMesh.rotation.z = Math.PI / 2;
const textureOffsetSpeed = 0.5;
function deformGeometry(geometry) {
// for (let i=0; i<geometry.vertices.length; i+=16) {
// const scalar = 1 - Math.random() * .5;
// geometry.vertices[i].multiplyScalar(scalar)
// }
return geometry;
}
function update(time, mouse, camera, mouseClick, reset) {
if (mouseClick) {
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects([subjectMesh]);
if (intersects.length > 0) {
// intersects[0].object.material.setHex(0xff0000)
intersects[0].object.material.color.setHex(0xff0000)
reset();
}
lastMouse = mouse.x;
}
const angle = time * speed;
subjectMesh.rotation.y = angle;
subjectMesh.rotation.x = angle;
subjectMaterial.alphaMap.offset.y = 0.55 + time * textureOffsetSpeed;
// subjectWireframe.material.color.setHSL( Math.sin(angle*2), 0.5, 0.5 );
const scale = (Math.sin(angle * 8) + 6.4) / 5;
// subjectWireframe.scale.set(scale, scale, scale)
}
return {
update
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment