Exemplo n.º 1
0
function getAnimationAttributes (positions, cells) {
  const directions = []
  const centroids = []
  for (let i=0; i<cells.length; i++) {
    const [ f0, f1, f2 ] = cells[i]
    const triangle = [ positions[f0], positions[f1], positions[f2] ]
    const center = triangleCentroid(triangle)
    const dir = new THREE.Vector3().fromArray(center)
    centroids.push(dir, dir, dir)
    
    const random = randomVec3([], Math.random())
    const anim = new THREE.Vector3().fromArray(random)
    directions.push(anim, anim, anim)
  }
  return {
    direction: { type: 'v3', value: directions },
    centroid: { type: 'v3', value: centroids }
  }
}
Exemplo n.º 2
0
    var gifts = array(amount).map(function(i) {
        var mesh = gift.clone()

        var newMats = mesh.material.materials.map(function(mat) {
            if (/ribbon/i.test(mat.name)) {
                mat = mat.clone()
                mat.color = new THREE.Color(colors[i%colors.length])
            } 
            return mat
        })
        mesh.material = new THREE.MeshFaceMaterial(newMats)


        var giftObj = new THREE.Object3D()
        giftObj.add(mesh)
        
        // var hover = geoMesh.clone()
        var meshObj = new THREE.Object3D()
        meshObj.scale.multiplyScalar(MIN_SCALE)
        meshObj.add(giftObj)
        // meshObj.add(hover)

        var s = randf(0.08, 0.35)
        TweenMax.to(meshObj.scale, 1.0, {
            x: s * randf(0.95,1.05), y: s * randf(0.95,1.05), z: s,
            delay: delay+=0.02
        })

        // hover.visible = false
        mesh.position.y = -0.4 //fix model to origin

        var pos = random([0, 0, 0], 10)
        meshObj.position.fromArray(pos)
        meshObj.rotation.x = randf(-Math.PI*2, Math.PI*2)
        meshObj.rotation.y = randf(-Math.PI*2, Math.PI*2) 
        meshObj.rotation.z = randf(-Math.PI*2, Math.PI*2)
        
        // meshObj.hover = hover
        return meshObj
    })