提交 4501d5a5 编写于 作者: G gero3

revert last commit

上级 fe849315
...@@ -84,7 +84,7 @@ Sidebar.Object3D = function ( editor ) { ...@@ -84,7 +84,7 @@ Sidebar.Object3D = function ( editor ) {
var objectNameRow = new UI.Panel(); var objectNameRow = new UI.Panel();
var objectName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () { var objectName = new UI.Input().setWidth( '150px' ).setFontSize( '12px' ).onChange( function () {
editor.nameObject( editor.selected, objectName.getValue() ); editor.nameObject( editor.selected, objectName.getValue() );
} ); } );
......
...@@ -203,17 +203,17 @@ THREE.BlendCharacter = function () { ...@@ -203,17 +203,17 @@ THREE.BlendCharacter = function () {
this.unPauseAll = function() { this.unPauseAll = function() {
for ( var a in this.animations ) { for ( var a in this.animations ) {
if ( this.animations[ a ].isPlaying && this.animations[ a ].isPaused ) { if ( this.animations[ a ].isPlaying && this.animations[ a ].isPaused ) {
this.animations[ a ].pause(); this.animations[ a ].pause();
} }
} }
}; };
this.stopAll = function() { this.stopAll = function() {
......
...@@ -18,12 +18,12 @@ THREE.Curves = {}; ...@@ -18,12 +18,12 @@ THREE.Curves = {};
THREE.Curves.GrannyKnot = THREE.Curve.create( function() {}, THREE.Curves.GrannyKnot = THREE.Curve.create( function() {},
function(t) { function(t) {
t = 2 * Math.PI * t; t = 2 * Math.PI * t;
var x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t); var x = -0.22 * Math.cos(t) - 1.28 * Math.sin(t) - 0.44 * Math.cos(3 * t) - 0.78 * Math.sin(3 * t);
var y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t); var y = -0.1 * Math.cos(2 * t) - 0.27 * Math.sin(2 * t) + 0.38 * Math.cos(4 * t) + 0.46 * Math.sin(4 * t);
var z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t); var z = 0.7 * Math.cos(3 * t) - 0.4 * Math.sin(3 * t);
return new THREE.Vector3(x, y, z).multiplyScalar(20); return new THREE.Vector3(x, y, z).multiplyScalar(20);
} }
); );
...@@ -214,10 +214,10 @@ THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create( ...@@ -214,10 +214,10 @@ THREE.Curves.TrefoilPolynomialKnot = THREE.Curve.create(
// } // }
var scaleTo = function(x, y, t) { var scaleTo = function(x, y, t) {
var r = y - x; var r = y - x;
return t * r + x; return t * r + x;
} }
THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create( THREE.Curves.FigureEightPolynomialKnot = THREE.Curve.create(
......
...@@ -108,9 +108,9 @@ THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segme ...@@ -108,9 +108,9 @@ THREE.ParametricGeometries.TubeGeometry = function(path, segments, radius, segme
binormals = frames.binormals; binormals = frames.binormals;
// proxy internals // proxy internals
this.tangents = tangents; this.tangents = tangents;
this.normals = normals; this.normals = normals;
this.binormals = binormals; this.binormals = binormals;
......
此差异已折叠。
...@@ -19,18 +19,18 @@ var SPARKS = {}; ...@@ -19,18 +19,18 @@ var SPARKS = {};
SPARKS.Emitter = function (counter) { SPARKS.Emitter = function (counter) {
this._counter = counter ? counter : new SPARKS.SteadyCounter(10); // provides number of particles to produce this._counter = counter ? counter : new SPARKS.SteadyCounter(10); // provides number of particles to produce
this._particles = []; this._particles = [];
this._initializers = []; // use for creation of particles this._initializers = []; // use for creation of particles
this._actions = []; // uses action to update particles this._actions = []; // uses action to update particles
this._activities = []; // not supported yet this._activities = []; // not supported yet
this._handlers = []; this._handlers = [];
this.callbacks = {}; this.callbacks = {};
}; };
...@@ -99,108 +99,108 @@ SPARKS.Emitter.prototype = { ...@@ -99,108 +99,108 @@ SPARKS.Emitter.prototype = {
// Update particle engine in seconds, not milliseconds // Update particle engine in seconds, not milliseconds
update: function(time) { update: function(time) {
var i, j; var i, j;
var len = this._counter.updateEmitter( this, time ); var len = this._counter.updateEmitter( this, time );
// Create particles // Create particles
for ( i = 0; i < len; i ++ ) { for ( i = 0; i < len; i ++ ) {
this.createParticle(); this.createParticle();
} }
// Update activities // Update activities
len = this._activities.length; len = this._activities.length;
for ( i = 0; i < len; i ++ ) for ( i = 0; i < len; i ++ )
{ {
this._activities[i].update( this, time ); this._activities[i].update( this, time );
} }
len = this._actions.length; len = this._actions.length;
var particle; var particle;
var action; var action;
var len2 = this._particles.length; var len2 = this._particles.length;
for ( j = 0; j < len; j ++ ) for ( j = 0; j < len; j ++ )
{ {
action = this._actions[j]; action = this._actions[j];
for ( i = 0; i < len2; ++ i ) for ( i = 0; i < len2; ++ i )
{ {
particle = this._particles[i]; particle = this._particles[i];
action.update( this, particle, time ); action.update( this, particle, time );
} }
} }
// remove dead particles // remove dead particles
for ( i = len2; i --; ) for ( i = len2; i --; )
{ {
particle = this._particles[i]; particle = this._particles[i];
if ( particle.isDead ) if ( particle.isDead )
{ {
//particle = //particle =
this._particles.splice( i, 1 ); this._particles.splice( i, 1 );
this.dispatchEvent("dead", particle); this.dispatchEvent("dead", particle);
SPARKS.VectorPool.release(particle.position); // SPARKS.VectorPool.release(particle.position); //
SPARKS.VectorPool.release(particle.velocity); SPARKS.VectorPool.release(particle.velocity);
} else { } else {
this.dispatchEvent("updated", particle); this.dispatchEvent("updated", particle);
} }
} }
this.dispatchEvent("loopUpdated"); this.dispatchEvent("loopUpdated");
}, },
createParticle: function() { createParticle: function() {
var particle = new SPARKS.Particle(); var particle = new SPARKS.Particle();
// In future, use a Particle Factory // In future, use a Particle Factory
var len = this._initializers.length, i; var len = this._initializers.length, i;
for ( i = 0; i < len; i ++ ) { for ( i = 0; i < len; i ++ ) {
this._initializers[i].initialize( this, particle ); this._initializers[i].initialize( this, particle );
} }
this._particles.push( particle ); this._particles.push( particle );
this.dispatchEvent("created", particle); // ParticleCreated this.dispatchEvent("created", particle); // ParticleCreated
return particle; return particle;
}, },
addInitializer: function (initializer) { addInitializer: function (initializer) {
this._initializers.push(initializer); this._initializers.push(initializer);
}, },
addAction: function (action) { addAction: function (action) {
this._actions.push(action); this._actions.push(action);
}, },
removeInitializer: function (initializer) { removeInitializer: function (initializer) {
var index = this._initializers.indexOf(initializer); var index = this._initializers.indexOf(initializer);
if (index > -1) { if (index > -1) {
this._initializers.splice( index, 1 ); this._initializers.splice( index, 1 );
} }
}, },
removeAction: function (action) { removeAction: function (action) {
var index = this._actions.indexOf(action); var index = this._actions.indexOf(action);
if (index > -1) { if (index > -1) {
this._actions.splice( index, 1 ); this._actions.splice( index, 1 );
} }
//console.log('removeAction', index, this._actions); //console.log('removeAction', index, this._actions);
}, },
addCallback: function(name, callback) { addCallback: function(name, callback) {
this.callbacks[name] = callback; this.callbacks[name] = callback;
}, },
dispatchEvent: function(name, args) { dispatchEvent: function(name, args) {
var callback = this.callbacks[name]; var callback = this.callbacks[name];
if (callback) { if (callback) {
callback(args); callback(args);
} }
} }
...@@ -227,7 +227,7 @@ SPARKS.EVENT_LOOP_UPDATED = "loopUpdated"; ...@@ -227,7 +227,7 @@ SPARKS.EVENT_LOOP_UPDATED = "loopUpdated";
// Number of particles per seconds // Number of particles per seconds
SPARKS.SteadyCounter = function(rate) { SPARKS.SteadyCounter = function(rate) {
this.rate = rate; this.rate = rate;
// we use a shortfall counter to make up for slow emitters // we use a shortfall counter to make up for slow emitters
this.leftover = 0; this.leftover = 0;
...@@ -277,31 +277,31 @@ SPARKS.Particle = function() { ...@@ -277,31 +277,31 @@ SPARKS.Particle = function() {
/** /**
* The lifetime of the particle, in seconds. * The lifetime of the particle, in seconds.
*/ */
this.lifetime = 0; this.lifetime = 0;
/** /**
* The age of the particle, in seconds. * The age of the particle, in seconds.
*/ */
this.age = 0; this.age = 0;
/** /**
* The energy of the particle. * The energy of the particle.
*/ */
this.energy = 1; this.energy = 1;
/** /**
* Whether the particle is dead and should be removed from the stage. * Whether the particle is dead and should be removed from the stage.
*/ */
this.isDead = false; this.isDead = false;
this.target = null; // tag this.target = null; // tag
/** /**
* For 3D * For 3D
*/ */
this.position = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 ); this.position = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 );
this.velocity = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 ); this.velocity = SPARKS.VectorPool.get().set(0, 0, 0); //new THREE.Vector3( 0, 0, 0 );
this._oldvelocity = SPARKS.VectorPool.get().set(0, 0, 0); this._oldvelocity = SPARKS.VectorPool.get().set(0, 0, 0);
// rotation vec3 // rotation vec3
// angVelocity vec3 // angVelocity vec3
...@@ -317,26 +317,26 @@ SPARKS.Particle = function() { ...@@ -317,26 +317,26 @@ SPARKS.Particle = function() {
* update function * update function
*********************************/ *********************************/
SPARKS.Action = function() { SPARKS.Action = function() {
this._priority = 0; this._priority = 0;
}; };
SPARKS.Age = function(easing) { SPARKS.Age = function(easing) {
this._easing = (easing == null) ? TWEEN.Easing.Linear.None : easing; this._easing = (easing == null) ? TWEEN.Easing.Linear.None : easing;
}; };
SPARKS.Age.prototype.update = function (emitter, particle, time) { SPARKS.Age.prototype.update = function (emitter, particle, time) {
particle.age += time; particle.age += time;
if ( particle.age >= particle.lifetime ) if ( particle.age >= particle.lifetime )
{ {
particle.energy = 0; particle.energy = 0;
particle.isDead = true; particle.isDead = true;
} }
else else
{ {
var t = this._easing(particle.age / particle.lifetime); var t = this._easing(particle.age / particle.lifetime);
particle.energy = -1 * t + 1; particle.energy = -1 * t + 1;
} }
}; };
/* /*
...@@ -360,9 +360,9 @@ SPARKS.Move = function() { ...@@ -360,9 +360,9 @@ SPARKS.Move = function() {
SPARKS.Move.prototype.update = function(emitter, particle, time) { SPARKS.Move.prototype.update = function(emitter, particle, time) {
// attempt verlet velocity updating. // attempt verlet velocity updating.
var p = particle.position; var p = particle.position;
var v = particle.velocity; var v = particle.velocity;
var old = particle._oldvelocity; var old = particle._oldvelocity;
if (this._velocityVerlet) { if (this._velocityVerlet) {
p.x += (v.x + old.x) * 0.5 * time; p.x += (v.x + old.x) * 0.5 * time;
...@@ -384,12 +384,12 @@ SPARKS.Move.prototype.update = function(emitter, particle, time) { ...@@ -384,12 +384,12 @@ SPARKS.Move.prototype.update = function(emitter, particle, time) {
/* Marks particles found in specified zone dead */ /* Marks particles found in specified zone dead */
SPARKS.DeathZone = function(zone) { SPARKS.DeathZone = function(zone) {
this.zone = zone; this.zone = zone;
}; };
SPARKS.DeathZone.prototype.update = function(emitter, particle, time) { SPARKS.DeathZone.prototype.update = function(emitter, particle, time) {
if (this.zone.contains(particle.position)) { if (this.zone.contains(particle.position)) {
particle.isDead = true; particle.isDead = true;
} }
...@@ -400,12 +400,12 @@ SPARKS.DeathZone.prototype.update = function(emitter, particle, time) { ...@@ -400,12 +400,12 @@ SPARKS.DeathZone.prototype.update = function(emitter, particle, time) {
*/ */
SPARKS.ActionZone = function(action, zone) { SPARKS.ActionZone = function(action, zone) {
this.action = action; this.action = action;
this.zone = zone; this.zone = zone;
}; };
SPARKS.ActionZone.prototype.update = function(emitter, particle, time) { SPARKS.ActionZone.prototype.update = function(emitter, particle, time) {
if (this.zone.contains(particle.position)) { if (this.zone.contains(particle.position)) {
this.action.update( emitter, particle, time ); this.action.update( emitter, particle, time );
} }
...@@ -421,20 +421,20 @@ SPARKS.Accelerate = function(x,y,z) { ...@@ -421,20 +421,20 @@ SPARKS.Accelerate = function(x,y,z) {
return; return;
} }
this.acceleration = new THREE.Vector3(x,y,z); this.acceleration = new THREE.Vector3(x,y,z);
}; };
SPARKS.Accelerate.prototype.update = function(emitter, particle, time) { SPARKS.Accelerate.prototype.update = function(emitter, particle, time) {
var acc = this.acceleration; var acc = this.acceleration;
var v = particle.velocity; var v = particle.velocity;
particle._oldvelocity.set(v.x, v.y, v.z); particle._oldvelocity.set(v.x, v.y, v.z);
v.x += acc.x * time; v.x += acc.x * time;
v.y += acc.y * time; v.y += acc.y * time;
v.z += acc.z * time; v.z += acc.z * time;
}; };
...@@ -442,16 +442,16 @@ SPARKS.Accelerate.prototype.update = function(emitter, particle, time) { ...@@ -442,16 +442,16 @@ SPARKS.Accelerate.prototype.update = function(emitter, particle, time) {
* Accelerate Factor accelerate based on a factor of particle's velocity. * Accelerate Factor accelerate based on a factor of particle's velocity.
*/ */
SPARKS.AccelerateFactor = function(factor) { SPARKS.AccelerateFactor = function(factor) {
this.factor = factor; this.factor = factor;
}; };
SPARKS.AccelerateFactor.prototype.update = function(emitter, particle, time) { SPARKS.AccelerateFactor.prototype.update = function(emitter, particle, time) {
var factor = this.factor; var factor = this.factor;
var v = particle.velocity; var v = particle.velocity;
var len = v.length(); var len = v.length();
var adjFactor; var adjFactor;
if (len > 0) { if (len > 0) {
adjFactor = factor * time / len; adjFactor = factor * time / len;
adjFactor += 1; adjFactor += 1;
...@@ -475,14 +475,14 @@ SPARKS.AccelerateVelocity = function(factor) { ...@@ -475,14 +475,14 @@ SPARKS.AccelerateVelocity = function(factor) {
}; };
SPARKS.AccelerateVelocity.prototype.update = function(emitter, particle, time) { SPARKS.AccelerateVelocity.prototype.update = function(emitter, particle, time) {
var factor = this.factor; var factor = this.factor;
var v = particle.velocity; var v = particle.velocity;
v.z += - v.x * factor; v.z += - v.x * factor;
v.y += v.z * factor; v.y += v.z * factor;
v.x += v.y * factor; v.x += v.y * factor;
}; };
...@@ -494,18 +494,18 @@ SPARKS.RandomDrift = function(x,y,z) { ...@@ -494,18 +494,18 @@ SPARKS.RandomDrift = function(x,y,z) {
return; return;
} }
this.drift = new THREE.Vector3(x,y,z); this.drift = new THREE.Vector3(x,y,z);
} }
SPARKS.RandomDrift.prototype.update = function(emitter, particle, time) { SPARKS.RandomDrift.prototype.update = function(emitter, particle, time) {
var drift = this.drift; var drift = this.drift;
var v = particle.velocity; var v = particle.velocity;
v.x += ( Math.random() - 0.5 ) * drift.x * time; v.x += ( Math.random() - 0.5 ) * drift.x * time;
v.y += ( Math.random() - 0.5 ) * drift.y * time; v.y += ( Math.random() - 0.5 ) * drift.y * time;
v.z += ( Math.random() - 0.5 ) * drift.z * time; v.z += ( Math.random() - 0.5 ) * drift.z * time;
}; };
...@@ -521,29 +521,29 @@ SPARKS.Zone = function() { ...@@ -521,29 +521,29 @@ SPARKS.Zone = function() {
// TODO, contains() for Zone // TODO, contains() for Zone
SPARKS.PointZone = function(pos) { SPARKS.PointZone = function(pos) {
this.pos = pos; this.pos = pos;
}; };
SPARKS.PointZone.prototype.getLocation = function() { SPARKS.PointZone.prototype.getLocation = function() {
return this.pos; return this.pos;
}; };
SPARKS.PointZone = function(pos) { SPARKS.PointZone = function(pos) {
this.pos = pos; this.pos = pos;
}; };
SPARKS.PointZone.prototype.getLocation = function() { SPARKS.PointZone.prototype.getLocation = function() {
return this.pos; return this.pos;
}; };
SPARKS.LineZone = function(start, end) { SPARKS.LineZone = function(start, end) {
this.start = start; this.start = start;
this.end = end; this.end = end;
this._length = end.clone().sub( start ); this._length = end.clone().sub( start );
}; };
SPARKS.LineZone.prototype.getLocation = function() { SPARKS.LineZone.prototype.getLocation = function() {
var len = this._length.clone(); var len = this._length.clone();
len.multiplyScalar( Math.random() ); len.multiplyScalar( Math.random() );
return len.add( this.start ); return len.add( this.start );
...@@ -552,7 +552,7 @@ SPARKS.LineZone.prototype.getLocation = function() { ...@@ -552,7 +552,7 @@ SPARKS.LineZone.prototype.getLocation = function() {
// Basically a RectangleZone // Basically a RectangleZone
SPARKS.ParallelogramZone = function(corner, side1, side2) { SPARKS.ParallelogramZone = function(corner, side1, side2) {
this.corner = corner; this.corner = corner;
this.side1 = side1; this.side1 = side1;
this.side2 = side2; this.side2 = side2;
}; };
...@@ -567,7 +567,7 @@ SPARKS.ParallelogramZone.prototype.getLocation = function() { ...@@ -567,7 +567,7 @@ SPARKS.ParallelogramZone.prototype.getLocation = function() {
}; };
SPARKS.CubeZone = function(position, x, y, z) { SPARKS.CubeZone = function(position, x, y, z) {
this.position = position; this.position = position;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
...@@ -674,29 +674,29 @@ SPARKS.DiscZone.prototype.getLocation = function() { ...@@ -674,29 +674,29 @@ SPARKS.DiscZone.prototype.getLocation = function() {
*/ */
SPARKS.SphereCapZone = function(x, y, z, minr, maxr, angle) { SPARKS.SphereCapZone = function(x, y, z, minr, maxr, angle) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.minr = minr; this.minr = minr;
this.maxr = maxr; this.maxr = maxr;
this.angle = angle; this.angle = angle;
}; };
SPARKS.SphereCapZone.prototype.getLocation = function() { SPARKS.SphereCapZone.prototype.getLocation = function() {
var theta = Math.PI * 2 * SPARKS.Utils.random(); var theta = Math.PI * 2 * SPARKS.Utils.random();
var r = SPARKS.Utils.random(); var r = SPARKS.Utils.random();
//new THREE.Vector3 //new THREE.Vector3
var v = SPARKS.VectorPool.get().set(r * Math.cos(theta), -1 / Math.tan(this.angle * SPARKS.Utils.DEGREE_TO_RADIAN), r * Math.sin(theta)); var v = SPARKS.VectorPool.get().set(r * Math.cos(theta), -1 / Math.tan(this.angle * SPARKS.Utils.DEGREE_TO_RADIAN), r * Math.sin(theta));
//v.length = StardustMath.interpolate(0, _minRadius, 1, _maxRadius, Math.random()); //v.length = StardustMath.interpolate(0, _minRadius, 1, _maxRadius, Math.random());
var i = this.minr - ((this.minr - this.maxr) * Math.random() ); var i = this.minr - ((this.minr - this.maxr) * Math.random() );
v.multiplyScalar(i); v.multiplyScalar(i);
v.__markedForReleased = true; v.__markedForReleased = true;
return v; return v;
}; };
...@@ -709,33 +709,33 @@ SPARKS.SphereCapZone.prototype.getLocation = function() { ...@@ -709,33 +709,33 @@ SPARKS.SphereCapZone.prototype.getLocation = function() {
// Specifies random life between max and min // Specifies random life between max and min
SPARKS.Lifetime = function(min, max) { SPARKS.Lifetime = function(min, max) {
this._min = min; this._min = min;
this._max = max ? max : min; this._max = max ? max : min;
}; };
SPARKS.Lifetime.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) { SPARKS.Lifetime.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
particle.lifetime = this._min + SPARKS.Utils.random() * ( this._max - this._min ); particle.lifetime = this._min + SPARKS.Utils.random() * ( this._max - this._min );
}; };
SPARKS.Position = function(zone) { SPARKS.Position = function(zone) {
this.zone = zone; this.zone = zone;
}; };
SPARKS.Position.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) { SPARKS.Position.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
var pos = this.zone.getLocation(); var pos = this.zone.getLocation();
particle.position.set(pos.x, pos.y, pos.z); particle.position.set(pos.x, pos.y, pos.z);
}; };
SPARKS.Velocity = function(zone) { SPARKS.Velocity = function(zone) {
this.zone = zone; this.zone = zone;
}; };
SPARKS.Velocity.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) { SPARKS.Velocity.prototype.initialize = function( emitter/*Emitter*/, particle/*Particle*/ ) {
var pos = this.zone.getLocation(); var pos = this.zone.getLocation();
particle.velocity.set(pos.x, pos.y, pos.z); particle.velocity.set(pos.x, pos.y, pos.z);
if (pos.__markedForReleased) { if (pos.__markedForReleased) {
//console.log("release"); //console.log("release");
SPARKS.VectorPool.release(pos); SPARKS.VectorPool.release(pos);
...@@ -744,17 +744,17 @@ SPARKS.Velocity.prototype.initialize = function( emitter/*Emitter*/, particle/*P ...@@ -744,17 +744,17 @@ SPARKS.Velocity.prototype.initialize = function( emitter/*Emitter*/, particle/*P
}; };
SPARKS.Target = function(target, callback) { SPARKS.Target = function(target, callback) {
this.target = target; this.target = target;
this.callback = callback; this.callback = callback;
}; };
SPARKS.Target.prototype.initialize = function( emitter, particle ) { SPARKS.Target.prototype.initialize = function( emitter, particle ) {
if (this.callback) { if (this.callback) {
particle.target = this.callback(); particle.target = this.callback();
} else { } else {
particle.target = this.target; particle.target = this.target;
} }
}; };
...@@ -807,7 +807,7 @@ SPARKS.VectorPool = { ...@@ -807,7 +807,7 @@ SPARKS.VectorPool = {
*********************************/ *********************************/
SPARKS.Utils = { SPARKS.Utils = {
random: function() { random: function() {
return Math.random(); return Math.random();
}, },
DEGREE_TO_RADIAN: Math.PI / 180, DEGREE_TO_RADIAN: Math.PI / 180,
TWOPI: Math.PI * 2, TWOPI: Math.PI * 2,
......
...@@ -6,50 +6,50 @@ ...@@ -6,50 +6,50 @@
THREE.MouseControls = function ( object ) { THREE.MouseControls = function ( object ) {
var scope = this; var scope = this;
var PI_2 = Math.PI / 2; var PI_2 = Math.PI / 2;
var mouseQuat = { var mouseQuat = {
x: new THREE.Quaternion(), x: new THREE.Quaternion(),
y: new THREE.Quaternion() y: new THREE.Quaternion()
}; };
var object = object; var object = object;
var xVector = new THREE.Vector3( 1, 0, 0 ); var xVector = new THREE.Vector3( 1, 0, 0 );
var yVector = new THREE.Vector3( 0, 1, 0 ); var yVector = new THREE.Vector3( 0, 1, 0 );
var onMouseMove = function ( event ) { var onMouseMove = function ( event ) {
if ( scope.enabled === false ) return; if ( scope.enabled === false ) return;
var orientation = scope.orientation; var orientation = scope.orientation;
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0; var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0; var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
orientation.y += movementX * 0.0025; orientation.y += movementX * 0.0025;
orientation.x += movementY * 0.0025; orientation.x += movementY * 0.0025;
orientation.x = Math.max( - PI_2, Math.min( PI_2, orientation.x ) ); orientation.x = Math.max( - PI_2, Math.min( PI_2, orientation.x ) );
}; };
this.enabled = true; this.enabled = true;
this.orientation = { this.orientation = {
x: 0, x: 0,
y: 0, y: 0,
}; };
this.update = function() { this.update = function() {
if ( this.enabled === false ) return; if ( this.enabled === false ) return;
mouseQuat.x.setFromAxisAngle( xVector, this.orientation.x ); mouseQuat.x.setFromAxisAngle( xVector, this.orientation.x );
mouseQuat.y.setFromAxisAngle( yVector, this.orientation.y ); mouseQuat.y.setFromAxisAngle( yVector, this.orientation.y );
object.quaternion.copy(mouseQuat.y).multiply(mouseQuat.x) object.quaternion.copy(mouseQuat.y).multiply(mouseQuat.x)
return; return;
}; };
document.addEventListener( 'mousemove', onMouseMove, false ); document.addEventListener( 'mousemove', onMouseMove, false );
}; };
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
} else { } else {
this.color.copy( this.oldColor ); this.color.copy( this.oldColor );
this.opacity = this.oldOpacity; this.opacity = this.oldOpacity;
} }
...@@ -65,8 +65,8 @@ ...@@ -65,8 +65,8 @@
} else { } else {
this.color.copy( this.oldColor ); this.color.copy( this.oldColor );
this.opacity = this.oldOpacity; this.opacity = this.oldOpacity;
} }
...@@ -331,15 +331,15 @@ ...@@ -331,15 +331,15 @@
var CircleGeometry = function ( radius, facing, arc ) { var CircleGeometry = function ( radius, facing, arc ) {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
arc = arc ? arc : 1; arc = arc ? arc : 1;
for ( var i = 0; i <= 64 * arc; ++ i ) { for ( var i = 0; i <= 64 * arc; ++ i ) {
if ( facing == 'x' ) geometry.vertices.push( new THREE.Vector3( 0, Math.cos( i / 32 * Math.PI ), Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) ); if ( facing == 'x' ) geometry.vertices.push( new THREE.Vector3( 0, Math.cos( i / 32 * Math.PI ), Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
if ( facing == 'y' ) geometry.vertices.push( new THREE.Vector3( Math.cos( i / 32 * Math.PI ), 0, Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) ); if ( facing == 'y' ) geometry.vertices.push( new THREE.Vector3( Math.cos( i / 32 * Math.PI ), 0, Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
if ( facing == 'z' ) geometry.vertices.push( new THREE.Vector3( Math.sin( i / 32 * Math.PI ), Math.cos( i / 32 * Math.PI ), 0 ).multiplyScalar(radius) ); if ( facing == 'z' ) geometry.vertices.push( new THREE.Vector3( Math.sin( i / 32 * Math.PI ), Math.cos( i / 32 * Math.PI ), 0 ).multiplyScalar(radius) );
} }
return geometry; return geometry;
}; };
this.handleGizmos = { this.handleGizmos = {
......
...@@ -56,7 +56,7 @@ THREE.VREffect = function ( renderer, done ) { ...@@ -56,7 +56,7 @@ THREE.VREffect = function ( renderer, done ) {
} }
if ( done ) { if ( done ) {
if ( !vrHMD ) { if ( !vrHMD ) {
error = 'HMD not available'; error = 'HMD not available';
} }
done( error ); done( error );
} }
......
...@@ -176,14 +176,14 @@ THREE.ConvexGeometry = function( vertices ) { ...@@ -176,14 +176,14 @@ THREE.ConvexGeometry = function( vertices ) {
for ( var j = 0; j < 3; j ++ ) { for ( var j = 0; j < 3; j ++ ) {
if ( newId[ face[ j ] ] === undefined ) { if ( newId[ face[ j ] ] === undefined ) {
newId[ face[ j ] ] = id ++; newId[ face[ j ] ] = id ++;
this.vertices.push( vertices[ face[ j ] ] ); this.vertices.push( vertices[ face[ j ] ] );
} }
face[ j ] = newId[ face[ j ] ]; face[ j ] = newId[ face[ j ] ];
} }
......
...@@ -191,8 +191,8 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) { ...@@ -191,8 +191,8 @@ THREE.DecalGeometry = function( mesh, position, rotation, dimensions, check ) {
vertices = this.clipFace( vertices, new THREE.Vector3( -1, 0, 0 ) ); vertices = this.clipFace( vertices, new THREE.Vector3( -1, 0, 0 ) );
} }
if ( check.y ) { if ( check.y ) {
vertices = this.clipFace( vertices, new THREE.Vector3( 0, 1, 0 ) ); vertices = this.clipFace( vertices, new THREE.Vector3( 0, 1, 0 ) );
vertices = this.clipFace( vertices, new THREE.Vector3( 0, -1, 0 ) ); vertices = this.clipFace( vertices, new THREE.Vector3( 0, -1, 0 ) );
} }
if ( check.z ) { if ( check.z ) {
vertices = this.clipFace( vertices, new THREE.Vector3( 0, 0, 1 ) ); vertices = this.clipFace( vertices, new THREE.Vector3( 0, 0, 1 ) );
......
此差异已折叠。
...@@ -735,7 +735,7 @@ THREE.ColladaLoader = function () { ...@@ -735,7 +735,7 @@ THREE.ColladaLoader = function () {
// move vertices to bind shape // move vertices to bind shape
for ( i = 0; i < geometry.vertices.length; i ++ ) { for ( i = 0; i < geometry.vertices.length; i ++ ) {
geometry.vertices[i].applyMatrix4( skinController.skin.bindShapeMatrix ); geometry.vertices[i].applyMatrix4( skinController.skin.bindShapeMatrix );
} }
var skinIndices = []; var skinIndices = [];
...@@ -1343,17 +1343,17 @@ THREE.ColladaLoader = function () { ...@@ -1343,17 +1343,17 @@ THREE.ColladaLoader = function () {
function getLibraryNode( id ) { function getLibraryNode( id ) {
var nodes = COLLADA.querySelectorAll('library_nodes node'); var nodes = COLLADA.querySelectorAll('library_nodes node');
for ( var i = 0; i < nodes.length; i ++ ) { for ( var i = 0; i < nodes.length; i ++ ) {
var attObj = nodes[i].attributes.getNamedItem('id'); var attObj = nodes[i].attributes.getNamedItem('id');
if ( attObj && attObj.value === id ) { if ( attObj && attObj.value === id ) {
return nodes[i]; return nodes[i];
} }
} }
return undefined; return undefined;
}; };
...@@ -3365,35 +3365,35 @@ THREE.ColladaLoader = function () { ...@@ -3365,35 +3365,35 @@ THREE.ColladaLoader = function () {
//for (var i = 0; i < this.accessor.params.length; i++) { //for (var i = 0; i < this.accessor.params.length; i++) {
var param = this.accessor.params[ 0 ]; var param = this.accessor.params[ 0 ];
//console.log(param.name + " " + param.type); //console.log(param.name + " " + param.type);
switch ( param.type ) { switch ( param.type ) {
case 'IDREF': case 'IDREF':
case 'Name': case 'name': case 'Name': case 'name':
case 'float': case 'float':
return this.data; return this.data;
case 'float4x4': case 'float4x4':
for ( var j = 0; j < this.data.length; j += 16 ) { for ( var j = 0; j < this.data.length; j += 16 ) {
var s = this.data.slice( j, j + 16 ); var s = this.data.slice( j, j + 16 );
var m = getConvertedMat4( s ); var m = getConvertedMat4( s );
result.push( m ); result.push( m );
} }
break; break;
default: default:
console.log( 'ColladaLoader: Source: Read dont know how to read ' + param.type + '.' ); console.log( 'ColladaLoader: Source: Read dont know how to read ' + param.type + '.' );
break; break;
} }
//} //}
......
...@@ -77,16 +77,16 @@ THREE.PVRLoader._parseV3 = function ( pvrDatas ) { ...@@ -77,16 +77,16 @@ THREE.PVRLoader._parseV3 = function ( pvrDatas ) {
} }
pvrDatas.dataPtr = 52 + metaLen; pvrDatas.dataPtr = 52 + metaLen;
pvrDatas.bpp = bpp; pvrDatas.bpp = bpp;
pvrDatas.format = format; pvrDatas.format = format;
pvrDatas.width = width; pvrDatas.width = width;
pvrDatas.height = height; pvrDatas.height = height;
pvrDatas.numSurfaces = numFaces; pvrDatas.numSurfaces = numFaces;
pvrDatas.numMipmaps = numMipmaps; pvrDatas.numMipmaps = numMipmaps;
pvrDatas.isCubemap = (numFaces === 6); pvrDatas.isCubemap = (numFaces === 6);
return THREE.PVRLoader._extract( pvrDatas ); return THREE.PVRLoader._extract( pvrDatas );
}; };
THREE.PVRLoader._parseV2 = function ( pvrDatas ) { THREE.PVRLoader._parseV2 = function ( pvrDatas ) {
...@@ -133,18 +133,18 @@ THREE.PVRLoader._parseV2 = function ( pvrDatas ) { ...@@ -133,18 +133,18 @@ THREE.PVRLoader._parseV2 = function ( pvrDatas ) {
pvrDatas.dataPtr = headerLength; pvrDatas.dataPtr = headerLength;
pvrDatas.bpp = bpp; pvrDatas.bpp = bpp;
pvrDatas.format = format; pvrDatas.format = format;
pvrDatas.width = width; pvrDatas.width = width;
pvrDatas.height = height; pvrDatas.height = height;
pvrDatas.numSurfaces = numSurfs; pvrDatas.numSurfaces = numSurfs;
pvrDatas.numMipmaps = numMipmaps + 1; pvrDatas.numMipmaps = numMipmaps + 1;
// guess cubemap type seems tricky in v2 // guess cubemap type seems tricky in v2
// it juste a pvr containing 6 surface (no explicit cubemap type) // it juste a pvr containing 6 surface (no explicit cubemap type)
pvrDatas.isCubemap = (numSurfs === 6); pvrDatas.isCubemap = (numSurfs === 6);
return THREE.PVRLoader._extract( pvrDatas ); return THREE.PVRLoader._extract( pvrDatas );
}; };
......
...@@ -30,11 +30,11 @@ THREE.RGBELoader.prototype._parser = function( buffer ) { ...@@ -30,11 +30,11 @@ THREE.RGBELoader.prototype._parser = function( buffer ) {
rgbe_error = function(rgbe_error_code, msg) { rgbe_error = function(rgbe_error_code, msg) {
switch (rgbe_error_code) { switch (rgbe_error_code) {
case rgbe_read_error: console.error("THREE.RGBELoader Read Error: " + (msg||'')); case rgbe_read_error: console.error("THREE.RGBELoader Read Error: " + (msg||''));
break; break;
case rgbe_write_error: console.error("THREE.RGBELoader Write Error: " + (msg||'')); case rgbe_write_error: console.error("THREE.RGBELoader Write Error: " + (msg||''));
break; break;
case rgbe_format_error: console.error("THREE.RGBELoader Bad File Format: " + (msg||'')); case rgbe_format_error: console.error("THREE.RGBELoader Bad File Format: " + (msg||''));
break; break;
default: default:
case rgbe_memory_error: console.error("THREE.RGBELoader: Error: " + (msg||'')); case rgbe_memory_error: console.error("THREE.RGBELoader: Error: " + (msg||''));
} }
......
...@@ -110,15 +110,15 @@ THREE.STLLoader.prototype = { ...@@ -110,15 +110,15 @@ THREE.STLLoader.prototype = {
(reader.getUint8(index + 4) == 0x52 /*'R'*/) && (reader.getUint8(index + 4) == 0x52 /*'R'*/) &&
(reader.getUint8(index + 5) == 0x3D /*'='*/)) { (reader.getUint8(index + 5) == 0x3D /*'='*/)) {
hasColors = true; hasColors = true;
colors = new Float32Array( faces * 3 * 3); colors = new Float32Array( faces * 3 * 3);
defaultR = reader.getUint8(index + 6) / 255; defaultR = reader.getUint8(index + 6) / 255;
defaultG = reader.getUint8(index + 7) / 255; defaultG = reader.getUint8(index + 7) / 255;
defaultB = reader.getUint8(index + 8) / 255; defaultB = reader.getUint8(index + 8) / 255;
alpha = reader.getUint8(index + 9) / 255; alpha = reader.getUint8(index + 9) / 255;
}
} }
}
var dataOffset = 84; var dataOffset = 84;
var faceLength = 12 * 4 + 2; var faceLength = 12 * 4 + 2;
......
...@@ -154,8 +154,8 @@ THREE.TGALoader.prototype._parser = function ( buffer ) { ...@@ -154,8 +154,8 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
pixel_total, pixel_total,
palettes; palettes;
pixel_size = header.pixel_size >> 3; pixel_size = header.pixel_size >> 3;
pixel_total = header.width * header.height * pixel_size; pixel_total = header.width * header.height * pixel_size;
// Read palettes // Read palettes
if ( use_pal ) { if ( use_pal ) {
...@@ -178,12 +178,12 @@ THREE.TGALoader.prototype._parser = function ( buffer ) { ...@@ -178,12 +178,12 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
if (c & 0x80) { if (c & 0x80) {
// Bind pixel tmp array // Bind pixel tmp array
for (i = 0; i < pixel_size; ++ i) { for (i = 0; i < pixel_size; ++ i) {
pixels[i] = data[offset ++]; pixels[i] = data[offset ++];
} }
// Copy pixel array // Copy pixel array
for (i = 0; i < count; ++ i) { for (i = 0; i < count; ++ i) {
pixel_data.set(pixels, shift + i * pixel_size); pixel_data.set(pixels, shift + i * pixel_size);
} }
shift += pixel_size * count; shift += pixel_size * count;
...@@ -192,7 +192,7 @@ THREE.TGALoader.prototype._parser = function ( buffer ) { ...@@ -192,7 +192,7 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
// Raw pixels. // Raw pixels.
count *= pixel_size; count *= pixel_size;
for (i = 0; i < count; ++ i) { for (i = 0; i < count; ++ i) {
pixel_data[shift + i] = data[offset ++]; pixel_data[shift + i] = data[offset ++];
} }
shift += count; shift += count;
} }
...@@ -214,7 +214,7 @@ THREE.TGALoader.prototype._parser = function ( buffer ) { ...@@ -214,7 +214,7 @@ THREE.TGALoader.prototype._parser = function ( buffer ) {
var colormap = palettes; var colormap = palettes;
var color, i = 0, x, y; var color, i = 0, x, y;
var width = header.width; var width = header.width;
for (y = y_start; y !== y_end; y += y_step) { for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i ++) { for (x = x_start; x !== x_end; x += x_step, i ++) {
......
此差异已折叠。
...@@ -260,7 +260,7 @@ THREE.VRMLLoader.prototype = { ...@@ -260,7 +260,7 @@ THREE.VRMLLoader.prototype = {
// end of current face // end of current face
if (parts[ind] === "-1") { if (parts[ind] === "-1") {
if (index.length > 0) { if (index.length > 0) {
this.indexes.push(index); this.indexes.push(index);
} }
// start new one // start new one
......
此差异已折叠。
此差异已折叠。
...@@ -430,7 +430,7 @@ THREE.SceneLoader.prototype = { ...@@ -430,7 +430,7 @@ THREE.SceneLoader.prototype = {
} else if ( objJSON.target ) { } else if ( objJSON.target ) {
camera.lookAt( new THREE.Vector3().fromArray( objJSON.target ) ); camera.lookAt( new THREE.Vector3().fromArray( objJSON.target ) );
} }
......
...@@ -49,35 +49,35 @@ ...@@ -49,35 +49,35 @@
*/ */
var global = window; var global = window;
(function (root, factory) { (function (root, factory) {
if (typeof exports === 'object') { if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but // Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports, // only CommonJS-like enviroments that support module.exports,
// like Node. // like Node.
factory(module.exports); factory(module.exports);
} else if (typeof define === 'function' && define.amd) { } else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define([], function () { define([], function () {
return factory(root); return factory(root);
}); });
} else { } else {
// Browser globals // Browser globals
factory(root); factory(root);
} }
}(this, function (root) { }(this, function (root) {
"use strict"; "use strict";
var categoriesDepsOrder = [ "buffers", "bufferViews", "images", "videos", "samplers", "textures", "shaders", "programs", "techniques", "materials", "accessors", "meshes", "cameras", "lights", "skins", "nodes", "scenes", "animations" ]; var categoriesDepsOrder = [ "buffers", "bufferViews", "images", "videos", "samplers", "textures", "shaders", "programs", "techniques", "materials", "accessors", "meshes", "cameras", "lights", "skins", "nodes", "scenes", "animations" ];
var glTFParser = Object.create(Object.prototype, { var glTFParser = Object.create(Object.prototype, {
_rootDescription: { value: null, writable: true }, _rootDescription: { value: null, writable: true },
rootDescription: { rootDescription: {
set: function(value) { set: function(value) {
this._rootDescription = value; this._rootDescription = value;
}, },
get: function() { get: function() {
return this._rootDescription; return this._rootDescription;
} }
}, },
...@@ -86,34 +86,34 @@ var global = window; ...@@ -86,34 +86,34 @@ var global = window;
//detect absolute path following the same protocol than window.location //detect absolute path following the same protocol than window.location
_isAbsolutePath: { _isAbsolutePath: {
value: function(path) { value: function(path) {
var isAbsolutePathRegExp = new RegExp("^" + window.location.protocol, "i"); var isAbsolutePathRegExp = new RegExp("^" + window.location.protocol, "i");
return path.match(isAbsolutePathRegExp) ? true : false; return path.match(isAbsolutePathRegExp) ? true : false;
} }
}, },
resolvePathIfNeeded: { resolvePathIfNeeded: {
value: function(path) { value: function(path) {
if (this._isAbsolutePath(path)) { if (this._isAbsolutePath(path)) {
return path; return path;
} }
return this.baseURL + path; return this.baseURL + path;
} }
}, },
_resolvePathsForCategories: { _resolvePathsForCategories: {
value: function(categories) { value: function(categories) {
categories.forEach( function(category) { categories.forEach( function(category) {
var descriptions = this.json[category]; var descriptions = this.json[category];
if (descriptions) { if (descriptions) {
var descriptionKeys = Object.keys(descriptions); var descriptionKeys = Object.keys(descriptions);
descriptionKeys.forEach( function(descriptionKey) { descriptionKeys.forEach( function(descriptionKey) {
var description = descriptions[descriptionKey]; var description = descriptions[descriptionKey];
description.path = this.resolvePathIfNeeded(description.path); description.path = this.resolvePathIfNeeded(description.path);
}, this); }, this);
} }
}, this); }, this);
} }
}, },
...@@ -125,13 +125,13 @@ var global = window; ...@@ -125,13 +125,13 @@ var global = window;
json: { json: {
enumerable: true, enumerable: true,
get: function() { get: function() {
return this._json; return this._json;
}, },
set: function(value) { set: function(value) {
if (this._json !== value) { if (this._json !== value) {
this._json = value; this._json = value;
this._resolvePathsForCategories([ "buffers", "shaders", "images", "videos" ]); this._resolvePathsForCategories([ "buffers", "shaders", "images", "videos" ]);
} }
} }
}, },
...@@ -142,60 +142,60 @@ var global = window; ...@@ -142,60 +142,60 @@ var global = window;
getEntryDescription: { getEntryDescription: {
value: function (entryID, entryType) { value: function (entryID, entryType) {
var entries = null; var entries = null;
var category = entryType; var category = entryType;
entries = this.rootDescription[category]; entries = this.rootDescription[category];
if (!entries) { if (!entries) {
console.log("ERROR:CANNOT find expected category named:" + category); console.log("ERROR:CANNOT find expected category named:" + category);
return null; return null;
} }
return entries ? entries[entryID] : null; return entries ? entries[entryID] : null;
} }
}, },
_stepToNextCategory: { _stepToNextCategory: {
value: function() { value: function() {
this._state.categoryIndex = this.getNextCategoryIndex(this._state.categoryIndex + 1); this._state.categoryIndex = this.getNextCategoryIndex(this._state.categoryIndex + 1);
if (this._state.categoryIndex !== -1) { if (this._state.categoryIndex !== -1) {
this._state.categoryState.index = 0; this._state.categoryState.index = 0;
return true; return true;
} }
return false; return false;
} }
}, },
_stepToNextDescription: { _stepToNextDescription: {
enumerable: false, enumerable: false,
value: function() { value: function() {
var categoryState = this._state.categoryState; var categoryState = this._state.categoryState;
var keys = categoryState.keys; var keys = categoryState.keys;
if (!keys) { if (!keys) {
console.log("INCONSISTENCY ERROR"); console.log("INCONSISTENCY ERROR");
return false; return false;
} }
categoryState.index ++; categoryState.index ++;
categoryState.keys = null; categoryState.keys = null;
if (categoryState.index >= keys.length) { if (categoryState.index >= keys.length) {
return this._stepToNextCategory(); return this._stepToNextCategory();
} }
return false; return false;
} }
}, },
hasCategory: { hasCategory: {
value: function(category) { value: function(category) {
return this.rootDescription[category] ? true : false; return this.rootDescription[category] ? true : false;
} }
}, },
_handleState: { _handleState: {
value: function() { value: function() {
var methodForType = { var methodForType = {
"buffers" : this.handleBuffer, "buffers" : this.handleBuffer,
"bufferViews" : this.handleBufferView, "bufferViews" : this.handleBufferView,
"shaders" : this.handleShader, "shaders" : this.handleShader,
...@@ -217,46 +217,46 @@ var global = window; ...@@ -217,46 +217,46 @@ var global = window;
}; };
var success = true; var success = true;
while (this._state.categoryIndex !== -1) { while (this._state.categoryIndex !== -1) {
var category = categoriesDepsOrder[this._state.categoryIndex]; var category = categoriesDepsOrder[this._state.categoryIndex];
var categoryState = this._state.categoryState; var categoryState = this._state.categoryState;
var keys = categoryState.keys; var keys = categoryState.keys;
if (!keys) { if (!keys) {
categoryState.keys = keys = Object.keys(this.rootDescription[category]); categoryState.keys = keys = Object.keys(this.rootDescription[category]);
if (keys) { if (keys) {
if (keys.length == 0) { if (keys.length == 0) {
this._stepToNextDescription(); this._stepToNextDescription();
continue; continue;
} }
} }
} }
var type = category; var type = category;
var entryID = keys[categoryState.index]; var entryID = keys[categoryState.index];
var description = this.getEntryDescription(entryID, type); var description = this.getEntryDescription(entryID, type);
if (!description) { if (!description) {
if (this.handleError) { if (this.handleError) {
this.handleError("INCONSISTENCY ERROR: no description found for entry " + entryID); this.handleError("INCONSISTENCY ERROR: no description found for entry " + entryID);
success = false; success = false;
break; break;
} }
} else { } else {
if (methodForType[type]) { if (methodForType[type]) {
if (methodForType[type].call(this, entryID, description, this._state.userInfo) === false) { if (methodForType[type].call(this, entryID, description, this._state.userInfo) === false) {
success = false; success = false;
break; break;
} }
} }
this._stepToNextDescription(); this._stepToNextDescription();
} }
} }
if (this.handleLoadCompleted) { if (this.handleLoadCompleted) {
this.handleLoadCompleted(success); this.handleLoadCompleted(success);
} }
} }
}, },
...@@ -264,40 +264,40 @@ var global = window; ...@@ -264,40 +264,40 @@ var global = window;
_loadJSONIfNeeded: { _loadJSONIfNeeded: {
enumerable: true, enumerable: true,
value: function(callback) { value: function(callback) {
var self = this; var self = this;
//FIXME: handle error //FIXME: handle error
if (!this._json) { if (!this._json) {
var jsonPath = this._path; var jsonPath = this._path;
var i = jsonPath.lastIndexOf("/"); var i = jsonPath.lastIndexOf("/");
this.baseURL = (i !== 0) ? jsonPath.substring(0, i + 1) : ''; this.baseURL = (i !== 0) ? jsonPath.substring(0, i + 1) : '';
var jsonfile = new XMLHttpRequest(); var jsonfile = new XMLHttpRequest();
jsonfile.open("GET", jsonPath, true); jsonfile.open("GET", jsonPath, true);
jsonfile.addEventListener( 'load', function ( event ) { jsonfile.addEventListener( 'load', function ( event ) {
self.json = JSON.parse(jsonfile.responseText); self.json = JSON.parse(jsonfile.responseText);
if (callback) { if (callback) {
callback(self.json); callback(self.json);
} }
}, false ); }, false );
jsonfile.send(null); jsonfile.send(null);
} else { } else {
if (callback) { if (callback) {
callback(this.json); callback(this.json);
} }
} }
} }
}, },
/* load JSON and assign it as description to the reader */ /* load JSON and assign it as description to the reader */
_buildLoader: { _buildLoader: {
value: function(callback) { value: function(callback) {
var self = this; var self = this;
function JSONReady(json) { function JSONReady(json) {
self.rootDescription = json; self.rootDescription = json;
if (callback) if (callback)
callback(this); callback(this);
} }
this._loadJSONIfNeeded(JSONReady); this._loadJSONIfNeeded(JSONReady);
} }
}, },
...@@ -305,51 +305,51 @@ var global = window; ...@@ -305,51 +305,51 @@ var global = window;
_getEntryType: { _getEntryType: {
value: function(entryID) { value: function(entryID) {
var rootKeys = categoriesDepsOrder; var rootKeys = categoriesDepsOrder;
for (var i = 0 ; i < rootKeys.length ; i ++) { for (var i = 0 ; i < rootKeys.length ; i ++) {
var rootValues = this.rootDescription[rootKeys[i]]; var rootValues = this.rootDescription[rootKeys[i]];
if (rootValues) { if (rootValues) {
return rootKeys[i]; return rootKeys[i];
} }
} }
return null; return null;
} }
}, },
getNextCategoryIndex: { getNextCategoryIndex: {
value: function(currentIndex) { value: function(currentIndex) {
for (var i = currentIndex ; i < categoriesDepsOrder.length ; i ++) { for (var i = currentIndex ; i < categoriesDepsOrder.length ; i ++) {
if (this.hasCategory(categoriesDepsOrder[i])) { if (this.hasCategory(categoriesDepsOrder[i])) {
return i; return i;
} }
} }
return -1; return -1;
} }
}, },
load: { load: {
enumerable: true, enumerable: true,
value: function(userInfo, options) { value: function(userInfo, options) {
var self = this; var self = this;
this._buildLoader(function loaderReady(reader) { this._buildLoader(function loaderReady(reader) {
var startCategory = self.getNextCategoryIndex.call(self, 0); var startCategory = self.getNextCategoryIndex.call(self, 0);
if (startCategory !== -1) { if (startCategory !== -1) {
self._state = { "userInfo" : userInfo, self._state = { "userInfo" : userInfo,
"options" : options, "options" : options,
"categoryIndex" : startCategory, "categoryIndex" : startCategory,
"categoryState" : { "index" : "0" } }; "categoryState" : { "index" : "0" } };
self._handleState(); self._handleState();
} }
}); });
} }
}, },
initWithPath: { initWithPath: {
value: function(path) { value: function(path) {
this._path = path; this._path = path;
this._json = null; this._json = null;
return this; return this;
} }
}, },
...@@ -359,30 +359,30 @@ var global = window; ...@@ -359,30 +359,30 @@ var global = window;
//to be invoked by subclass, so that ids can be ensured to not overlap //to be invoked by subclass, so that ids can be ensured to not overlap
loaderContext: { loaderContext: {
value: function() { value: function() {
if (typeof this._knownURLs[this._path] === "undefined") { if (typeof this._knownURLs[this._path] === "undefined") {
this._knownURLs[this._path] = Object.keys(this._knownURLs).length; this._knownURLs[this._path] = Object.keys(this._knownURLs).length;
} }
return "__" + this._knownURLs[this._path]; return "__" + this._knownURLs[this._path];
} }
}, },
initWithJSON: { initWithJSON: {
value: function(json, baseURL) { value: function(json, baseURL) {
this.json = json; this.json = json;
this.baseURL = baseURL; this.baseURL = baseURL;
if (!baseURL) { if (!baseURL) {
console.log("WARNING: no base URL passed to Reader:initWithJSON"); console.log("WARNING: no base URL passed to Reader:initWithJSON");
} }
return this; return this;
} }
} }
}); });
if (root) { if (root) {
root.glTFParser = glTFParser; root.glTFParser = glTFParser;
} }
return glTFParser; return glTFParser;
})); }));
...@@ -26,8 +26,8 @@ THREE.GLTFLoaderUtils = Object.create(Object, { ...@@ -26,8 +26,8 @@ THREE.GLTFLoaderUtils = Object.create(Object, {
value: function() { value: function() {
this._streams = {}; this._streams = {};
this._streamsStatus = {}; this._streamsStatus = {};
this._resources = {}; this._resources = {};
this._resourcesStatus = {}; this._resourcesStatus = {};
} }
}, },
...@@ -35,60 +35,60 @@ THREE.GLTFLoaderUtils = Object.create(Object, { ...@@ -35,60 +35,60 @@ THREE.GLTFLoaderUtils = Object.create(Object, {
_containsResource: { _containsResource: {
enumerable: false, enumerable: false,
value: function(resourceID) { value: function(resourceID) {
return this._resources[resourceID] ? true : false; return this._resources[resourceID] ? true : false;
} }
}, },
_storeResource: { _storeResource: {
enumerable: false, enumerable: false,
value: function(resourceID, resource) { value: function(resourceID, resource) {
if (!resourceID) { if (!resourceID) {
console.log("ERROR: entry does not contain id, cannot store"); console.log("ERROR: entry does not contain id, cannot store");
return; return;
} }
if (this._containsResource[resourceID]) { if (this._containsResource[resourceID]) {
console.log("WARNING: resource:" + resourceID + " is already stored, overriding"); console.log("WARNING: resource:" + resourceID + " is already stored, overriding");
} }
this._resources[resourceID] = resource; this._resources[resourceID] = resource;
} }
}, },
_getResource: { _getResource: {
enumerable: false, enumerable: false,
value: function(resourceID) { value: function(resourceID) {
return this._resources[resourceID]; return this._resources[resourceID];
} }
}, },
_loadStream: { _loadStream: {
value: function(path, type, delegate) { value: function(path, type, delegate) {
var self = this; var self = this;
if (!type) { if (!type) {
delegate.handleError(THREE.GLTFLoaderUtils.INVALID_TYPE, null); delegate.handleError(THREE.GLTFLoaderUtils.INVALID_TYPE, null);
return; return;
} }
if (!path) { if (!path) {
delegate.handleError(THREE.GLTFLoaderUtils.INVALID_PATH); delegate.handleError(THREE.GLTFLoaderUtils.INVALID_PATH);
return; return;
} }
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('GET', path, true); xhr.open('GET', path, true);
xhr.responseType = (type === this.ARRAY_BUFFER) ? "arraybuffer" : "text"; xhr.responseType = (type === this.ARRAY_BUFFER) ? "arraybuffer" : "text";
//if this is not specified, 1 "big blob" scenes fails to load. //if this is not specified, 1 "big blob" scenes fails to load.
xhr.setRequestHeader("If-Modified-Since", "Sat, 01 Jan 1970 00:00:00 GMT"); xhr.setRequestHeader("If-Modified-Since", "Sat, 01 Jan 1970 00:00:00 GMT");
xhr.addEventListener( 'load', function ( event ) { xhr.addEventListener( 'load', function ( event ) {
delegate.streamAvailable(path, xhr.response); delegate.streamAvailable(path, xhr.response);
}, false ); }, false );
xhr.addEventListener( 'error', function ( event ) { xhr.addEventListener( 'error', function ( event ) {
delegate.handleError(THREE.GLTFLoaderUtils.XMLHTTPREQUEST_STATUS_ERROR, xhr.status); delegate.handleError(THREE.GLTFLoaderUtils.XMLHTTPREQUEST_STATUS_ERROR, xhr.status);
}, false ); }, false );
xhr.send(null); xhr.send(null);
} }
}, },
...@@ -97,86 +97,86 @@ THREE.GLTFLoaderUtils = Object.create(Object, { ...@@ -97,86 +97,86 @@ THREE.GLTFLoaderUtils = Object.create(Object, {
_handleRequest: { _handleRequest: {
value: function(request) { value: function(request) {
var resourceStatus = this._resourcesStatus[request.id]; var resourceStatus = this._resourcesStatus[request.id];
if (resourceStatus) if (resourceStatus)
{ {
this._resourcesStatus[request.id] ++; this._resourcesStatus[request.id] ++;
} }
else else
{ {
this._resourcesStatus[request.id] = 1; this._resourcesStatus[request.id] = 1;
} }
var streamStatus = this._streamsStatus[request.path]; var streamStatus = this._streamsStatus[request.path];
if (streamStatus && streamStatus.status === "loading" ) if (streamStatus && streamStatus.status === "loading" )
{ {
streamStatus.requests.push(request); streamStatus.requests.push(request);
return; return;
} }
this._streamsStatus[request.path] = { status : "loading", requests : [ request ] }; this._streamsStatus[request.path] = { status : "loading", requests : [ request ] };
var self = this; var self = this;
var processResourceDelegate = {}; var processResourceDelegate = {};
processResourceDelegate.streamAvailable = function(path, res_) { processResourceDelegate.streamAvailable = function(path, res_) {
var streamStatus = self._streamsStatus[path]; var streamStatus = self._streamsStatus[path];
var requests = streamStatus.requests; var requests = streamStatus.requests;
requests.forEach( function(req_) { requests.forEach( function(req_) {
var subArray = res_.slice(req_.range[0], req_.range[1]); var subArray = res_.slice(req_.range[0], req_.range[1]);
var convertedResource = req_.delegate.convert(subArray, req_.ctx); var convertedResource = req_.delegate.convert(subArray, req_.ctx);
self._storeResource(req_.id, convertedResource); self._storeResource(req_.id, convertedResource);
req_.delegate.resourceAvailable(convertedResource, req_.ctx); req_.delegate.resourceAvailable(convertedResource, req_.ctx);
-- self._resourcesStatus[req_.id]; -- self._resourcesStatus[req_.id];
}, this); }, this);
delete self._streamsStatus[path]; delete self._streamsStatus[path];
}; };
processResourceDelegate.handleError = function(errorCode, info) { processResourceDelegate.handleError = function(errorCode, info) {
request.delegate.handleError(errorCode, info); request.delegate.handleError(errorCode, info);
} }
this._loadStream(request.path, request.type, processResourceDelegate); this._loadStream(request.path, request.type, processResourceDelegate);
} }
}, },
_elementSizeForGLType: { _elementSizeForGLType: {
value: function(glType) { value: function(glType) {
switch (glType) { switch (glType) {
case WebGLRenderingContext.FLOAT : case WebGLRenderingContext.FLOAT :
return Float32Array.BYTES_PER_ELEMENT; return Float32Array.BYTES_PER_ELEMENT;
case WebGLRenderingContext.UNSIGNED_BYTE : case WebGLRenderingContext.UNSIGNED_BYTE :
return Uint8Array.BYTES_PER_ELEMENT; return Uint8Array.BYTES_PER_ELEMENT;
case WebGLRenderingContext.UNSIGNED_SHORT : case WebGLRenderingContext.UNSIGNED_SHORT :
return Uint16Array.BYTES_PER_ELEMENT; return Uint16Array.BYTES_PER_ELEMENT;
case WebGLRenderingContext.FLOAT_VEC2 : case WebGLRenderingContext.FLOAT_VEC2 :
return Float32Array.BYTES_PER_ELEMENT * 2; return Float32Array.BYTES_PER_ELEMENT * 2;
case WebGLRenderingContext.FLOAT_VEC3 : case WebGLRenderingContext.FLOAT_VEC3 :
return Float32Array.BYTES_PER_ELEMENT * 3; return Float32Array.BYTES_PER_ELEMENT * 3;
case WebGLRenderingContext.FLOAT_VEC4 : case WebGLRenderingContext.FLOAT_VEC4 :
return Float32Array.BYTES_PER_ELEMENT * 4; return Float32Array.BYTES_PER_ELEMENT * 4;
case WebGLRenderingContext.FLOAT_MAT3 : case WebGLRenderingContext.FLOAT_MAT3 :
return Float32Array.BYTES_PER_ELEMENT * 9; return Float32Array.BYTES_PER_ELEMENT * 9;
case WebGLRenderingContext.FLOAT_MAT4 : case WebGLRenderingContext.FLOAT_MAT4 :
return Float32Array.BYTES_PER_ELEMENT * 16; return Float32Array.BYTES_PER_ELEMENT * 16;
default: default:
return null; return null;
} }
} }
}, },
_handleWrappedBufferViewResourceLoading: { _handleWrappedBufferViewResourceLoading: {
value: function(wrappedBufferView, delegate, ctx) { value: function(wrappedBufferView, delegate, ctx) {
var bufferView = wrappedBufferView.bufferView; var bufferView = wrappedBufferView.bufferView;
var buffer = bufferView.buffer; var buffer = bufferView.buffer;
var byteOffset = wrappedBufferView.byteOffset + bufferView.description.byteOffset; var byteOffset = wrappedBufferView.byteOffset + bufferView.description.byteOffset;
var range = [ byteOffset, (this._elementSizeForGLType(wrappedBufferView.type) * wrappedBufferView.count) + byteOffset ]; var range = [ byteOffset, (this._elementSizeForGLType(wrappedBufferView.type) * wrappedBufferView.count) + byteOffset ];
this._handleRequest({ "id" : wrappedBufferView.id, this._handleRequest({ "id" : wrappedBufferView.id,
"range" : range, "range" : range,
"type" : buffer.description.type, "type" : buffer.description.type,
"path" : buffer.description.path, "path" : buffer.description.path,
...@@ -189,14 +189,14 @@ THREE.GLTFLoaderUtils = Object.create(Object, { ...@@ -189,14 +189,14 @@ THREE.GLTFLoaderUtils = Object.create(Object, {
value: function(wrappedBufferView, delegate, ctx) { value: function(wrappedBufferView, delegate, ctx) {
var savedBuffer = this._getResource(wrappedBufferView.id); var savedBuffer = this._getResource(wrappedBufferView.id);
if (savedBuffer) { if (savedBuffer) {
return savedBuffer; return savedBuffer;
} else { } else {
this._handleWrappedBufferViewResourceLoading(wrappedBufferView, delegate, ctx); this._handleWrappedBufferViewResourceLoading(wrappedBufferView, delegate, ctx);
} }
return null; return null;
} }
}, },
...@@ -204,17 +204,17 @@ THREE.GLTFLoaderUtils = Object.create(Object, { ...@@ -204,17 +204,17 @@ THREE.GLTFLoaderUtils = Object.create(Object, {
value: function(request, delegate, ctx) { value: function(request, delegate, ctx) {
request.delegate = delegate; request.delegate = delegate;
request.ctx = ctx; request.ctx = ctx;
this._handleRequest({ "id" : request.id, this._handleRequest({ "id" : request.id,
"path" : request.path, "path" : request.path,
"range" : [ 0 ], "range" : [ 0 ],
"type" : "text", "type" : "text",
"delegate" : delegate, "delegate" : delegate,
"ctx" : ctx }, null); "ctx" : ctx }, null);
return null; return null;
} }
}, },
}); });
...@@ -215,7 +215,7 @@ THREE.SVGRenderer = function () { ...@@ -215,7 +215,7 @@ THREE.SVGRenderer = function () {
var x = _vector3.x * _svgWidthHalf; var x = _vector3.x * _svgWidthHalf;
var y = - _vector3.y * _svgHeightHalf; var y = - _vector3.y * _svgHeightHalf;
var node = object.node; var node = object.node;
node.setAttribute( 'transform', 'translate(' + x + ',' + y + ')' ); node.setAttribute( 'transform', 'translate(' + x + ',' + y + ')' );
_svg.appendChild( node ); _svg.appendChild( node );
......
...@@ -404,8 +404,8 @@ THREE.SoftwareRenderer = function ( parameters ) { ...@@ -404,8 +404,8 @@ THREE.SoftwareRenderer = function ( parameters ) {
+ (material.palette[cIndex + 2] * tdata[tIndex + 2]); + (material.palette[cIndex + 2] * tdata[tIndex + 2]);
if (opaci < 250) { if (opaci < 250) {
var backColor = buffer[ colorOffset ] << 24 + buffer[ colorOffset + 1 ] << 16 + buffer[ colorOffset + 2 ] << 8; var backColor = buffer[ colorOffset ] << 24 + buffer[ colorOffset + 1 ] << 16 + buffer[ colorOffset + 2 ] << 8;
foreColor = foreColor * opaci + backColor * (1 - opaci); foreColor = foreColor * opaci + backColor * (1 - opaci);
} }
buffer[ colorOffset ] = (foreColor & 0xff0000) >> 16; buffer[ colorOffset ] = (foreColor & 0xff0000) >> 16;
......
此差异已折叠。
...@@ -182,11 +182,11 @@ THREE.FontUtils = { ...@@ -182,11 +182,11 @@ THREE.FontUtils = {
var t = i2 / divisions; var t = i2 / divisions;
var tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx ); var tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
var ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy ); var ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
} }
} }
break; break;
case 'b': case 'b':
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册