Commit 2ca9c04b authored by LANOTTE Nicolas's avatar LANOTTE Nicolas

Upload New File

parent fa42c808
Pipeline #4605 passed with stage
in 12 seconds
"use strict"; // good practice - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
/*global THREE, Coordinates, document, window, $ */
var camera, scene, renderer;
var cameraControls;
var clock = new THREE.Clock();
var headlight, spotlight;
function fillScene() {
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xcce0ff );
scene.fog = new THREE.Fog( 0x808080, 2000, 4000 );
// LIGHTS
scene.add( new THREE.AmbientLight( 0x222222 ) );
headlight = new THREE.PointLight( 0x606060, 1.0 );
scene.add( headlight );
spotlight = new THREE.SpotLight( 0xFFFFFF, 0.5 );
spotlight.position.set(300, 900, -600 );
spotlight.angle = 25 * Math.PI / 180;
//spotlight.exponent = 1;
//spotlight.target.position.set( 0, 400, 0 );
spotlight.castShadow = true;
spotlight.shadow.mapSize.width = 512; //largeur de la map
spotlight.shadow.mapSize.height = 512;//hauteur de la map
spotlight.shadow.camera.near = 0.5; // dimension near du Z-buffer
spotlight.shadow.camera.far = 5000 // dimension far du Z-buffer
scene.add( spotlight );
var lightSphere = new THREE.Mesh(
new THREE.SphereGeometry( 10, 12, 6 ),
new THREE.MeshBasicMaterial() );
lightSphere.position.copy( spotlight.position );
scene.add( lightSphere );
// GROUND
// put grid lines every 10000/100 = 100 units
var solidGround = new THREE.Mesh(
new THREE.PlaneGeometry( 10000, 10000 ),
new THREE.MeshPhongMaterial({ color: 0xFFFFFF,
polygonOffset: true, polygonOffsetFactor: 1.0, polygonOffsetUnits: 4.0
}));
solidGround.rotation.x = -Math.PI / 2;
solidGround.receiveShadow= true;
scene.add( solidGround );
var paint = new THREE.Object3D();
createPaint(paint);
scene.add(paint);
}
function createElement(element) {
var bouteille = new THREE.MeshPhongMaterial( { color: 0x0f6512, opacity: 0.4, transparent: true } );
var whisky = new THREE.MeshPhongMaterial( { color: 0xd7cfca, opacity: 0.4, transparent: true} );
var carafe = new THREE.MeshPhongMaterial( { color: 0xd7cfca, opacity: 0.6, transparent: true } );
var pain = new THREE.MeshPhongMaterial( { color: 0xde6317 } );
var assiette = new THREE.MeshPhongMaterial( { color: 0xd0cbc7 } );
var verre = new THREE.MeshPhongMaterial( { color: 0xd7cfca, opacity: 0.4, transparent: true, shininess:100 } );
var cylinder, sphere;
// assiette
var a = new THREE.Object3D();
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(110, 90, 30, 32 ), assiette );
cylinder.position.y=20/2;
a.add(cylinder);
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(150, 150, 10, 32 ), assiette );
cylinder.position.y=20;
a.add(cylinder);
a.position.x=0;
a.position.z=0;
a.castShadow = true;
a.receiveShadow = true;
scene.add(a);
// verre
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(60, 70, 10, 32 ), verre );
cylinder.position.x=200;
cylinder.position.y=5/2;
cylinder.position.z=-100;
cylinder.castShadow = true;
cylinder.receiveShadow = true;
scene.add(cylinder);
sphere = new THREE.Mesh(
new THREE.SphereGeometry( 20, 32, 16 ), verre);
sphere.position.x = 200;
sphere.position.y = 5+20;
sphere.position.z = -100;
scene.add( sphere );
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(10, 10, 30, 32 ), verre );
cylinder.position.x=200;
cylinder.position.y=25+30;
cylinder.position.z=-100;
scene.add(cylinder);
sphere = new THREE.Mesh(
new THREE.SphereGeometry( 80, 32, 16, 0, Math.PI * 2, Math.PI/2, Math.PI ), verre);
sphere.position.x = 200;
sphere.position.y = 25+30+80;
sphere.position.z = -100;
scene.add( sphere );
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(80, 80, 100, 32 ), verre );
cylinder.position.x=200;
cylinder.position.y=25+30+80+50;
cylinder.position.z=-100;
scene.add(cylinder);
//baguette de pain
var clockHand = new THREE.Object3D();
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(90, 90, 350, 32 ), pain );
clockHand.add( cylinder );
sphere = new THREE.Mesh(
new THREE.SphereGeometry( 90, 32, 16 ), pain );
sphere.position.y=175;
clockHand.add(sphere);
clockHand.position.x= 100;
clockHand.position.y= 90;
clockHand.position.z= 350;
clockHand.rotation.z = 90 * Math.PI/180;
clockHand.rotation.y = -15 * Math.PI / 180;
clockHand.castShadow = true;
clockHand.receiveShadow = true;
scene.add( clockHand );
// bouteille de vin centrale
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(90, 90, 380, 32 ), bouteille );
cylinder.position.x=250;
cylinder.position.y=380/2;
cylinder.position.z=100;
cylinder.castShadow = true;
cylinder.receiveShadow = true;
scene.add(cylinder);
sphere = new THREE.Mesh(
new THREE.SphereGeometry( 90, 32, 16 ), bouteille );
sphere.position.x = 250;
sphere.position.y = 380;
sphere.position.z = 100;
scene.add( sphere );
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(35, 38, 150, 32 ), bouteille );
cylinder.position.x=250;
cylinder.position.y=380+90+60;
cylinder.position.z=100;
scene.add(cylinder);
//bouteille de whisky
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(90, 80, 200, 32 ), whisky );
cylinder.position.x=-200;
cylinder.position.y=200/2;
cylinder.position.z=-400;
cylinder.castShadow = true;
cylinder.receiveShadow = true;
scene.add(cylinder);
sphere = new THREE.Mesh(
new THREE.SphereGeometry( 90, 32, 16 ), whisky );
sphere.position.x = -200;
sphere.position.y = 200;
sphere.position.z = -400;
scene.add( sphere );
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(30, 35, 150, 32 ), whisky );
cylinder.position.x=-200;
cylinder.position.y=200+90+45;
cylinder.position.z=-400;
scene.add(cylinder);
//carafe d'eau
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(100, 95, 100, 32 ), carafe );
cylinder.position.x=0;
cylinder.position.y=100/2;
cylinder.position.z=-300;
cylinder.castShadow = true;
cylinder.receiveShadow = true;
scene.add(cylinder);
sphere = new THREE.Mesh(
new THREE.SphereGeometry( 100, 32, 16 ), carafe );
sphere.position.x = 0;
sphere.position.y = 100;
sphere.position.z = -300;
scene.add( sphere );
cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(20, 25, 210, 32 ), carafe );
cylinder.position.x=0;
cylinder.position.y=100+200;
cylinder.position.z=-300;
scene.add(cylinder);
//Create a plane that receives shadows (but does not cast them)
const planeGeometry = new THREE.PlaneGeometry( 20, 20, 32, 32 );
const planeMaterial = new THREE.MeshStandardMaterial( { color: 0x00ff00 } )
const plane = new THREE.Mesh( planeGeometry, planeMaterial );
plane.receiveShadow = true;
scene.add( plane );
}
function createPaint(paint) {
var element = new THREE.Object3D();
createElement(element);
paint.add(element);
paint.traverse( function ( object ) {
if ( object instanceof THREE.Mesh ) {
object.castShadow = true;
object.receiveShadow = true;
}
} );
}
function init() {
var canvasWidth = 846;
var canvasHeight = 494;
// For grading the window is fixed in size; here's general code:
//var canvasWidth = window.innerWidth;
//var canvasHeight = window.innerHeight;
var canvasRatio = canvasWidth / canvasHeight;
// RENDERER
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.setSize(canvasWidth, canvasHeight);
renderer.setClearColor( 0x0, 1.0 );
renderer.shadowMap.enabled = true;
// CAMERA
//camera = new THREE.PerspectiveCamera( 45, canvasRatio, 1, 4000 );
camera = new THREE.PerspectiveCamera( 35, canvasWidth/ canvasHeight, 1, 4000 );
camera.position.set( -1160, 350, -600 );
// CONTROLS
cameraControls = new THREE.OrbitControls(camera, renderer.domElement);
//camera.position.set( -480, 659, -619 );
cameraControls.target.set(0,310,0);
fillScene();
}
function addToDOM() {
var container = document.getElementById('webGL');
var canvas = container.getElementsByTagName('canvas');
if (canvas.length>0) {
container.removeChild(canvas[0]);
}
container.appendChild( renderer.domElement );
}
function animate() {
window.requestAnimationFrame(animate);
render();
}
function render() {
var delta = clock.getDelta();
cameraControls.update(delta);
renderer.render(scene, camera);
}
try {
init();
fillScene();
addToDOM();
animate();
} catch(e) {
var errorReport = "Your program encountered an unrecoverable error, can not draw on canvas. Error was:<br/><br/>";
$('#container').append(errorReport+e);
}
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