Created
March 2, 2019 16:45
-
-
Save JacobMJones/a83033f97d46f5eb0b8987b57f4a6288 to your computer and use it in GitHub Desktop.
Psych Marble 2 x+y rotation simpler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as THREE from 'three' | |
import alphaTexture from './stripe6.jpg'; | |
export default scene => { | |
const group = new THREE.Group(); | |
const subjectGeometry = deformGeometry(new THREE.IcosahedronGeometry(7, 5)); | |
const subjectMaterial = new THREE.MeshStandardMaterial({ color: "red", transparent: true, side: THREE.DoubleSide, alphaTest: 0.1 }); | |
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); | |
group.add(subjectMesh); | |
// group.add(subjectWireframe); | |
scene.add(group); | |
// group.rotation.z = Math.PI/2; | |
const speed = 0.3; | |
const textureOffsetSpeed = .5; | |
function deformGeometry(geometry) { | |
// for (let i=0; i<geometry.vertices.length; i+=8) { | |
// const scalar = 1 - Math.random() * .2; | |
// geometry.vertices[i].multiplyScalar(scalar) | |
// } | |
return geometry; | |
} | |
function update(time) { | |
const angle = time*speed; | |
group.rotation.x = angle; | |
group.rotation.y = 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