Commit c58023ee authored by GLASSER Emilie's avatar GLASSER Emilie
Browse files

Upload New File

parent 6041412a
Pipeline #5167 passed with stage
in 15 seconds
"use strict"; // good practice - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
var camera, scene, renderer;
var cameraControls, effectController;
var clock = new THREE.Clock();
var axes = false;
var ground = true;
var cube;
var headlight;
var spotlight;
var myTexture;
function init() {
var canvasWidth = 846;
var canvasHeight = 494;
// For grading the window is fixed in size; here's general code:
// RENDERER
renderer = new THREE.WebGLRenderer( );
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.setSize(canvasWidth, canvasHeight);
renderer.setClearColor( 0x0, 1.0 );
renderer.shadowMap.enabled = true;
// CAMERA
camera = new THREE.PerspectiveCamera( 35, canvasWidth/ canvasHeight, 1, 4000 );
camera.position.set( 1200, 600, 300 );
// CONTROLS
cameraControls = new THREE.OrbitControls(camera, renderer.domElement);
cameraControls.target.set(0,310,0);
fillScene();
}
function fillScene() {
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0xAAAAAA, 3000, 5000 );
// LIGHTS
scene.add( new THREE.AmbientLight( 0x222222 ) );
headlight = new THREE.PointLight( 0x606060, 1.0 );
scene.add( headlight );
spotlight = new THREE.SpotLight( 0xFFFFFF, 1.0 );
spotlight.position.set( -500, 500, 222 );
spotlight.angle = 30 * Math.PI / 180;
spotlight.exponent = 1;
spotlight.target.position.set( 0, 400, 0 );
spotlight.castShadow = true;
spotlight.shadow.mapSize.width = 512;
spotlight.shadow.mapSize.height = 512;
spotlight.shadow.camera.near = 0.5;
spotlight.shadow.camera.far = 5000;
scene.add( spotlight );
var lightSphere = new THREE.Mesh(
new THREE.SphereGeometry( 1, 1, 1 ),
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.castShadow=true;
solidGround.receiveShadow=true;
scene.add( solidGround );
chaise1();
table();
chaise2();
lit();
murs();
fenetre();
tableau();
}
function lit(){
var loader = new THREE.OBJLoader();
// Charger le fichier
loader.load('lit.obj',
function ( object ) {
//var material = new THREE.MeshPhongMaterial( { ambient: 0x0055ff, color: 0x0055ff, specular: 0x111111, shininess: 200 } );
        //var mesh = new THREE.Mesh( , material );
object.position.set(-50,0,-250);
object.scale.x = 0.1;
object.scale.y = 0.1;
object.scale.z = 0.1;
if ( object instanceof THREE.Mesh ) {
object.castShadow = true;
object.receiveShadow = true;
}
scene.add( object );
}
)
}
function chaise1(){
var loader = new THREE.OBJLoader();
// Charger le fichier
loader.load('chaise.obj',function ( object ) {
//object.scale.set(50, 50, 50);
object.position.set(300,0,-400);
object.rotateY(Math.PI/4)
scene.add( object );
}
/* Fin du processus pour avoir du lissage */
)
}
function chaise2(){
var loader = new THREE.OBJLoader();
// Charger le fichier
loader.load('chaise.obj',function ( object ) {
object.position.set(200,0,-300);
//object.scale.set(50, 50, 50);
object.rotateY(Math.PI/2)
scene.add( object );
}
/* Fin du processus pour avoir du lissage */
)
}
function table(){
var cubeMaterial = new THREE.MeshLambertMaterial( { color: 0xFFFFFF, shininess: 100 } );
cube = new THREE.Mesh(new THREE.BoxGeometry( 10, 200, 10 ), cubeMaterial );
cube.position.x = -300;
cube.position.y = 100;
cube.position.z = 300;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 10, 200, 10 ), cubeMaterial );
cube.position.x = -400;
cube.position.y = 100;
cube.position.z = 300;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 10, 200, 10 ), cubeMaterial );
cube.position.x = -400;
cube.position.y = 100;
cube.position.z = 400;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 10, 200, 10 ), cubeMaterial );
cube.position.x = -300;
cube.position.y = 100;
cube.position.z = 400;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 100, 50, 100 ), cubeMaterial );
cube.position.x = -350;
cube.position.y = 170;
cube.position.z = 350;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 150, 10, 150 ), cubeMaterial );
cube.position.x = -350;
cube.position.y = 200;
cube.position.z = 350;
scene.add( cube );
}
function fenetre(){
var cubeMaterial = new THREE.MeshLambertMaterial( { color: 0xFFFFFF, shininess: 100 } );
var glassMaterial = new THREE.MeshPhongMaterial( { shininess: 100, opacity: 0.1, transparent: true} );
cube = new THREE.Mesh(new THREE.BoxGeometry( 15, 300, 150 ), glassMaterial );
cube.position.x = -500;
cube.position.y = 500;
cube.position.z = 300;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 15, 300, 150 ), glassMaterial );
cube.position.x = -500;
cube.position.y = 500;
cube.position.z = 150;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 55, 300, 300 ), cubeMaterial );
cube.position.x = -500;
cube.position.y = 500;
cube.position.z = 222;
scene.add( cube );
}
function murs(){
var loader = new THREE.TextureLoader();
myTexture = loader.load( 'textures/mur.jpg' );
myTexture.wrapS = myTexture.wrapT = THREE.RepeatWrapping;
myTexture.repeat.set( 1,1 );
var myPolygonMaterial = new THREE.MeshBasicMaterial( { map: myTexture } );
cube = new THREE.Mesh(new THREE.BoxGeometry( 1000, 1500, 50 ), myPolygonMaterial );
cube.position.x = -45;
cube.position.y = 52/2;
cube.position.z = -460;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 1000, 1500, 50 ), myPolygonMaterial );
cube.position.x = -45;
cube.position.y = 52/2;
cube.position.z = 550;
scene.add( cube );
cube = new THREE.Mesh(new THREE.BoxGeometry( 50, 1500, 1000 ), myPolygonMaterial );
cube.position.x = -520;
cube.position.y = 52/2;
cube.position.z = 60;
scene.add( cube );
}
function tableau(){
var loader = new THREE.TextureLoader();
myTexture = loader.load( 'chambre-van-gogh.jpg' );
myTexture.wrapS = myTexture.wrapT = THREE.RepeatWrapping;
myTexture.repeat.set( 1,1 );
var myPolygonMaterial = new THREE.MeshBasicMaterial( { map: myTexture } );
var solidGround = new THREE.Mesh(
new THREE.BoxGeometry( 15, 100,150, 1 ),
myPolygonMaterial );
solidGround.position.x=-500;
solidGround.position.y=500;
solidGround.position.z=-200;
scene.add( solidGround );
}
function setupGui() {
effectController = {
shadowBias: 0.00001
};
var gui = new dat.GUI();
gui.add( effectController, "shadowBias", -0.01, 0.01 ).name("shadow bias");
gui.close();
}
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);
headlight.position.copy( camera.position );
spotlight.shadowBias = effectController.shadowBias;
renderer.render(scene, camera);
}
try {
init();
fillScene();
setupGui();
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);
}
Supports Markdown
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