|
@@ -44,27 +44,24 @@
|
|
|
|
|
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
|
|
|
|
|
|
- var container,
|
|
|
|
- stats,
|
|
|
|
- camera,
|
|
|
|
- scene,
|
|
|
|
- renderer,
|
|
|
|
- pointLight,
|
|
|
|
- model,
|
|
|
|
- animations,
|
|
|
|
- kfAnimations = [ ],
|
|
|
|
- loader = new THREE.ColladaLoader(),
|
|
|
|
- lastTimestamp,
|
|
|
|
- startTime,
|
|
|
|
- progress = 0;
|
|
|
|
|
|
+ var stats;
|
|
|
|
+ var scene;
|
|
|
|
+ var camera;
|
|
|
|
+ var renderer;
|
|
|
|
+ var model;
|
|
|
|
+ var animations;
|
|
|
|
+ var kfAnimations = [ ];
|
|
|
|
+ var kfAnimationsLength = 0;
|
|
|
|
+ var loader = new THREE.ColladaLoader();
|
|
|
|
+ var lastTimestamp;
|
|
|
|
+ var progress = 0;
|
|
|
|
|
|
loader.load( './models/collada/pump/pump.dae', function ( collada ) {
|
|
loader.load( './models/collada/pump/pump.dae', function ( collada ) {
|
|
|
|
|
|
model = collada.scene;
|
|
model = collada.scene;
|
|
animations = collada.animations;
|
|
animations = collada.animations;
|
|
-
|
|
|
|
- model.scale.x = model.scale.y = model.scale.z = 0.125;
|
|
|
|
- model.updateMatrix();
|
|
|
|
|
|
+ kfAnimationsLength = animations.length;
|
|
|
|
+ model.scale.x = model.scale.y = model.scale.z = 0.125; // 1/8 scale, modeled in cm
|
|
|
|
|
|
init();
|
|
init();
|
|
start();
|
|
start();
|
|
@@ -74,14 +71,15 @@
|
|
|
|
|
|
function init() {
|
|
function init() {
|
|
|
|
|
|
- container = document.createElement( 'div' );
|
|
|
|
|
|
+ var container = document.createElement( 'div' );
|
|
document.body.appendChild( container );
|
|
document.body.appendChild( container );
|
|
|
|
|
|
- model.getChildByName( 'camEye_camera', true ).visible = false;
|
|
|
|
- model.getChildByName( 'camTarget_camera', true ).visible = false;
|
|
|
|
|
|
+ // Scene
|
|
|
|
|
|
scene = new THREE.Scene();
|
|
scene = new THREE.Scene();
|
|
|
|
|
|
|
|
+ // Camera
|
|
|
|
+
|
|
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.01, 1000 );
|
|
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.01, 1000 );
|
|
camera.position.set( -5.00181875, 3.42631375, 11.3102925 );
|
|
camera.position.set( -5.00181875, 3.42631375, 11.3102925 );
|
|
camera.lookAt( new THREE.Vector3( -1.224774125, 2.18410625, 4.57969125 ) );
|
|
camera.lookAt( new THREE.Vector3( -1.224774125, 2.18410625, 4.57969125 ) );
|
|
@@ -90,21 +88,17 @@
|
|
|
|
|
|
// KeyFrame Animations
|
|
// KeyFrame Animations
|
|
|
|
|
|
- var animHandler = THREE.AnimationHandler,
|
|
|
|
- toConvert = { };
|
|
|
|
|
|
+ var animHandler = THREE.AnimationHandler;
|
|
|
|
|
|
- for ( var i = 0, il = animations.length; i < il; ++i ) {
|
|
|
|
- var node = animations[ i ].node;
|
|
|
|
- toConvert[ node.id ] = node;
|
|
|
|
- }
|
|
|
|
|
|
+ for ( var i = 0; i < kfAnimationsLength; ++i ) {
|
|
|
|
|
|
- for ( var i = 0, il = animations.length; i < il; ++i ) {
|
|
|
|
var animation = animations[ i ];
|
|
var animation = animations[ i ];
|
|
animHandler.add( animation );
|
|
animHandler.add( animation );
|
|
|
|
|
|
- var kfAnimation = new THREE.KeyFrameAnimation( toConvert[ animation.node.id ], animation.name );
|
|
|
|
|
|
+ var kfAnimation = new THREE.KeyFrameAnimation( animation.node, animation.name );
|
|
kfAnimation.timeScale = 1;
|
|
kfAnimation.timeScale = 1;
|
|
kfAnimations.push( kfAnimation );
|
|
kfAnimations.push( kfAnimation );
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
// Grid
|
|
// Grid
|
|
@@ -127,20 +121,25 @@
|
|
|
|
|
|
// Add the COLLADA
|
|
// Add the COLLADA
|
|
|
|
|
|
|
|
+ model.getChildByName( 'camEye_camera', true ).visible = false;
|
|
|
|
+ model.getChildByName( 'camTarget_camera', true ).visible = false;
|
|
|
|
+
|
|
scene.add( model );
|
|
scene.add( model );
|
|
|
|
|
|
// Lights
|
|
// Lights
|
|
|
|
|
|
- pointLight = new THREE.PointLight( 0xffffff, 1.5 );
|
|
|
|
|
|
+ pointLight = new THREE.PointLight( 0xffffff, 1.75 );
|
|
pointLight.position = camera.position;
|
|
pointLight.position = camera.position;
|
|
pointLight.rotation = camera.rotation;
|
|
pointLight.rotation = camera.rotation;
|
|
pointLight.scale = camera.scale;
|
|
pointLight.scale = camera.scale;
|
|
|
|
+
|
|
scene.add( pointLight );
|
|
scene.add( pointLight );
|
|
|
|
|
|
// Renderer
|
|
// Renderer
|
|
|
|
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer = new THREE.WebGLRenderer( { antialias: true } );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
+
|
|
container.appendChild( renderer.domElement );
|
|
container.appendChild( renderer.domElement );
|
|
|
|
|
|
// Stats
|
|
// Stats
|
|
@@ -148,28 +147,29 @@
|
|
stats = new Stats();
|
|
stats = new Stats();
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.position = 'absolute';
|
|
stats.domElement.style.top = '0px';
|
|
stats.domElement.style.top = '0px';
|
|
|
|
+
|
|
container.appendChild( stats.domElement );
|
|
container.appendChild( stats.domElement );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
function start() {
|
|
function start() {
|
|
|
|
|
|
- for ( var i = 0, il = kfAnimations.length; i < il; ++i ) {
|
|
|
|
|
|
+ for ( var i = 0; i < kfAnimationsLength; ++i ) {
|
|
|
|
|
|
var animation = kfAnimations[i];
|
|
var animation = kfAnimations[i];
|
|
|
|
|
|
for ( var h = 0, hl = animation.hierarchy.length; h < hl; h++ ) {
|
|
for ( var h = 0, hl = animation.hierarchy.length; h < hl; h++ ) {
|
|
|
|
|
|
- var keys = animation.data.hierarchy[ h ].keys,
|
|
|
|
- sids = animation.data.hierarchy[ h ].sids,
|
|
|
|
- obj = animation.hierarchy[ h ];
|
|
|
|
|
|
+ var keys = animation.data.hierarchy[ h ].keys;
|
|
|
|
+ var sids = animation.data.hierarchy[ h ].sids;
|
|
|
|
+ var obj = animation.hierarchy[ h ];
|
|
|
|
|
|
if ( keys.length && sids ) {
|
|
if ( keys.length && sids ) {
|
|
|
|
|
|
for ( var s = 0; s < sids.length; s++ ) {
|
|
for ( var s = 0; s < sids.length; s++ ) {
|
|
|
|
|
|
- var sid = sids[ s ],
|
|
|
|
- next = animation.getNextKeyWith( sid, h, 0 );
|
|
|
|
|
|
+ var sid = sids[ s ];
|
|
|
|
+ var next = animation.getNextKeyWith( sid, h, 0 );
|
|
|
|
|
|
if ( next ) next.apply( sid );
|
|
if ( next ) next.apply( sid );
|
|
|
|
|
|
@@ -196,7 +196,7 @@
|
|
|
|
|
|
if ( progress >= 0 && progress < 48 ) {
|
|
if ( progress >= 0 && progress < 48 ) {
|
|
|
|
|
|
- for ( var i = 0, il = kfAnimations.length; i < il; ++i ) {
|
|
|
|
|
|
+ for ( var i = 0; i < kfAnimationsLength; ++i ) {
|
|
|
|
|
|
kfAnimations[ i ].update( frameTime );
|
|
kfAnimations[ i ].update( frameTime );
|
|
|
|
|
|
@@ -204,7 +204,7 @@
|
|
|
|
|
|
} else if ( progress >= 48 ) {
|
|
} else if ( progress >= 48 ) {
|
|
|
|
|
|
- for ( var i = 0, il = kfAnimations.length; i < il; ++i ) {
|
|
|
|
|
|
+ for ( var i = 0; i < kfAnimationsLength; ++i ) {
|
|
|
|
|
|
kfAnimations[ i ].stop();
|
|
kfAnimations[ i ].stop();
|
|
|
|
|