1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| class Scene {
constructor(image, camera) {
this.image = image
this.points = []
this.sprites = []
this.scene = null
this.camera = camera
}
createScene(scene) {
this.scene = scene
const geometry = new THREE.SphereGeometry(11, 32, 32)
const texture = new THREE.TextureLoader().load(this.image)
scene.background = null;
texture.wrapS = THREE.RepeatWrapping
texture.repeat.x = -1
const material = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide
})
material.transparent = true
this.sphere = new THREE.Mesh(geometry, material)
this.scene.add(this.sphere)
this.points.forEach(this.addTooltip.bind(this))
}
addPoint(point) {
this.points.push(point)
}
addTooltip(point) {
var loader = new THREE.TextureLoader();
let spriteMap = loader.load('../textures/' + point.image, (texture) => {
actionSprite = spriteMixer.ActionSprite(texture, 4, 6);
actionSprite.setFrame(0);
actions.runLeft = spriteMixer.Action(actionSprite, 0, 20, 50);
actions.runLeft.playLoop()
actionSprite.scale.set(5, 3, 5);
let spriteMaterial = new THREE.SpriteMaterial({
map: spriteMap
})
let sprite = new THREE.Sprite(spriteMaterial)
sprite.name = point.name;
sprite.position.copy(point.position.clone().normalize().multiplyScalar(10));
sprite.scale.multiplyScalar(2)
this.scene.add(sprite);
this.sprites.push(sprite);
if (point.scene !== false) {
sprite.onClick = () => {
this.destroy();
point.scene.appear();
}
} else {
sprite.onClick = () => {
}
}
}
)
var geometry = new THREE.CircleGeometry(3, 50);
var material = new THREE.MeshBasicMaterial({
map: new THREE.TextureLoader().load('../ressources/insa.png')
});
var plane = new THREE.Mesh(geometry, material);
plane.material.side = THREE.DoubleSide;
scene.add(plane);
plane.position.x = 0;
plane.position.y = -6;
plane.position.z = 0;
plane.rotation.x = 30
plane.rotation.y = 0
plane.rotation.z = 4.5
}
destroy = function () {
actions.runLeft.stop();
this.sprites.forEach((sprite) => {
gsap.to(this.camera.position, {
x: -1,
y: 0,
z: 0,
duration: 1.5,
ease: "power4.inOut",
onComplete: () => {
this.sphere.remove(this.scene)
}
})
this.sprites.forEach((sprite) => {
TweenLite.to(sprite.scale, 1, {
x: 0,
y: 0,
z: 0,
onComplete: () => {
this.scene.remove(sprite)
}
})
})
}
)
}
appear() {
this.sprites.forEach((sprite) => {
sprite.scale.set(0, 0, 0)
TweenLite.to(sprite.scale, 1, {
x: 1,
y: 3,
z: 3
})
})
}
} |
Partager