Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var GC3D = { Version: '1.0.2' };
- GC3D.Enums = {
- renderer: {
- id: 0,
- type: THREE.WebGLRenderer,
- antialias: true,
- alpha: true,
- canvasDomId: 'webgl-application'
- },
- camera: {
- id: 1,
- type: THREE.PerspectiveCamera,
- fov: 45,
- aspect: window.innerWidth / window.innerHeight,
- near: 1,
- far: 20000
- },
- light: {
- id: 2,
- type: THREE.PointLight,
- color: 0xffff00
- },
- mapDefaultSettings: {
- id: 3,
- type: Object,
- coordinates: {
- x: 39604,
- y: 20492,
- zoom: 16
- }
- }
- };
- GC3D.Utils = function() {
- this.renderer = undefined;
- this.scene = undefined;
- this.camera = undefined;
- this.init();
- };
- GC3D.Utils.prototype.init = function() {
- this.initRender();
- this.initScene();
- this.initCamera();
- this.initLight();
- };
- GC3D.Utils.prototype.initRender = function() {
- var properties = GC3D.Enums.renderer;
- this.renderer = new THREE.WebGLRenderer({
- antialias: properties.antialias,
- alpha: properties.alpha,
- canvas: document.getElementById( properties.canvasDomId )
- });
- this.renderer.setSize( window.innerWidth, window.innerHeight );
- };
- GC3D.Utils.prototype.renderScene = function() {
- requestAnimationFrame( GC3D.Utils.prototype.renderScene.bind( this ) );
- this.renderer.render( this.scene, this.camera );
- this.scene.children.filter(function( item ) {
- if ( item instanceof THREE.Mesh ) {
- item.rotation.x += 0.02;
- }
- });
- };
- GC3D.Utils.prototype.initScene = function() {
- this.scene = new THREE.Scene();
- };
- GC3D.Utils.prototype.initCamera = function() {
- var properties = GC3D.Enums.camera;
- this.camera = new THREE.PerspectiveCamera(
- properties.fov,
- properties.aspect,
- properties.near,
- properties.far
- );
- this.scene.add( this.camera );
- };
- GC3D.Utils.prototype.setCameraPosition = function( newPosition ) {
- this.camera.position.set( newPosition.x, newPosition.y, newPosition.z );
- };
- GC3D.Utils.prototype.setCameraLookAtView = function( object ) {
- this.camera.lookAt( object );
- };
- GC3D.Utils.prototype.initLight = function() {
- var properties = GC3D.Enums.light;
- this.light = new THREE.PointLight( properties.color );
- this.scene.add( this.light );
- };
- GC3D.Utils.prototype.setLightPosition = function( newPosition ) {
- this.light.position.set( newPosition.x, newPosition.y, newPosition.z );
- };
- GC3D.Application = function() {
- this.utils = new GC3D.Utils();
- this.run();
- };
- GC3D.Application.prototype.run = function() {
- this.utils.setCameraPosition( { x: 3, y: 3, z: 3 } );
- this.utils.setCameraLookAtView( this.utils.scene.position );
- this.utils.setCameraPosition( { x: 10, y: 10, z: 10 } );
- var cube = new THREE.Mesh(
- new THREE.CubeGeometry( 3, 3, 3 ),
- new THREE.MeshBasicMaterial({
- map: THREE.ImageUtils.loadTexture( '/images/textures/box.jpg' )
- })
- );
- this.utils.scene.add( cube );
- this.utils.renderScene();
- var worker = new Worker( "webworker.js" );
- worker.postMessage( JSON.stringify( this.utils.scene ) );
- };
Advertisement
Add Comment
Please, Sign In to add comment