Commit 0eb17c90 authored by MARTIN Tanguy's avatar MARTIN Tanguy
Browse files

Update picture.js

parent fdb4a8c7
Pipeline #5200 passed with stage
in 5 seconds
"use strict";
var scene;
function PolygonGeometry(sides, location, radius) {
var triangle = new THREE.BufferGeometry();
// generate vertices
var vertices=[];
for ( var pt = 0 ; pt < sides; pt++ )
{
// Add 90 degrees so we start at +Y axis, rotate counterclockwise around
var angle = (Math.PI/2) + (pt / sides) * 2 * Math.PI;
var x = Math.cos( angle )*radius + location.x;
var y = Math.sin( angle )*radius + location.y;
// Save the vertex location
vertices.push( new THREE.Vector3( x, y, 0.0 ) );
}
// generate faces
//var faces=new Float32Array( []);
var faces=[];
for ( var face = 0 ; face < sides-2; face++ )
{
// this makes a triangle fan, from the first +Y point around
faces.push(vertices[0].x);
faces.push(vertices[0].y);
faces.push(vertices[0].z);
faces.push(vertices[face+1].x);
faces.push(vertices[face+1].y);
faces.push(vertices[face+1].z);
faces.push(vertices[face+2].x);
faces.push(vertices[face+2].y);
faces.push(vertices[face+2].z);
}
const fv=new Float32Array(faces);
// done: return it.
triangle.setAttribute( 'position', new THREE.BufferAttribute( fv, 3 ) );
return triangle;
function initPicture() {
// characters[0] = new Character('characters/ray.png',-65,115,-170);
// characters[1] = new Character('characters/emma.png',0,115,-170);
// characters[2] = new Character('characters/norman.png',72,115,-170);
characters[0] = new MainCharacter('openBook','characters/trio_front_open_book.png','characters/trio_back_open_book.png','characters/trio_front_close_book.png','characters/trio_back_close_book.png',0,115,30);
characters[1] = new InteractiveStringCharacter('littleBernie',littleBerniesSpritesFront,littleBerniesSpritesBack,0,115,-70);
characters[2] = new Character('characters/group2_front.png','characters/group2_back.png',0,115,-70);
characters[3] = new Character('characters/group3_front.png','characters/group3_back.png',0,115,-70);
characters[4] = new Character('characters/group4_front.png','characters/group4_back.png',0,115,-70);
}
function lights() {
var light = new THREE.PointLight(0xffffcc, 1 , 900);
light.position.set(40,300,-50);
scene.add(light);
function drawGousset() {
//var gousset = new THREE.Object3D();
var main = new THREE.CylinderGeometry(180,180,32,32);
main.rotateX(Math.PI/2);
var materialMain = new THREE.MeshPhongMaterial( { color: 'gold', wireframe: false, flatShading: false, shininess: 30 } );
var meshMain = new THREE.Mesh(main,materialMain);
meshMain.position.x = 0;
meshMain.position.y = 175;
meshMain.position.z = 100;
return (meshMain);
/*gousset.add(meshMain);
var haut = new THREE.CylinderGeometry(10,10,32,32);
var materialBase = new THREE.MeshLambertMaterial( { color: 0xaaaa99, wireframe: false } );
var meshBase = new THREE.Mesh(base,materialBase);
meshBase.position.x = 0;
meshBase.position.y = 70;
meshBase.position.z = -120;
gousset.add(meshBase);
scene.add(gousset);*/
}
function drawGousset() {
var cylindre = new THREE.CylinderGeometry(180,180,50,32);
cylindre.rotateX(Math.PI/2);
var material = new THREE.MeshLambertMaterial( { color: 0xffaf00, wireframe: false } );
var mesh = new THREE.Mesh(cylindre,material);
mesh.position.x = 0;
mesh.position.y = 190;
mesh.position.z = 100;
scene.add(mesh);
function drawLamp() {
var grp = new THREE.Group();
var lanceGeometry = new THREE.PlaneGeometry(17,20);
lanceGeometry.rotateY(Math.PI);
var lanceTexture = TextureLoader.load('objs/lamp_bis/textures/lance_lamp.png');
var lanceMaterial = new THREE.MeshStandardMaterial({
map: lanceTexture,
color: 0xFFFFFF,
transparent : true,
opacity: 0.8,
side : THREE.DoubleSide
});
var lance = new THREE.Mesh(lanceGeometry, lanceMaterial);
// lance.position.x = -1;
lance.position.y = 43;
lance.receiveShadow = true;
lance.castShadow = true;
grp.add(lance);
var gltfLoader = new THREE.GLTFLoader();
// Load a glTF resource
gltfLoader.load(
// resource URL
'objs/lamp_bis/scene.gltf',
// called when the resource is loaded
function ( gltf ) {
gltf.scene.traverse(
function(child) {
if(child instanceof THREE.Mesh && child.material.name === 'Fire.001') {
// console.log('Fire found');
// update fire intensity
child.material = fireMaterial;
}
else if(child instanceof THREE.Mesh && child.material.name !== 'Bulb.003') {
child.castShadow = true;
child.receiveShadow = true;
}
}
);
var homothetie = new THREE.Matrix4();
homothetie.set(
1.25, 0, 0, 0,
0, 1.25, 0, 0,
0, 0, 1.25, 0,
0, 0, 0, 1
);
gltf.scene.applyMatrix4(homothetie);
grp.add(gltf.scene);
}
);
fireLight.position.set(5,25,-7.5);
grp.add(fireLight);
var translation = new THREE.Matrix4();
translation.set(
1, 0, 0, 85,
0, 1, 0, 105,
0, 0, 1, 20,
0, 0, 0, 1
);
grp.rotateY(Math.PI/4);
grp.applyMatrix4(translation);
return grp;
}
function drawAssiette(x,y) {
var base = new THREE.CylinderGeometry(150,100,20,32);
var material = new THREE.MeshLambertMaterial( { color: 0xaaaa99, wireframe: false } );
var mesh = new THREE.Mesh(base,material);
mesh.position.x = x;
function drawAssiette() {
var mesh = assietteMesh.clone();
mesh.position.x = 0;
mesh.position.y = 10;
mesh.position.z = y;
mesh.position.z = 0;
mesh.receiveShadow = true;
mesh.castShadow = true;
return mesh;
}
function drawAssiettes() {
var meshs=[];
var main = drawMainAssiette();
main.position.y = 70;
meshs.push(main);
meshs.push(drawAssiette(400,600));
meshs.push(drawAssiette(-400,600));
meshs.push(drawAssiette(600,1200));
meshs.push(drawAssiette(-600,1200));
return meshs;
var r = [];
for(var i = 0; i< assiettesCoords.length; i++) {
var grp = new THREE.Group();
grp.add(drawAssiette());
switch(i) {
default:
break;
case 0:
grp.add(drawCadran());
fourchette = drawFourchette();
fourchette.rotation.x = fourchetteAngleX*THREE.MathUtils.DEG2RAD;
fourchette.rotation.z = fourchetteAngleZ*THREE.MathUtils.DEG2RAD;
fourchette.rotation.y = fourchetteAngleY*THREE.MathUtils.DEG2RAD;
fourchette.position.y = fourchetteY;
fourchette.position.x = fourchetteX;
fourchette.position.z = fourchetteZ;
grp.add(fourchette);
couteau = drawCouteau();
couteau.rotation.x = couteauAngleX*THREE.MathUtils.DEG2RAD;
couteau.rotation.z = couteauAngleZ*THREE.MathUtils.DEG2RAD;
couteau.rotation.y = couteauAngleY*THREE.MathUtils.DEG2RAD;
couteau.position.y = couteauY;
couteau.position.x = couteauX;
couteau.position.z = couteauZ;
grp.add(couteau);
grp.add(drawLamp());
break;
case 1:
grp.add(drawTeddies());
break;
}
characters[i].updateSprite();
grp.add(characters[i].draw());
grp.translateX(assiettesCoords[i][0]);
grp.translateZ(assiettesCoords[i][1]);
grp.rotateY(assiettesAngle*THREE.MathUtils.DEG2RAD);
r.push(grp);
}
return r;
}
function drawMainAssiette() {
var mesh = drawAssiette(0,-120);
drawRomanDigits(mesh);
drawCouverts();
return mesh;
function drawCadran() {
var geo = new THREE.PlaneGeometry(300,300);
var mat = assietteMaterial.clone();
mat.map = TextureLoader.load('objs/cadran.png');
mat.transparent = true;
var ret = new THREE.Mesh(geo,mat);
ret.rotation.x = Math.PI/2.;
ret.rotation.y = Math.PI;
ret.position.y = 20.1;
ret.castShadow = true;
ret.receiveShadow = true;
return ret;
}
function drawTeddies() {
var ret = new THREE.Group();
var VOXloader = new THREE.VOXLoader();
VOXloader.load(
'objs/teddy_bears.vox',
function ( chunks ) {
for ( let i = 0; i < chunks.length; i ++ ) {
const chunk = chunks[ i ];
const mesh = new THREE.VOXMesh( chunk );
mesh.scale.setScalar(0.8);
mesh.castShadow = true;
mesh.receiveShadow = true;
ret.add( mesh );
}
}
);
ret.position.y = 50;
ret.position.x = 0;
ret.position.z = -40;
return ret;
}
function drawFourchette() {
var ret = new THREE.Group();
var scalingMatrix = new THREE.Matrix4();
scalingMatrix.set(
2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 2, 0,
0, 0, 0, 1
);
// var translateMatrix = new THREE.Matrix4();
// translateMatrix.set(
// 1, 0, 0, fourchetteX,
// 0, 1, 0, fourchetteY,
// 0, 0, 1, fourchetteZ,
// 0, 0, 0, 1
// );
OBJLoader.load(
'objs/fork.obj',
function(object) {
object.traverse(
function(child) {
if(child instanceof THREE.Mesh) {
// console.log('coucou');
// console.log(child);
child.material = couvertsMaterial;
child.applyMatrix4(scalingMatrix);
child.castShadow = true;
child.receiveShadow = true;
// child.rotateZ(fourchetteAngleY*THREE.MathUtils.DEG2RAD);
// child.rotateY(fourchetteAngleZ*THREE.MathUtils.DEG2RAD);
// child.rotateX(fourchetteAngleX*THREE.MathUtils.DEG2RAD);
ret.add(child.clone());
}
}
);
}
);
// ret.applyMatrix4(translateMatrix);
return ret;
}
function drawCouteau() {
var ret = new THREE.Group();
}
var transfromMatrix = new THREE.Matrix4();
transfromMatrix.set(
2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 2, 0,
0, 0, 0, 1
);
function drawCouverts() {
drawCouteau();
drawFourchette();
}
OBJLoader.load(
'objs/knife.obj',
function ( object ) {
object.traverse(
function(child) {
if(child instanceof THREE.Mesh) {
// console.log('hello');
child.applyMatrix4(transfromMatrix);
// child.rotateY(-Math.PI/4);
// child.rotateX(couteauAngleX*THREE.MathUtils.DEG2RAD);
child.material = couvertsMaterial;
child.castShadow = true;
child.receiveShadow = true;
ret.add(child.clone());
}
}
);
}
);
function drawRomanDigits() {
// ret.applyMatrix4(transfromMatrix);
// ret.rotateY(-Math.PI/4);
// ret.rotateX(couteauAngleX*THREE.MathUtils.DEG2RAD);
return ret;
}
function drawPicture(sc) {
scene=sc;
drawGousset();
var assiettes = drawAssiettes();
function drawPicture() {
var ret = new THREE.Group();
var e = drawGround();
ret.add(e);
e = drawGousset();
ret.add(e);
assiettes = drawAssiettes();
for(var i = 0; i < assiettes.length; i++) {
scene.add(assiettes[i]);
ret.add(assiettes[i]);
}
//drawCharacters();
lights();
return ret;
}
function drawCharacters() {
const map = new THREE.TextureLoader().load( '../wood.jpg' );
const material = new THREE.SpriteMaterial( { map: map, color: 0xffffff } );
const sprite = new THREE.Sprite( material );
sprite.scale.set(200, 200, 1);
sprite.position.x=0;
sprite.position.y=170;
sprite.position.z=-60;
scene.add( sprite );
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment