diff --git a/build/yuka.js b/build/yuka.js index 664c6a8b..4bacfc95 100644 --- a/build/yuka.js +++ b/build/yuka.js @@ -8716,19 +8716,19 @@ } /** - * Returns a new geometry without containing indices. + * Returns a new geometry without containing indices. If the geometry is already + * non-indexed, the method performs no changes. * - * @return {MeshGeometry} The new geometry. + * @return {MeshGeometry} The new non-indexed geometry. */ toTriangleSoup() { const indices = this.indices; - const vertices = this.vertices; - let newVertices; if ( indices ) { - newVertices = new Float32Array( indices.length * 3 ); + const vertices = this.vertices; + const newVertices = new Float32Array( indices.length * 3 ); for ( let i = 0, l = indices.length; i < l; i ++ ) { @@ -8741,14 +8741,14 @@ } + return new MeshGeometry( newVertices ); + } else { - newVertices = new Float32Array( vertices ); + return this; } - return new MeshGeometry( newVertices ); - } /** @@ -14059,8 +14059,9 @@ // primitives - const nonIndexedGeometry = geometry.toTriangleSoup(); - const vertices = nonIndexedGeometry.vertices; + if ( geometry.indices !== null ) geometry = geometry.toTriangleSoup(); + + const vertices = geometry.vertices; for ( let i = 0, l = vertices.length; i < l; i ++ ) { diff --git a/build/yuka.min.js b/build/yuka.min.js index f2525c9b..b7ca6c87 100644 --- a/build/yuka.min.js +++ b/build/yuka.min.js @@ -172,38 +172,38 @@ b).cross(Lc.subVectors(a,b)).normalize();this.fromNormalAndCoplanarPoint(eb,a);r b.subVectors(a,eb);return b};X.prototype.equals=function(a){return a.normal.equals(this.normal)&&a.constant===this.constant};var Gd=new M,N={a:new f,b:new f,c:new f},fb=new I,Hd=new X,Id=new D,Mc=new f,Nc=new f,Oc=new f,Pc=new f,Sa=function(a,b){this.vertices=a=void 0===a?new Float32Array:a;this.indices=void 0===b?null:b;this.backfaceCulling=!0;this.aabb=new E;this.boundingSphere=new M;this.computeBoundingVolume()};Sa.prototype.computeBoundingVolume=function(){var a=this.vertices,b=new f,c=this.aabb, e=this.boundingSphere;c.min.set(Infinity,Infinity,Infinity);c.max.set(-Infinity,-Infinity,-Infinity);for(var d=0,k=a.length;d=this._nextUpdateTime?(this._nextUpdateTime=a+1/this.updateFrequency,!0):!1};var za=function(){};za.prototype.enter=function(){};za.prototype.execute=function(){};za.prototype.exit=function(){};za.prototype.toJSON=function(){};za.prototype.fromJSON=function(){};za.prototype.resolveReferences=function(){};za.prototype.onMessage=function(){return!1};var Z=function(a){this.owner=void 0===a?null:a;this.globalState=this.previousState=this.currentState=null;this.states=new Map;this._typesMap=new Map}; -Z.prototype.update=function(){null!==this.globalState&&this.globalState.execute(this.owner);null!==this.currentState&&this.currentState.execute(this.owner);return this};Z.prototype.add=function(a,b){b instanceof za?this.states.set(a,b):C.warn('YUKA.StateMachine: .add() needs a parameter of type "YUKA.State".');return this};Z.prototype.remove=function(a){this.states.delete(a);return this};Z.prototype.get=function(a){return this.states.get(a)};Z.prototype.changeTo=function(a){a=this.get(a);this._change(a); -return this};Z.prototype.revert=function(){this._change(this.previousState);return this};Z.prototype.in=function(a){return this.get(a)===this.currentState};Z.prototype.handleMessage=function(a){return null!==this.currentState&&!0===this.currentState.onMessage(this.owner,a)||null!==this.globalState&&!0===this.globalState.onMessage(this.owner,a)?!0:!1};Z.prototype.toJSON=function(){for(var a={owner:this.owner.uuid,currentState:null,previousState:null,globalState:null,states:[]},b=new Map,c=$jscomp.makeIterator(this.states), -e=c.next();!e.done;e=c.next()){var d=$jscomp.makeIterator(e.value);e=d.next().value;d=d.next().value;a.states.push({type:d.constructor.name,id:e,state:d.toJSON()});b.set(d,e)}a.currentState=b.get(this.currentState)||null;a.previousState=b.get(this.previousState)||null;a.globalState=b.get(this.globalState)||null;return a};Z.prototype.fromJSON=function(a){this.owner=a.owner;for(var b=a.states,c=0,e=b.length;cb&&(b=d)}return b};var hb= -function(a){a=void 0===a?null:a;return U.call(this,null!==a?[a]:[])||this};$jscomp.inherits(hb,U);hb.prototype.clearDegreeOfMembership=function(){this.terms[0].clearDegreeOfMembership();return this};hb.prototype.getDegreeOfMembership=function(){var a=this.terms[0].getDegreeOfMembership();return a*a};hb.prototype.updateDegreeOfMembership=function(a){this.terms[0].updateDegreeOfMembership(a*a);return this};var w=function(a){this.degreeOfMembership=0;this.representativeValue=void 0===a?0:a;this.right= -this.left=0;this._uuid=null;return this};$jscomp.inherits(w,Aa);w.prototype.computeDegreeOfMembership=function(){};w.prototype.clearDegreeOfMembership=function(){this.degreeOfMembership=0;return this};w.prototype.getDegreeOfMembership=function(){return this.degreeOfMembership};w.prototype.updateDegreeOfMembership=function(a){a>this.degreeOfMembership&&(this.degreeOfMembership=a);return this};w.prototype.toJSON=function(){var a=Aa.prototype.toJSON.call(this);a.degreeOfMembership=this.degreeOfMembership; -a.representativeValue=this.representativeValue;a.left=this.left;a.right=this.right;a.uuid=this.uuid;return a};w.prototype.fromJSON=function(a){this.degreeOfMembership=a.degreeOfMembership;this.representativeValue=a.representativeValue;this.left=a.left;this.right=a.right;this.uuid=a.uuid;return this};$jscomp.global.Object.defineProperties(w.prototype,{uuid:{configurable:!0,enumerable:!0,get:function(){null===this._uuid&&(this._uuid=J.generateUUID());return this._uuid},set:function(a){this._uuid=a}}}); -var Db=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+a)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(Db,w);Db.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.right;return a>=this.left&&a<=b?1:a>b&&a<=c?a>=(b+c)/2?2*Math.pow((a-c)/(b-c),2):1-2*Math.pow((a-b)/(b-c),2):0};Db.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};Db.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this, -a);this.midpoint=a.midpoint;return this};var ib=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+a)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(ib,w);ib.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.right;return a>=this.left&&a<=b?1:a>b&&a<=c?1/(c-b)*(c-a):0};ib.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};ib.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this, -a);this.midpoint=a.midpoint;return this};var jb=function(a,b,c,e){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;e=void 0===e?0:e;var d=w.call(this,b)||this;d.left=a;d.midpoint=b;d.right=c;d.standardDeviation=e;d._cache={};return d};$jscomp.inherits(jb,w);jb.prototype.computeDegreeOfMembership=function(a){this._updateCache();return a>=this.right||a<=this.left?0:p(a,this.midpoint,this._cache.variance)/this._cache.normalizationFactor};jb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this); -a.midpoint=this.midpoint;a.standardDeviation=this.standardDeviation;return a};jb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint=a.midpoint;this.standardDeviation=a.standardDeviation;return this};jb.prototype._updateCache=function(){var a=this._cache,b=this.midpoint,c=this.standardDeviation;if(b!==a.midpoint||c!==a.standardDeviation){var e=c*c;a.midpoint=b;a.standardDeviation=c;a.variance=e;a.normalizationFactor=p(b,b,e)}return this};var Eb=function(a,b,c){a=void 0=== -a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+c)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(Eb,w);Eb.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.left,e=this.right;return a>=c&&a<=b?a<=(c+b)/2?2*Math.pow((a-c)/(b-c),2):1-2*Math.pow((a-b)/(b-c),2):a>b&&a<=e?1:0};Eb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};Eb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a); -this.midpoint=a.midpoint;return this};var kb=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+c)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(kb,w);kb.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.left,e=this.right;return a>=c&&a<=b?1/(b-c)*(a-c):a>b&&a<=e?1:0};kb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};kb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this, -a);this.midpoint=a.midpoint;return this};var lb=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,b)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(lb,w);lb.prototype.computeDegreeOfMembership=function(a){var b=this.right;return a>=this.left&&a<=b?1:0};lb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};lb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint=a.midpoint; -return this};var mb=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,b)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(mb,w);mb.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.left,e=this.right;return a>=c&&a<=b?1/(b-c)*(a-c):a>b&&a<=e?1/(e-b)*(e-a):0};mb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};mb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this, -a);this.midpoint=a.midpoint;return this};var nb=function(a,b){this.antecedent=void 0===a?null:a;this.consequence=void 0===b?null:b};nb.prototype.initConsequence=function(){this.consequence.clearDegreeOfMembership();return this};nb.prototype.evaluate=function(){this.consequence.updateDegreeOfMembership(this.antecedent.getDegreeOfMembership());return this};nb.prototype.toJSON=function(){var a={},b=this.antecedent,c=this.consequence;a.type=this.constructor.name;a.antecedent=b instanceof U?b.toJSON(): -b.uuid;a.consequence=c instanceof U?c.toJSON():c.uuid;return a};nb.prototype.fromJSON=function(a,b){function c(a){if("string"===typeof a)return b.get(a)||null;var e=a.type;switch(e){case "FuzzyAND":e=new gc;break;case "FuzzyOR":e=new hc;break;case "FuzzyVERY":e=new hb;break;case "FuzzyFAIRLY":e=new gb;break;default:C.error("YUKA.FuzzyRule: Unsupported operator type:",e);return}a=a.terms;for(var d=0,f=a.length;dthis.maxRange&&(this.maxRange=a.right);return this};Ba.prototype.remove=function(a){var b=this.fuzzySets;a=b.indexOf(a);b.splice(a,1);this.minRange=Infinity;this.maxRange=-Infinity;a=0;for(var c=b.length;athis.maxRange&& -(this.maxRange=e.right)}return this};Ba.prototype.fuzzify=function(a){if(athis.maxRange)C.warn("YUKA.FuzzyVariable: Value for fuzzification out of range.");else{for(var b=this.fuzzySets,c=0,e=b.length;c=this._nextUpdateTime? +(this._nextUpdateTime=a+1/this.updateFrequency,!0):!1};var za=function(){};za.prototype.enter=function(){};za.prototype.execute=function(){};za.prototype.exit=function(){};za.prototype.toJSON=function(){};za.prototype.fromJSON=function(){};za.prototype.resolveReferences=function(){};za.prototype.onMessage=function(){return!1};var Z=function(a){this.owner=void 0===a?null:a;this.globalState=this.previousState=this.currentState=null;this.states=new Map;this._typesMap=new Map};Z.prototype.update=function(){null!== +this.globalState&&this.globalState.execute(this.owner);null!==this.currentState&&this.currentState.execute(this.owner);return this};Z.prototype.add=function(a,b){b instanceof za?this.states.set(a,b):C.warn('YUKA.StateMachine: .add() needs a parameter of type "YUKA.State".');return this};Z.prototype.remove=function(a){this.states.delete(a);return this};Z.prototype.get=function(a){return this.states.get(a)};Z.prototype.changeTo=function(a){a=this.get(a);this._change(a);return this};Z.prototype.revert= +function(){this._change(this.previousState);return this};Z.prototype.in=function(a){return this.get(a)===this.currentState};Z.prototype.handleMessage=function(a){return null!==this.currentState&&!0===this.currentState.onMessage(this.owner,a)||null!==this.globalState&&!0===this.globalState.onMessage(this.owner,a)?!0:!1};Z.prototype.toJSON=function(){for(var a={owner:this.owner.uuid,currentState:null,previousState:null,globalState:null,states:[]},b=new Map,c=$jscomp.makeIterator(this.states),e=c.next();!e.done;e= +c.next()){var d=$jscomp.makeIterator(e.value);e=d.next().value;d=d.next().value;a.states.push({type:d.constructor.name,id:e,state:d.toJSON()});b.set(d,e)}a.currentState=b.get(this.currentState)||null;a.previousState=b.get(this.previousState)||null;a.globalState=b.get(this.globalState)||null;return a};Z.prototype.fromJSON=function(a){this.owner=a.owner;for(var b=a.states,c=0,e=b.length;cb&&(b=d)}return b};var hb=function(a){a=void 0===a?null:a;return U.call(this, +null!==a?[a]:[])||this};$jscomp.inherits(hb,U);hb.prototype.clearDegreeOfMembership=function(){this.terms[0].clearDegreeOfMembership();return this};hb.prototype.getDegreeOfMembership=function(){var a=this.terms[0].getDegreeOfMembership();return a*a};hb.prototype.updateDegreeOfMembership=function(a){this.terms[0].updateDegreeOfMembership(a*a);return this};var w=function(a){this.degreeOfMembership=0;this.representativeValue=void 0===a?0:a;this.right=this.left=0;this._uuid=null;return this};$jscomp.inherits(w, +Aa);w.prototype.computeDegreeOfMembership=function(){};w.prototype.clearDegreeOfMembership=function(){this.degreeOfMembership=0;return this};w.prototype.getDegreeOfMembership=function(){return this.degreeOfMembership};w.prototype.updateDegreeOfMembership=function(a){a>this.degreeOfMembership&&(this.degreeOfMembership=a);return this};w.prototype.toJSON=function(){var a=Aa.prototype.toJSON.call(this);a.degreeOfMembership=this.degreeOfMembership;a.representativeValue=this.representativeValue;a.left= +this.left;a.right=this.right;a.uuid=this.uuid;return a};w.prototype.fromJSON=function(a){this.degreeOfMembership=a.degreeOfMembership;this.representativeValue=a.representativeValue;this.left=a.left;this.right=a.right;this.uuid=a.uuid;return this};$jscomp.global.Object.defineProperties(w.prototype,{uuid:{configurable:!0,enumerable:!0,get:function(){null===this._uuid&&(this._uuid=J.generateUUID());return this._uuid},set:function(a){this._uuid=a}}});var Db=function(a,b,c){a=void 0===a?0:a;b=void 0=== +b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+a)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(Db,w);Db.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.right;return a>=this.left&&a<=b?1:a>b&&a<=c?a>=(b+c)/2?2*Math.pow((a-c)/(b-c),2):1-2*Math.pow((a-b)/(b-c),2):0};Db.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};Db.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint=a.midpoint; +return this};var ib=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+a)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(ib,w);ib.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.right;return a>=this.left&&a<=b?1:a>b&&a<=c?1/(c-b)*(c-a):0};ib.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};ib.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint= +a.midpoint;return this};var jb=function(a,b,c,e){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;e=void 0===e?0:e;var d=w.call(this,b)||this;d.left=a;d.midpoint=b;d.right=c;d.standardDeviation=e;d._cache={};return d};$jscomp.inherits(jb,w);jb.prototype.computeDegreeOfMembership=function(a){this._updateCache();return a>=this.right||a<=this.left?0:p(a,this.midpoint,this._cache.variance)/this._cache.normalizationFactor};jb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint= +this.midpoint;a.standardDeviation=this.standardDeviation;return a};jb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint=a.midpoint;this.standardDeviation=a.standardDeviation;return this};jb.prototype._updateCache=function(){var a=this._cache,b=this.midpoint,c=this.standardDeviation;if(b!==a.midpoint||c!==a.standardDeviation){var e=c*c;a.midpoint=b;a.standardDeviation=c;a.variance=e;a.normalizationFactor=p(b,b,e)}return this};var Eb=function(a,b,c){a=void 0===a?0:a;b=void 0=== +b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+c)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(Eb,w);Eb.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.left,e=this.right;return a>=c&&a<=b?a<=(c+b)/2?2*Math.pow((a-c)/(b-c),2):1-2*Math.pow((a-b)/(b-c),2):a>b&&a<=e?1:0};Eb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};Eb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint=a.midpoint; +return this};var kb=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,(b+c)/2)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(kb,w);kb.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.left,e=this.right;return a>=c&&a<=b?1/(b-c)*(a-c):a>b&&a<=e?1:0};kb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};kb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint= +a.midpoint;return this};var lb=function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,b)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(lb,w);lb.prototype.computeDegreeOfMembership=function(a){var b=this.right;return a>=this.left&&a<=b?1:0};lb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};lb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint=a.midpoint;return this};var mb= +function(a,b,c){a=void 0===a?0:a;b=void 0===b?0:b;c=void 0===c?0:c;var e=w.call(this,b)||this;e.left=a;e.midpoint=b;e.right=c;return e};$jscomp.inherits(mb,w);mb.prototype.computeDegreeOfMembership=function(a){var b=this.midpoint,c=this.left,e=this.right;return a>=c&&a<=b?1/(b-c)*(a-c):a>b&&a<=e?1/(e-b)*(e-a):0};mb.prototype.toJSON=function(){var a=w.prototype.toJSON.call(this);a.midpoint=this.midpoint;return a};mb.prototype.fromJSON=function(a){w.prototype.fromJSON.call(this,a);this.midpoint=a.midpoint; +return this};var nb=function(a,b){this.antecedent=void 0===a?null:a;this.consequence=void 0===b?null:b};nb.prototype.initConsequence=function(){this.consequence.clearDegreeOfMembership();return this};nb.prototype.evaluate=function(){this.consequence.updateDegreeOfMembership(this.antecedent.getDegreeOfMembership());return this};nb.prototype.toJSON=function(){var a={},b=this.antecedent,c=this.consequence;a.type=this.constructor.name;a.antecedent=b instanceof U?b.toJSON():b.uuid;a.consequence=c instanceof +U?c.toJSON():c.uuid;return a};nb.prototype.fromJSON=function(a,b){function c(a){if("string"===typeof a)return b.get(a)||null;var e=a.type;switch(e){case "FuzzyAND":e=new gc;break;case "FuzzyOR":e=new hc;break;case "FuzzyVERY":e=new hb;break;case "FuzzyFAIRLY":e=new gb;break;default:C.error("YUKA.FuzzyRule: Unsupported operator type:",e);return}a=a.terms;for(var d=0,f=a.length;dthis.maxRange&&(this.maxRange=a.right);return this};Ba.prototype.remove=function(a){var b=this.fuzzySets;a=b.indexOf(a);b.splice(a,1);this.minRange=Infinity;this.maxRange=-Infinity;a=0;for(var c=b.length;athis.maxRange&&(this.maxRange=e.right)}return this}; +Ba.prototype.fuzzify=function(a){if(athis.maxRange)C.warn("YUKA.FuzzyVariable: Value for fuzzification out of range.");else{for(var b=this.fuzzySets,c=0,e=b.length;c=b)for(this.split(a),d=0;d=b)for(this.split(a),d=0;da&&(a=l);v>b&&(b=v);m>c&&(c=m);lb&&a>c?ke:b>c?le:me};fa.prototype.split=function(a){for(var b=this.centroids,c=this.primitives,e=0;ek&&f