diff --git a/away3d/animators/ParticleAnimationSet.hx b/away3d/animators/ParticleAnimationSet.hx index f65fcf9b..d28eec79 100644 --- a/away3d/animators/ParticleAnimationSet.hx +++ b/away3d/animators/ParticleAnimationSet.hx @@ -297,6 +297,8 @@ class ParticleAnimationSet extends AnimationSetBase implements IAnimationSet animationSubGeometry.createVertexData(subGeometry.numVertices, _totalLenOfOneVertex); } + calculateParticleOffsets(mesh); + if (newAnimationSubGeometry == false) return; @@ -344,6 +346,12 @@ class ParticleAnimationSet extends AnimationSetBase implements IAnimationSet break; } } + + if(j < animationSubGeometry.animationParticleOffset + animationSubGeometry.animationParticles.length) { + j++; + continue; + } + numVertices = particle.numVertices; vertexData = animationSubGeometry.vertexData; vertexLength = numVertices*_totalLenOfOneVertex; @@ -366,7 +374,6 @@ class ParticleAnimationSet extends AnimationSetBase implements IAnimationSet counterForVertex += _totalLenOfOneVertex; } - } //store particle properties if they need to be retreived for dynamic local nodes @@ -382,5 +389,24 @@ class ParticleAnimationSet extends AnimationSetBase implements IAnimationSet //next particle i++; } + + calculateParticleOffsets(mesh); + } + + /** + * Will throw an error if a sub-mesh lacks an AnimationSubGeometry; only + * call this after creating them all. + */ + private function calculateParticleOffsets(mesh:Mesh):Void + { + var particleOffset:Int = 0; + for (subMesh in mesh.subMeshes) { + var subGeometry:AnimationSubGeometry = mesh.shareAnimationGeometry + ? _animationSubGeometries[subMesh.subGeometry] + : subMesh.animationSubGeometry; + + subGeometry.animationParticleOffset = particleOffset; + particleOffset += subGeometry.animationParticles.length; + } } } \ No newline at end of file diff --git a/away3d/animators/ParticleAnimator.hx b/away3d/animators/ParticleAnimator.hx index d605aa10..ce33695f 100644 --- a/away3d/animators/ParticleAnimator.hx +++ b/away3d/animators/ParticleAnimator.hx @@ -157,6 +157,7 @@ class ParticleAnimator extends AnimatorBase implements IAnimator animatorSubGeometry.createVertexData(subGeometry.numVertices, _totalLenOfOneVertex); //pass the particles data to the animator subGeometry + animatorSubGeometry.animationParticleOffset = subMesh.animationSubGeometry.animationParticleOffset; animatorSubGeometry.animationParticles = subMesh.animationSubGeometry.animationParticles; } } \ No newline at end of file diff --git a/away3d/animators/data/AnimationSubGeometry.hx b/away3d/animators/data/AnimationSubGeometry.hx index 00ccfc19..0664de0b 100644 --- a/away3d/animators/data/AnimationSubGeometry.hx +++ b/away3d/animators/data/AnimationSubGeometry.hx @@ -30,6 +30,7 @@ class AnimationSubGeometry public var previousTime:Float = Math.NEGATIVE_INFINITY; + public var animationParticleOffset:Int = 0; public var animationParticles:Vector = new Vector(); public function new() diff --git a/away3d/animators/states/ParticleStateBase.hx b/away3d/animators/states/ParticleStateBase.hx index 43d4be03..871aa8aa 100644 --- a/away3d/animators/states/ParticleStateBase.hx +++ b/away3d/animators/states/ParticleStateBase.hx @@ -60,13 +60,19 @@ class ParticleStateBase extends AnimationStateBase var animationParticle:ParticleAnimationData = null; // var numParticles:uint = _positions.length/dataLength; - var numParticles:Int = _dynamicProperties.length; - var i:Int = 0; + var particleOffset:Int = animationSubGeometry.animationParticleOffset; + var numParticles:Int = animationParticles.length; + if(numParticles > _dynamicProperties.length - particleOffset) { + numParticles = _dynamicProperties.length - particleOffset; + } + + var i:Int = particleOffset; var j:Int = 0; var k:Int = 0; //loop through all particles - while (i < numParticles) { + while (i < particleOffset + numParticles) { + data = _dynamicProperties[i]; //loop through each particle data for the current particle while (j < numParticles && (animationParticle = animationParticles[j]).index == i) { data = _dynamicProperties[i];