!function(e,t,n){n.un,n.uns;var i=n.static,r=n.class,a=n.getset,o=n.__newvec,s=(laya.ani.AnimationContent,laya.ani.AnimationPlayer),l=(laya.ani.AnimationState,laya.ani.AnimationTemplet),h=laya.maths.Arith,_=laya.webgl.atlas.AtlasResourceManager,u=laya.webgl.shader.BaseShader,c=laya.utils.Browser,d=laya.webgl.utils.Buffer,f=laya.utils.Byte,m=(laya.ani.bone.canvasmesh.CacheAbleSkinMesh,laya.utils.ClassUtils),p=n.Config,v=(laya.events.Event,laya.events.EventDispatcher),g=laya.utils.Handler,E=laya.net.Loader,S=laya.net.LoaderManager,D=laya.maths.MathUtil,T=laya.display.Node,x=laya.renders.Render,M=(laya.renders.RenderContext,laya.renders.RenderSprite,laya.webgl.utils.RenderState2D),R=laya.resource.Resource,A=laya.utils.RunDriver,I=(laya.webgl.shader.Shader,laya.webgl.utils.ShaderCompile),y=laya.display.Sprite,C=laya.utils.Stat,N=laya.utils.StringKey,w=(laya.display.css.Style,laya.resource.Texture,laya.net.URL),O=laya.utils.Utils,V=laya.webgl.WebGL,P=laya.webgl.WebGLContext;laya.webgl.canvas.WebGLContext2D;n.interface("laya.d3.core.IClone"),n.interface("laya.d3.graphics.IVertex"),n.interface("laya.d3.core.render.IUpdate"),n.interface("laya.d3.core.scene.ITreeNode"),n.interface("laya.d3.core.render.IRenderable");var L=function(){function e(){}return r(e,"laya.d3.animation.AnimationClipParser01"),e.READ_DATA=function(){e._DATA.offset=e._reader.getUint32(),e._DATA.size=e._reader.getUint32()},e.READ_BLOCK=function(){for(var t=e._BLOCK.count=e._reader.getUint16(),n=e._BLOCK.blockStarts=[],i=e._BLOCK.blockLengths=[],r=0;r0&&(V.params=P=[]),i=0;i=0&&e=0&&tthis._number?n=i-1:t=i+1}return t},t._addCollider=function(t){0===this._colliders.length&&e._collsionTestList.splice(this._binarySearchIndex(),0,this._number),t._isRigidbody?(this._colliders.unshift(t),this._nonRigidbodyOffset++):this._colliders.push(t)},t._removeCollider=function(t){var n=this._colliders.indexOf(t);n30)throw new Error("无法返回指定Layer,该number超出范围!");return e._layerList[t]},e.getLayerByName=function(t){for(var n=0;n<31;n++)if(e._layerList[n].name===t)return e._layerList[n];throw new Error("无法返回指定Layer,该name不存在")},e.isVisible=function(t){return 0!=(t&e._currentCameraCullingMask&e._visibleLayers)},e._layerList=[],e._visibleLayers=2147483647,e._collsionTestList=[],e._currentCameraCullingMask=2147483647,e.maxCount=31,e.currentCreationLayer=null,e}(),W=function(){function e(e,t,n){this._time=NaN,this._minCount=0,this._maxCount=0,this._time=e,this._minCount=t,this._maxCount=n}r(e,"laya.d3.core.particleShuriKen.module.Burst");var t=e.prototype;return n.imps(t,{"laya.d3.core.IClone":!0}),t.cloneTo=function(e){var t=e;t._time=this._time,t._minCount=this._minCount,t._maxCount=this._maxCount},t.clone=function(){var e=new this.constructor;return this.cloneTo(e),e},a(0,t,"time",function(){return this._time}),a(0,t,"minCount",function(){return this._minCount}),a(0,t,"maxCount",function(){return this._maxCount}),e}(),X=function(){function e(e){this._color=null,this.enbale=!1,this._color=e}r(e,"laya.d3.core.particleShuriKen.module.ColorOverLifetime");var t=e.prototype;return t.cloneTo=function(e){var t=e;this._color.cloneTo(t._color),t.enbale=this.enbale},t.clone=function(){var e;switch(this._color.type){case 0:e=K.createByConstant(this._color.constant.clone());break;case 1:e=K.createByGradient(this._color.gradient.clone());break;case 2:e=K.createByRandomTwoConstant(this._color.constantMin.clone(),this._color.constantMax.clone());break;case 3:e=K.createByRandomTwoGradient(this._color.gradientMin.clone(),this._color.gradientMax.clone())}var t=new this.constructor(e);return t.enbale=this.enbale,t},a(0,t,"color",function(){return this._color}),e}(),Z=function(){function e(){this._destroyed=!1,this._emissionRate=0,this._bursts=null,this.enbale=!1,this._destroyed=!1,this.emissionRate=10,this._bursts=[]}r(e,"laya.d3.core.particleShuriKen.module.Emission");var t=e.prototype;return n.imps(t,{"laya.d3.core.IClone":!0,"laya.resource.IDestroy":!0}),t._destroy=function(){this._bursts=null,this._destroyed=!0},t.getBurstsCount=function(){return this._bursts.length},t.getBurstByIndex=function(e){return this._bursts[e]},t.addBurst=function(e){var t=this._bursts.length;if(t>0)for(var n=0;ne.time&&this._bursts.splice(n,0,e);this._bursts.push(e)},t.removeBurst=function(e){var t=this._bursts.indexOf(e);-1!==t&&this._bursts.splice(t,1)},t.removeBurstByIndex=function(e){this._bursts.splice(e,1)},t.clearBurst=function(){this._bursts.length=0},t.cloneTo=function(e){var t=e,n=t._bursts;n.length=this._bursts.length;for(var i=0,r=this._bursts.length;i=t){var a=e.getKeyByIndex(n-1),o=(t-a)/(r-a);return D.lerp(e.getValueByIndex(n-1),e.getValueByIndex(n),o)}}throw new Error("ShurikenParticleData: can't get value foam startLifeTimeGradient.")},e._randomInvertRoationArray=function(e,t,n,i,r){var a=NaN;i?(i.seed=r[6],a=i.getFloat(),r[6]=i.seed):a=Math.random(),athis._vbData.length||this._posInIBData+2>this._ibData.length)&&this.flush(),this._tempUint0=this._posInVBData/this._floatSizePerVer,this.addVertex(e.x,e.y,e.z,t.x,t.y,t.z,t.w),this.addVertex(n.x,n.y,n.z,i.x,i.y,i.z,i.w),this.addIndexes(this._tempUint0,this._tempUint0+1),this},t.circle=function(e,t,n,i,r,a){for(this._hasBegun&&1===this._primitiveType||this.drawLinesException(),this._tempUint0=2*t,(this._posInVBData+this._tempUint0*this._floatSizePerVer>this._vbData.length||this._posInIBData+2*this._tempUint0>this._ibData.length)&&this.flush(),this._tempUint1=this._posInVBData/this._floatSizePerVer,this._tempNumver0=0,this._tempInt0=0;this._tempNumver0<6.2832;this._tempNumver0=this._tempNumver0+3.1416/t,this._tempInt0++)this.addVertex(Math.sin(this._tempNumver0)*e,Math.cos(this._tempNumver0)*e,0,n,i,r,a),0===this._tempInt0?this.addIndexes(this._tempUint1):this._tempInt0===this._tempUint0-1?(this._tempUint2=this._tempUint1+this._tempInt0,this.addIndexes(this._tempUint2,this._tempUint2,this._tempUint1)):(this._tempUint2=this._tempUint1+this._tempInt0,this.addIndexes(this._tempUint2,this._tempUint2));return this},t.plane=function(e,t,n,i,r,a,o,s,l){return this._hasBegun&&4===this._primitiveType||this.drawTrianglesException(),(this._posInVBData+4*this._floatSizePerVer>this._vbData.length||this._posInIBData+6>this._ibData.length)&&this.flush(),this._tempNumver0=i/2,this._tempNumver1=r/2,this._tempUint0=this._posInVBData/this._floatSizePerVer,this.addVertex(e-this._tempNumver0,t+this._tempNumver1,n,a,o,s,l),this.addVertex(e+this._tempNumver0,t+this._tempNumver1,n,a,o,s,l),this.addVertex(e-this._tempNumver0,t-this._tempNumver1,n,a,o,s,l),this.addVertex(e+this._tempNumver0,t-this._tempNumver1,n,a,o,s,l),this._tempUint1=this._tempUint0+1,this._tempUint2=this._tempUint0+2,this.addIndexes(this._tempUint0,this._tempUint1,this._tempUint2,this._tempUint2,this._tempUint1,this._tempUint0+3),this},t.box=function(e,t,n,i,r,a,o,s,l,h){return this._hasBegun&&4===this._primitiveType||this.drawTrianglesException(),(this._posInVBData+8*this._floatSizePerVer>this._vbData.length||this._posInIBData+36>this._ibData.length)&&this.flush(),this._tempNumver0=i/2,this._tempNumver1=r/2,this._tempNumver2=a/2,this._tempUint0=this._posInVBData/this._floatSizePerVer,this.addVertex(e-this._tempNumver0,t+this._tempNumver1,n+this._tempNumver2,o,s,l,h),this.addVertex(e+this._tempNumver0,t+this._tempNumver1,n+this._tempNumver2,o,s,l,h),this.addVertex(e-this._tempNumver0,t-this._tempNumver1,n+this._tempNumver2,o,s,l,h),this.addVertex(e+this._tempNumver0,t-this._tempNumver1,n+this._tempNumver2,o,s,l,h),this.addVertex(e+this._tempNumver0,t+this._tempNumver1,n-this._tempNumver2,o,s,l,h),this.addVertex(e-this._tempNumver0,t+this._tempNumver1,n-this._tempNumver2,o,s,l,h),this.addVertex(e+this._tempNumver0,t-this._tempNumver1,n-this._tempNumver2,o,s,l,h),this.addVertex(e-this._tempNumver0,t-this._tempNumver1,n-this._tempNumver2,o,s,l,h),this._tempUint1=this._tempUint0+1,this._tempUint2=this._tempUint0+2,this._tempUint3=this._tempUint0+3,this._tempUint4=this._tempUint0+4,this._tempUint5=this._tempUint0+5,this._tempUint6=this._tempUint0+6,this._tempUint7=this._tempUint0+7,this.addIndexes(this._tempUint0,this._tempUint1,this._tempUint2,this._tempUint2,this._tempUint1,this._tempUint3,this._tempUint4,this._tempUint5,this._tempUint6,this._tempUint6,this._tempUint5,this._tempUint7,this._tempUint5,this._tempUint0,this._tempUint7,this._tempUint7,this._tempUint0,this._tempUint2,this._tempUint1,this._tempUint4,this._tempUint3,this._tempUint3,this._tempUint4,this._tempUint6,this._tempUint5,this._tempUint4,this._tempUint0,this._tempUint0,this._tempUint4,this._tempUint1,this._tempUint2,this._tempUint3,this._tempUint7,this._tempUint7,this._tempUint3,this._tempUint6),this},t.cone=function(e,t,n,i,r,a,o){for(this._hasBegun&&4===this._primitiveType||this.drawTrianglesException(),(this._posInVBData+(2*n+2)*this._floatSizePerVer>this._vbData.length||this._posInIBData+6*n>this._ibData.length)&&this.flush(),this._tempUint0=this._posInVBData,this._tempUint1=this._posInVBData/this._floatSizePerVer,this._tempNumver0=2*Math.PI/n,this.addVertexIndex(0,t,0,i,r,a,o,this._tempUint0),this.addVertexIndex(0,0,0,i,r,a,o,this._tempUint0+this._floatSizePerVer),this._tempInt0=2,this._tempNumver1=0,this._tempInt1=0;this._tempInt1this._vbData.length||this._posInIBData+48>this._ibData.length)&&this.flush(),this._tempUint0=this._posInVBData/this._floatSizePerVer,this.addVertex(e,r,a,o,s,l,h),this.addVertex(i,r,a,o,s,l,h),this.addVertex(e,t,a,o,s,l,h),this.addVertex(i,t,a,o,s,l,h),this.addVertex(i,r,n,o,s,l,h),this.addVertex(e,r,n,o,s,l,h),this.addVertex(i,t,n,o,s,l,h),this.addVertex(e,t,n,o,s,l,h),this._tempUint1=this._tempUint0+1,this._tempUint2=this._tempUint0+2,this._tempUint3=this._tempUint0+3,this._tempUint4=this._tempUint0+4,this._tempUint5=this._tempUint0+5,this._tempUint6=this._tempUint0+6,this._tempUint7=this._tempUint0+7,this.addIndexes(this._tempUint0,this._tempUint1,this._tempUint1,this._tempUint3,this._tempUint3,this._tempUint2,this._tempUint2,this._tempUint0,this._tempUint4,this._tempUint5,this._tempUint5,this._tempUint7,this._tempUint7,this._tempUint6,this._tempUint6,this._tempUint4,this._tempUint5,this._tempUint0,this._tempUint0,this._tempUint2,this._tempUint2,this._tempUint7,this._tempUint7,this._tempUint5,this._tempUint1,this._tempUint4,this._tempUint4,this._tempUint6,this._tempUint6,this._tempUint3,this._tempUint3,this._tempUint1,this._tempUint5,this._tempUint4,this._tempUint4,this._tempUint1,this._tempUint1,this._tempUint0,this._tempUint0,this._tempUint5,this._tempUint2,this._tempUint3,this._tempUint3,this._tempUint6,this._tempUint6,this._tempUint7,this._tempUint7,this._tempUint2),this},t.addVertex=function(e,t,n,i,r,a,o){return this._hasBegun||this.addVertexIndexException(),this._vbData[this._posInVBData]=e,this._vbData[this._posInVBData+1]=t,this._vbData[this._posInVBData+2]=n,this._vbData[this._posInVBData+3]=i,this._vbData[this._posInVBData+4]=r,this._vbData[this._posInVBData+5]=a,this._vbData[this._posInVBData+6]=o,this._posInVBData+=this._floatSizePerVer,this},t.addVertexIndex=function(e,t,n,i,r,a,o,s){return this._hasBegun||this.addVertexIndexException(),this._vbData[s]=e,this._vbData[s+1]=t,this._vbData[s+2]=n,this._vbData[s+3]=i,this._vbData[s+4]=r,this._vbData[s+5]=a,this._vbData[s+6]=o,(s+=this._floatSizePerVer)>this._posInVBData&&(this._posInVBData=s),this},t.addIndexes=function(e){var t=arguments;this._hasBegun||this.addVertexIndexException();for(var n=0;n=Mt.zeroTolerance?(this._owner._trailTotalLength+=this._delLength,this._owner._trailSupplementLength=0,this._updateVerticesByPosition(e),e.cloneTo(this._lastFixedVertexPosition),this._verticesCount+=2,this._virtualVerticesCount=0,this._everyGroupVertexBirthTime.push(this._owner._curtime),this._verticesCount==this._maxVerticesCount&&this._onTrailRenderElementFinish()):(this._owner._trailSupplementLength=this._delLength,this._updateVerticesByPosition(e),this._virtualVerticesCount=2)},t._updateVerticesByPosition=function(e){this._pointe=e.elements,this._pointAtoBVector3e=this._pointAtoBVector3.elements,this._curtime=this._owner._curtime,this._owner._hasLifeSubTrail&&0==this._isStart&&(this._pointe=this._owner._curSubTrailFinishPosition.elements,this._pointAtoBVector3e=this._owner._curSubTrailFinishDirection.elements,this._curtime=this._owner._curSubTrailFinishCurTime),this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointe[0],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointe[1],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointe[2],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=-this._pointAtoBVector3e[0],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=-this._pointAtoBVector3e[1],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=-this._pointAtoBVector3e[2],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._curtime,this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=1,this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointe[0],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointe[1],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointe[2],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointAtoBVector3e[0],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointAtoBVector3e[1],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._pointAtoBVector3e[2],this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=this._curtime,this._vertices1[this._verticesIndex1+this._everyAddVerticeCount1++]=0,this._VerticesToTailLength[this._verticesCount/2]=this._owner._trailTotalLength+this._owner._trailSupplementLength,0==this._owner._trailSupplementLength?this._everyVertexToPreVertexDistance[this._verticesCount/2]=this._delLength:this._everyVertexToPreVertexDistance[this._verticesCount/2]=this._isStart?this._owner._trailSupplementLength:0},t._updateVertexBuffer2=function(){var e=0,t=0,n=0,i=0;for(n=0,i=(this._verticesCount+this._virtualVerticesCount)/2;n=this._owner.time+Mt.zeroTolerance&&(this._curDisappearIndex++,this._owner._trailDeadLength+=this._everyVertexToPreVertexDistance[this._curDisappearIndex],this._curDisappearIndex>=(this._verticesCount+this._virtualVerticesCount)/2&&(this._isDead=!0))},t._beforeRender=function(e){return this._camera=e.camera,null!=this._camera&&(this._owner._owner.transform.position.cloneTo(this._curPosition),!this._isDead&&(this._verticesCount0)&&(this._updateVertexBuffer2(),this._updateDisappear(),!0))},t._render=function(e){this._isDead||(V.mainContext.drawArrays(5,2*this._curDisappearIndex,this._verticesCount+this._virtualVerticesCount-2*this._curDisappearIndex),console.log(2*this._curDisappearIndex,this._verticesCount+this._virtualVerticesCount-2*this._curDisappearIndex),C.drawCall++,C.trianglesFaces+=this._verticesCount+this._virtualVerticesCount-2*this._curDisappearIndex-2)},t._getVertexBuffer=function(e){return void 0===e&&(e=0),0===e?this._vertexBuffer1:1===e?this._vertexBuffer2:null},t._getVertexBuffers=function(){return this._vertexBuffers},t._getIndexBuffer=function(){return null},t.reActivate=function(){this._id=laya.d3.core.trail.TrailRenderElement.renderElementCount++,this._isStart=!1,this._isFinish=!1,this._isDead=!1,this._verticesCount=0,this._virtualVerticesCount=0,this._verticesIndex1=0,this._delLength=0,this._curDisappearIndex=0,this._everyGroupVertexBirthTime=[],this._owner._curSubTrailFinishPosition.cloneTo(this._lastPosition)},t._destroy=function(){this._vertexBuffer1.dispose(),this._vertexBuffer2.dispose(),this._vertices1=null,this._vertexBuffer1=null,this._vertices2=null,this._vertexBuffer2=null,this._vertexBuffers=null,this._everyGroupVertexBirthTime=null,this._VerticesToTailLength=null,this._everyVertexToPreVertexDistance=null,this._lastPosition=null,this._curPosition=null,this._delVector3=null,this._lastFixedVertexPosition=null,this._pointAtoBVector3=null,this._pointe=null,this._pointAtoBVector3e=null,this._pointA=null,this._pointB=null},a(0,t,"_vertexBufferCount",function(){return this._vertexBuffers.length}),a(0,t,"triangleCount",function(){return 0}),e.renderElementCount=0,e}(),Se=function(){function e(){}r(e,"laya.d3.core.trail.VertexTrail");var t=e.prototype;return n.imps(t,{"laya.d3.graphics.IVertex":!0}),a(0,t,"vertexDeclaration",function(){return e._vertexDeclaration1}),a(1,e,"vertexDeclaration1",function(){return e._vertexDeclaration1}),a(1,e,"vertexDeclaration2",function(){return e._vertexDeclaration2}),i(e,["_vertexDeclaration1",function(){return this._vertexDeclaration1=new Ae(32,[new Ie(0,"vector3",0),new Ie(12,"vector3",41),new Ie(24,"single",33),new Ie(28,"single",40)])},"_vertexDeclaration2",function(){return this._vertexDeclaration2=new Ae(4,[new Ie(0,"single",38)])}]),e}(),De=function(){function e(e){this._vertexDeclaration=null,this._vertexDatas=null,this._indexDatas=null,this._vertexBuffer=null,this._indexBuffer=null,this._currentCombineVertexCount=0,this._currentCombineIndexCount=0,this._combineRenderElements=null,this._materials=null,this._materialToRenderElementsOffsets=null,this._merageElements=null,this._combineRenderElementPool=null,this._combineRenderElementPoolIndex=0,this._currentCombineVertexCount=0,this._currentCombineIndexCount=0,this._combineRenderElements=[],this._materialToRenderElementsOffsets=[],this._materials=[],this._merageElements=[],this._combineRenderElementPool=[],this._combineRenderElementPoolIndex=0,this._vertexDeclaration=e}r(e,"laya.d3.graphics.DynamicBatch");var t=e.prototype;return n.imps(t,{"laya.d3.core.render.IRenderable":!0}),t._getVertexBuffer=function(e){return void 0===e&&(e=0),0===e?this._vertexBuffer:null},t._getIndexBuffer=function(){return this._indexBuffer},t._getCombineRenderElementFromPool=function(e,t,n){var i=this._combineRenderElementPool[this._combineRenderElementPoolIndex++];return i||(this._combineRenderElementPool[this._combineRenderElementPoolIndex-1]=i=new _e,i._sprite3D=new vi),i._sprite3D._render._renderUpdate(n),i},t._getRenderElement=function(t,n,i){this._vertexDatas||(this._vertexDatas=new Float32Array(this._vertexDeclaration.vertexStride/4*e.maxVertexCount),this._indexDatas=new Uint16Array(e.maxIndexCount),this._vertexBuffer=Kn.create(this._vertexDeclaration,e.maxVertexCount,35048),this._indexBuffer=jn.create("ushort",e.maxIndexCount,35048)),this._merageElements.length=0;for(var r=0,a=0,o=0,s=this._combineRenderElements.length;oe.maxVertexCount||i>e.maxIndexCount)},t._addCombineRenderObj=function(e){var t=e.renderObj;this._combineRenderElements.push(e),this._currentCombineIndexCount=this._currentCombineIndexCount+t._getIndexBuffer().indexCount,this._currentCombineVertexCount=this._currentCombineVertexCount+t._getVertexBuffer().vertexCount},t._addCombineMaterial=function(e){this._materials.push(e)},t._addMaterialToRenderElementOffset=function(e){this._materialToRenderElementsOffsets.push(e)},t._clearRenderElements=function(){this._combineRenderElements.length=0,this._materials.length=0,this._materialToRenderElementsOffsets.length=0,this._currentCombineVertexCount=0,this._currentCombineIndexCount=0},t._addToRenderQueue=function(e,t,n,i){this._getRenderElement(t,n,i);for(var r=0,a=this._materials.length;rDe.maxVertexCount||E._getIndexBuffer().indexCount+S._getIndexBuffer().indexCount>De.maxIndexCount?(t.getRenderQueue(h._material.renderQueue)._addRenderElement(h),l=a,d=s.combineRenderElementsCount,h=o):(s._addCombineMaterial(l),s._addMaterialToRenderElementOffset(d),s._addCombineRenderObj(h),l=null,h=null,d=-1,s._addCombineRenderObj(o))}else s._addCombineRenderObj(o);u=!0}else l&&(t.getRenderQueue(h._material.renderQueue)._addRenderElement(h),l=null,h=null,d=-1),c++,u=!1;else r=this._prepareDynamicBatchCombineElements[f-1],s._addMaterialToRenderElementOffset(s.combineRenderElementsCount),n=r._material,s._addCombineMaterial(n),s._addCombineRenderObj(r),u=!0,n!==(a=o._material)?(l=a,d=s.combineRenderElementsCount,h=o):s._addCombineRenderObj(o),n=a}l&&(t.getRenderQueue(h._material.renderQueue)._addRenderElement(h),l=null,h=null,d=-1),this._prepareDynamicBatchCombineElements.length=0},t._clearRenderElements=function(){for(var e in this._dynamicBatches)this._dynamicBatches[e]._clearRenderElements()},t._addToRenderQueue=function(e,t,n,i){for(var r in this._dynamicBatches){var a=this._dynamicBatches[r];a.combineRenderElementsCount>0&&a._addToRenderQueue(e,t,n,i)}},t.dispose=function(){this._dynamicBatches=null},e._sortPrepareDynamicBatch=function(e,t){return e._mainSortID-t._mainSortID},e}(),xe=function(){function e(){}return r(e,"laya.d3.graphics.FrustumCulling"),e.renderShadowObjectCulling=function(e,t,n,i,r){var a=0,o=0,s=0,l=0;for(a=0,s=n.length;a1){for(a=0,s=e._cullingRendersLength;a1?e.treeRoot.cullingShadowObjects(t,n,!0,0,e):e.treeRoot.cullingShadowObjectsOnePSSM(t[0],n,i,!0,0,e)},e.renderObjectCulling=function(e,t,n,i,r,a){var o=0,s=0,l=0,h=0,_=t._quenes,u=t._dynamicBatchManager,c=t._cullingRenders;for(o=0,s=_.length;o0&&a._updateToRenderQueue(e,i)}},t.dispose=function(){this._staticBatches=null},e._addToStaticBatchQueue=function(t){t instanceof laya.d3.core.RenderableSprite3D&&t._addToInitStaticBatchManager();for(var n=0,i=t.numChildren;ne.maxVertexDeclaration)throw new Error("VertexDeclaration: VertexDeclaration count should not large than ",e.maxVertexDeclaration);this._shaderValues=new Ht,this._vertexElementsDic={},this._vertexStride=t,this._vertexElements=n;for(var i=0;i=0&&(c[0]=s[0]),_>=0&&(c[1]=s[1]),u>=0&&(c[2]=s[2]),o.cloneTo(i);var d=i.elements;h>=0&&(d[0]=a[0]),_>=0&&(d[1]=a[1]),u>=0&&(d[2]=a[2])},a(0,t,"top",function(){return this._top}),a(0,t,"matrix",function(){return this._matrix},function(t){this._matrix=t,e._getPlanesFromMatrix(this._matrix,this._near,this._far,this._left,this._right,this._top,this._bottom)}),a(0,t,"near",function(){return this._near}),a(0,t,"far",function(){return this._far}),a(0,t,"left",function(){return this._left}),a(0,t,"right",function(){return this._right}),a(0,t,"bottom",function(){return this._bottom}),e._getPlanesFromMatrix=function(e,t,n,i,r,a,o){var s=e.elements,l=s[0],h=s[1],_=s[2],u=s[3],c=s[4],d=s[5],f=s[6],m=s[7],p=s[8],v=s[9],g=s[10],E=s[11],S=s[12],D=s[13],T=s[14],x=s[15],M=t.normal.elements;M[0]=u+_,M[1]=m+f,M[2]=E+g,t.distance=x+T,t.normalize();var R=n.normal.elements;R[0]=u-_,R[1]=m-f,R[2]=E-g,n.distance=x-T,n.normalize();var A=i.normal.elements;A[0]=u+l,A[1]=m+c,A[2]=E+p,i.distance=x+S,i.normalize();var I=r.normal.elements;I[0]=u-l,I[1]=m-c,I[2]=E-p,r.distance=x-S,r.normalize();var y=a.normal.elements;y[0]=u-h,y[1]=m-d,y[2]=E-v,a.distance=x-D,a.normalize();var C=o.normal.elements;C[0]=u+h,C[1]=m+d,C[2]=E+v,o.distance=x+D,o.normalize()},e._get3PlaneInterPoint=function(t,n,i){var r=t.normal,a=n.normal,o=i.normal;Vt.cross(a,o,e._tempV30),Vt.cross(o,r,e._tempV31),Vt.cross(r,a,e._tempV32);var s=Vt.dot(r,e._tempV30),l=Vt.dot(a,e._tempV31),h=Vt.dot(o,e._tempV32);Vt.scale(e._tempV30,-t.distance/s,e._tempV33),Vt.scale(e._tempV31,-n.distance/l,e._tempV34),Vt.scale(e._tempV32,-i.distance/h,e._tempV35),Vt.add(e._tempV33,e._tempV34,e._tempV36),Vt.add(e._tempV35,e._tempV36,e._tempV37);return e._tempV37},i(e,["_tempV30",function(){return this._tempV30=new Vt},"_tempV31",function(){return this._tempV31=new Vt},"_tempV32",function(){return this._tempV32=new Vt},"_tempV33",function(){return this._tempV33=new Vt},"_tempV34",function(){return this._tempV34=new Vt},"_tempV35",function(){return this._tempV35=new Vt},"_tempV36",function(){return this._tempV36=new Vt},"_tempV37",function(){return this._tempV37=new Vt}]),e}(),Tt=function(){function e(e,t){this.center=null,this.radius=NaN,this.center=e,this.radius=t}r(e,"laya.d3.math.BoundSphere");var t=e.prototype;return n.imps(t,{"laya.d3.core.IClone":!0}),t.toDefault=function(){this.center.toDefault(),this.radius=0},t.intersectsRayDistance=function(e){return xt.intersectsRayAndSphereRD(e,this)},t.intersectsRayPoint=function(e,t){return xt.intersectsRayAndSphereRP(e,this,t)},t.cloneTo=function(e){var t=e;this.center.cloneTo(t.center),t.radius=this.radius},t.clone=function(){var e=new this.constructor(new Vt,new Vt);return this.cloneTo(e),e},e.createFromSubPoints=function(t,n,i,r){if(null==t)throw new Error("points");if(n<0||n>=t.length)throw new Error("start"+n+"Must be in the range [0, "+(t.length-1)+"]");if(i<0||n+i>t.length)throw new Error("count"+i+"Must be in the range <= "+t.length+"}");var a=n+i,o=e._tempVector3;o.elements[0]=0,o.elements[1]=0,o.elements[2]=0;for(var s=n;sh&&(h=_)}r.radius=Math.sqrt(h)},e.createfromPoints=function(t,n){if(null==t)throw new Error("points");e.createFromSubPoints(t,0,t.length,n)},i(e,["_tempVector3",function(){return this._tempVector3=new Vt}]),e}(),xt=function(){function e(){}return r(e,"laya.d3.math.Collision"),e.distancePlaneToPoint=function(e,t){return Vt.dot(e.normal,t)-e.distance},e.distanceBoxToPoint=function(e,t){var n=e.min.elements,i=n[0],r=n[1],a=n[2],o=e.max.elements,s=o[0],l=o[1],h=o[2],_=t.elements,u=_[0],c=_[1],d=_[2],f=0;return us&&(f+=(s-u)*(s-u)),cl&&(f+=(l-c)*(l-c)),dh&&(f+=(h-d)*(h-d)),Math.sqrt(f)},e.distanceBoxToBox=function(e,t){var n=e.min.elements,i=n[0],r=n[1],a=n[2],o=e.max.elements,s=o[0],l=o[1],h=o[2],_=t.min.elements,u=_[0],c=_[1],d=_[2],f=t.max.elements,m=f[0],p=f[1],v=f[2],g=0,E=NaN;return i>m?g+=(E=i-m)*E:u>s&&(g+=(E=u-s)*E),r>p?g+=(E=r-p)*E:c>l&&(g+=(E=c-l)*E),a>v?g+=(E=a-v)*E:d>h&&(g+=(E=d-h)*E),Math.sqrt(g)},e.distanceSphereToPoint=function(e,t){var n=Math.sqrt(Vt.distanceSquared(e.center,t));return n-=e.radius,Math.max(n,0)},e.distanceSphereToSphere=function(e,t){var n=Math.sqrt(Vt.distanceSquared(e.center,t.center));return n-=e.radius+t.radius,Math.max(n,0)},e.intersectsRayAndTriangleRD=function(t,n,i,r,a){var o=t.origin.elements,s=o[0],l=o[1],h=o[2],_=t.direction.elements,u=_[0],c=_[1],d=_[2],f=n.elements,m=f[0],p=f[1],v=f[2],g=i.elements,E=g[0],S=g[1],D=g[2],T=r.elements,x=T[0],M=T[1],R=T[2],A=e._tempV30.elements,I=A[0],y=A[1],C=A[2];I=E-m,y=S-p,C=D-v;var N=e._tempV31.elements,w=N[0],O=N[1],V=N[2];w=x-m,O=M-p,V=R-v;var P=e._tempV32.elements,L=P[0],b=P[1],F=P[2],B=I*(L=c*V-d*O)+y*(b=d*w-u*V)+C*(F=u*O-c*w);if(Mt.isZero(B))return 0,!1;var U=1/B,H=e._tempV33.elements,G=H[0],z=H[1],k=H[2],W=(G=s-m)*L+(z=l-p)*b+(k=h-v)*F;if((W*=U)<0||W>1)return 0,!1;var X=e._tempV34.elements,Z=X[0],Y=X[1],j=X[2],K=u*(Z=z*C-k*y)+c*(Y=k*I-G*C)+d*(j=G*y-z*I);if((K*=U)<0||W+K>1)return 0,!1;var q=w*Z+O*Y+V*j;return(q*=U)<0?(0,!1):(q,!0)},e.intersectsRayAndTriangleRP=function(t,n,i,r,a){return e.intersectsRayAndTriangleRD(t,n,i,r,NaN)?(Vt.scale(t.direction,NaN,e._tempV30),Vt.add(t.origin,e._tempV30,a),!0):(a=Vt.ZERO,!1)},e.intersectsRayAndPoint=function(t,n){Vt.subtract(t.origin,n,e._tempV30);var i=Vt.dot(e._tempV30,t.direction),r=Vt.dot(e._tempV30,e._tempV30)-Mt.zeroTolerance;if(r>0&&i>0)return!1;return!(i*i-r<0)},e.intersectsRayAndRay=function(t,n,i){var r=t.origin,a=r.elements,o=a[0],s=a[1],l=a[2],h=t.direction,_=h.elements,u=_[0],c=_[1],d=_[2],f=n.origin,m=f.elements,p=m[0],v=m[1],g=m[2],E=n.direction,S=E.elements,D=S[0],T=S[1],x=S[2];Vt.cross(h,E,e._tempV30);var M=e._tempV30.elements,R=Vt.scalarLengthSquared(e._tempV30);if(Mt.isZero(R)&&Mt.nearEqual(p,o)&&Mt.nearEqual(v,s)&&Mt.nearEqual(g,l))return Vt.ZERO.cloneTo(i),!0;var A=p-o,I=v-s,y=g-l,C=D,N=T,w=x,O=M[0],V=M[1],P=M[2],L=(A*N*P+I*w*O+y*C*V-A*w*V-I*C*P-y*N*O)/R,b=(A*(N=c)*P+I*(w=d)*O+y*(C=u)*V-A*w*V-I*C*P-y*N*O)/R;Vt.scale(h,L,e._tempV30),Vt.scale(E,b,e._tempV31),Vt.add(r,e._tempV30,e._tempV32),Vt.add(f,e._tempV31,e._tempV33);var F=e._tempV32.elements,B=e._tempV33.elements;return Mt.nearEqual(B[0],F[0])&&Mt.nearEqual(B[1],F[1])&&Mt.nearEqual(B[2],F[2])?(e._tempV32.cloneTo(i),!0):(Vt.ZERO.cloneTo(i),!1)},e.intersectsPlaneAndTriangle=function(t,n,i,r){var a=e.intersectsPlaneAndPoint(t,n),o=e.intersectsPlaneAndPoint(t,i),s=e.intersectsPlaneAndPoint(t,r);return a==yt.PlaneIntersectionType_Front&&o==yt.PlaneIntersectionType_Front&&s==yt.PlaneIntersectionType_Front?yt.PlaneIntersectionType_Front:a==yt.PlaneIntersectionType_Back&&o==yt.PlaneIntersectionType_Back&&s==yt.PlaneIntersectionType_Back?yt.PlaneIntersectionType_Back:yt.PlaneIntersectionType_Intersecting},e.intersectsRayAndPlaneRD=function(e,t,n){var i=t.normal,r=Vt.dot(i,e.direction);if(Mt.isZero(r))return 0,!1;var a=Vt.dot(i,e.origin);return!((-t.distance-a)/r<0)},e.intersectsRayAndPlaneRP=function(t,n,i){return e.intersectsRayAndPlaneRD(t,n,NaN)?(Vt.scale(t.direction,NaN,e._tempV30),Vt.add(t.origin,e._tempV30,e._tempV31),e._tempV31,!0):(Vt.ZERO,!1)},e.intersectsRayAndBoxRD=function(e,t){var n=e.origin.elements,i=n[0],r=n[1],a=n[2],o=e.direction.elements,s=o[0],l=o[1],h=o[2],_=t.min.elements,u=_[0],c=_[1],d=_[2],f=t.max.elements,m=f[0],p=f[1],v=f[2],g=0,E=Mt.MaxValue;if(Mt.isZero(s)){if(im)return-1}else{var S=1/s,D=(u-i)*S,T=(m-i)*S;if(D>T){var x=D;D=T,T=x}if(g=Math.max(D,g),E=Math.min(T,E),g>E)return-1}if(Mt.isZero(l)){if(rp)return-1}else{var M=1/l,R=(c-r)*M,A=(p-r)*M;if(R>A){var I=R;R=A,A=I}if(g=Math.max(R,g),E=Math.min(A,E),g>E)return-1}if(Mt.isZero(h)){if(av)return-1}else{var y=1/h,C=(d-a)*y,N=(v-a)*y;if(C>N){var w=C;C=N,N=w}if(g=Math.max(C,g),E=Math.min(N,E),g>E)return-1}return g},e.intersectsRayAndBoxRP=function(t,n,i){var r=e.intersectsRayAndBoxRD(t,n);return-1===r?(Vt.ZERO.cloneTo(i),r):(Vt.scale(t.direction,r,e._tempV30),Vt.add(t.origin,e._tempV30,e._tempV31),e._tempV31.cloneTo(i),r)},e.intersectsRayAndSphereRD=function(t,n){var i=n.radius;Vt.subtract(t.origin,n.center,e._tempV30);var r=Vt.dot(e._tempV30,t.direction),a=Vt.dot(e._tempV30,e._tempV30)-i*i;if(a>0&&r>0)return-1;var o=r*r-a;if(o<0)return-1;var s=-r-Math.sqrt(o);return s<0&&(s=0),s},e.intersectsRayAndSphereRP=function(t,n,i){var r=e.intersectsRayAndSphereRD(t,n);return-1===r?(Vt.ZERO.cloneTo(i),r):(Vt.scale(t.direction,r,e._tempV30),Vt.add(t.origin,e._tempV30,e._tempV31),e._tempV31.cloneTo(i),r)},e.intersectsSphereAndTriangle=function(t,n,i,r){var a=t.center,o=t.radius;e.closestPointPointTriangle(a,n,i,r,e._tempV30),Vt.subtract(e._tempV30,a,e._tempV31);return Vt.dot(e._tempV31,e._tempV31)<=o*o},e.intersectsPlaneAndPoint=function(e,t){var n=Vt.dot(e.normal,t)+e.distance;return n>0?yt.PlaneIntersectionType_Front:n<0?yt.PlaneIntersectionType_Back:yt.PlaneIntersectionType_Intersecting},e.intersectsPlaneAndPlane=function(t,n){Vt.cross(t.normal,n.normal,e._tempV30);var i=Vt.dot(e._tempV30,e._tempV30);return!Mt.isZero(i)},e.intersectsPlaneAndPlaneRL=function(t,n,i){var r=t.normal,a=n.normal;Vt.cross(r,a,e._tempV34);var o=Vt.dot(e._tempV34,e._tempV34);return!Mt.isZero(o)&&(Vt.scale(a,t.distance,e._tempV30),Vt.scale(r,n.distance,e._tempV31),Vt.subtract(e._tempV30,e._tempV31,e._tempV32),Vt.cross(e._tempV32,e._tempV34,e._tempV33),Vt.normalize(e._tempV34,e._tempV34),new wt(e._tempV33,e._tempV34),!0)},e.intersectsPlaneAndBox=function(t,n){var i=t.distance,r=t.normal,a=r.elements,o=a[0],s=a[1],l=a[2],h=n.min.elements,_=h[0],u=h[1],c=h[2],d=n.max.elements,f=d[0],m=d[1],p=d[2];e._tempV30.elements[0]=o>0?_:f,e._tempV30.elements[1]=s>0?u:m,e._tempV30.elements[2]=l>0?c:p,e._tempV31.elements[0]=o>0?f:_,e._tempV31.elements[1]=s>0?m:u,e._tempV31.elements[2]=l>0?p:c;var v=Vt.dot(r,e._tempV30);return v+i>0?yt.PlaneIntersectionType_Front:(v=Vt.dot(r,e._tempV31))+i<0?yt.PlaneIntersectionType_Back:yt.PlaneIntersectionType_Intersecting},e.intersectsPlaneAndSphere=function(e,t){var n=t.radius,i=Vt.dot(e.normal,t.center)+e.distance;return i>n?yt.PlaneIntersectionType_Front:i<-n?yt.PlaneIntersectionType_Back:yt.PlaneIntersectionType_Intersecting},e.intersectsBoxAndBox=function(e,t){var n=e.min.elements,i=e.max.elements,r=t.min.elements,a=t.max.elements;return!(n[0]>a[0]||r[0]>i[0])&&(!(n[1]>a[1]||r[1]>i[1])&&!(n[2]>a[2]||r[2]>i[2]))},e.intersectsBoxAndSphere=function(t,n){var i=n.center,r=n.radius;Vt.Clamp(i,t.min,t.max,e._tempV30);return Vt.distanceSquared(i,e._tempV30)<=r*r},e.intersectsSphereAndSphere=function(e,t){var n=e.radius+t.radius;return Vt.distanceSquared(e.center,t.center)<=n*n},e.boxContainsPoint=function(e,t){var n=e.min.elements,i=e.max.elements,r=t.elements;return n[0]<=r[0]&&i[0]>=r[0]&&n[1]<=r[1]&&i[1]>=r[1]&&n[2]<=r[2]&&i[2]>=r[2]?1:0},e.boxContainsBox=function(e,t){var n=e.min.elements,i=n[0],r=n[1],a=n[2],o=e.max.elements,s=o[0],l=o[1],h=o[2],_=t.min.elements,u=_[0],c=_[1],d=_[2],f=t.max.elements,m=f[0],p=f[1],v=f[2];return sm?0:lp?0:hv?0:i<=u&&m<=m&&r<=c&&p<=l&&a<=d&&v<=h?1:2},e.boxContainsSphere=function(t,n){var i=t.min,r=i.elements,a=r[0],o=r[1],s=r[2],l=t.max,h=l.elements,_=h[0],u=h[1],c=h[2],d=n.center,f=d.elements,m=f[0],p=f[1],v=f[2],g=n.radius;Vt.Clamp(d,i,l,e._tempV30);return Vt.distanceSquared(d,e._tempV30)>g*g?0:a+g<=m&&m<=_-g&&_-a>g&&o+g<=p&&p<=u-g&&u-o>g&&s+g<=v&&v<=c-g&&c-s>g?1:2},e.sphereContainsPoint=function(e,t){return Vt.distanceSquared(t,e.center)<=e.radius*e.radius?1:0},e.sphereContainsTriangle=function(t,n,i,r){var a=e.sphereContainsPoint(t,n),o=e.sphereContainsPoint(t,i),s=e.sphereContainsPoint(t,r);return 1==a&&1==o&&1==s?1:e.intersectsSphereAndTriangle(t,n,i,r)?2:0},e.sphereContainsBox=function(t,n){var i=t.center.elements,r=i[0],a=i[1],o=i[2],s=t.radius,l=n.min.elements,h=l[0],_=l[1],u=l[2],c=n.max.elements,d=c[0],f=c[1],m=c[2],p=e._tempV30.elements;p[0],p[1],p[2];if(!e.intersectsBoxAndSphere(n,t))return 0;var v=s*s;return r-h,a-f,o-m,Vt.scalarLengthSquared(e._tempV30)>v?2:(r-d,a-f,o-m,Vt.scalarLengthSquared(e._tempV30)>v?2:(r-d,a-_,o-m,Vt.scalarLengthSquared(e._tempV30)>v?2:(r-h,a-_,o-m,Vt.scalarLengthSquared(e._tempV30)>v?2:(r-h,a-f,o-u,Vt.scalarLengthSquared(e._tempV30)>v?2:(r-d,a-f,o-u,Vt.scalarLengthSquared(e._tempV30)>v?2:(r-d,a-_,o-u,Vt.scalarLengthSquared(e._tempV30)>v?2:(r-h,a-_,o-u,Vt.scalarLengthSquared(e._tempV30)>v?2:1)))))))},e.sphereContainsSphere=function(e,t){var n=e.radius,i=t.radius,r=Vt.distance(e.center,t.center);return n+i=0&&h<=l)i.cloneTo(a);else{var c=o*h-l*s;if(c<=0&&o>=0&&l<=0){var d=o/(o-l);return Vt.scale(e._tempV30,d,a),void Vt.add(n,a,a)}if(u>=0&&_<=u)r.cloneTo(a);else{var f=_*s-o*u;if(f<=0&&s>=0&&u<=0){var m=s/(s-u);return Vt.scale(e._tempV31,m,a),void Vt.add(n,a,a)}var p=l*u-_*h;if(p<=0&&h-l>=0&&_-u>=0){var v=(h-l)/(h-l+(_-u));return Vt.subtract(r,i,a),Vt.scale(a,v,a),void Vt.add(i,a,a)}var g=1/(p+f+c),E=f*g,S=c*g;Vt.scale(e._tempV30,E,e._tempV35),Vt.scale(e._tempV31,S,e._tempV36),Vt.add(e._tempV35,e._tempV36,a),Vt.add(n,a,a)}}},e.closestPointPlanePoint=function(t,n,i){var r=t.normal,a=Vt.dot(r,n)-t.distance;Vt.scale(r,a,e._tempV30),Vt.subtract(n,e._tempV30,i)},e.closestPointBoxPoint=function(t,n,i){Vt.max(n,t.min,e._tempV30),Vt.min(e._tempV30,t.max,i)},e.closestPointSpherePoint=function(e,t,n){var i=e.center;Vt.subtract(t,i,n),Vt.normalize(n,n),Vt.scale(n,e.radius,n),Vt.add(n,i,n)},e.closestPointSphereSphere=function(e,t,n){var i=e.center;Vt.subtract(t.center,i,n),Vt.normalize(n,n),Vt.scale(n,e.radius,n),Vt.add(n,i,n)},i(e,["_tempV30",function(){return this._tempV30=new Vt},"_tempV31",function(){return this._tempV31=new Vt},"_tempV32",function(){return this._tempV32=new Vt},"_tempV33",function(){return this._tempV33=new Vt},"_tempV34",function(){return this._tempV34=new Vt},"_tempV35",function(){return this._tempV35=new Vt},"_tempV36",function(){return this._tempV36=new Vt}]),e}(),Mt=(function(){function e(){}r(e,"laya.d3.math.ContainmentType"),e.Disjoint=0,e.Contains=1,e.Intersects=2}(),function(){function e(){}return r(e,"laya.d3.math.MathUtils3D"),e.isZero=function(t){return Math.abs(t)3)throw new Error("row","Rows and columns for matrices run from 0 to 3, inclusive.");if(t<0||t>3)throw new Error("column","Rows and columns for matrices run from 0 to 3, inclusive.");return this.elements[4*e+t]},t.setElementByRowColumn=function(e,t,n){if(e<0||e>3)throw new Error("row","Rows and columns for matrices run from 0 to 3, inclusive.");if(t<0||t>3)throw new Error("column","Rows and columns for matrices run from 0 to 3, inclusive.");this.elements[4*e+t]=n},t.equalsOtherMatrix=function(e){var t=this.elements,n=e.elements;return Mt.nearEqual(t[0],n[0])&&Mt.nearEqual(t[1],n[1])&&Mt.nearEqual(t[2],n[2])&&Mt.nearEqual(t[3],n[3])&&Mt.nearEqual(t[4],n[4])&&Mt.nearEqual(t[5],n[5])&&Mt.nearEqual(t[6],n[6])&&Mt.nearEqual(t[7],n[7])&&Mt.nearEqual(t[8],n[8])&&Mt.nearEqual(t[9],n[9])&&Mt.nearEqual(t[10],n[10])&&Mt.nearEqual(t[11],n[11])&&Mt.nearEqual(t[12],n[12])&&Mt.nearEqual(t[13],n[13])&&Mt.nearEqual(t[14],n[14])&&Mt.nearEqual(t[15],n[15])},t.decomposeTransRotScale=function(t,n,i){var r=e._tempMatrix4x4;return this.decomposeTransRotMatScale(t,r,i)?(Ct.createFromMatrix4x4(r,n),!0):(n.identity(),!1)},t.decomposeTransRotMatScale=function(t,n,i){var r=this.elements,a=t.elements,o=n.elements,s=i.elements;a[0]=r[12],a[1]=r[13],a[2]=r[14];var l=r[0],h=r[1],_=r[2],u=r[4],c=r[5],d=r[6],f=r[8],m=r[9],p=r[10],v=s[0]=Math.sqrt(l*l+h*h+_*_),g=s[1]=Math.sqrt(u*u+c*c+d*d),E=s[2]=Math.sqrt(f*f+m*m+p*p);if(Mt.isZero(v)||Mt.isZero(g)||Mt.isZero(E))return o[1]=o[2]=o[3]=o[4]=o[6]=o[7]=o[8]=o[9]=o[11]=o[12]=o[13]=o[14]=0,o[0]=o[5]=o[10]=o[15]=1,!1;var S=e._tempVector0,D=S.elements;D[0]=f/E,D[1]=m/E,D[2]=p/E;var T=e._tempVector1,x=T.elements;x[0]=l/v,x[1]=h/v,x[2]=_/v;var M=e._tempVector2;Vt.cross(S,T,M);var R=e._tempVector1;return Vt.cross(M,S,R),o[3]=o[7]=o[11]=o[12]=o[13]=o[14]=0,o[15]=1,o[0]=R.x,o[1]=R.y,o[2]=R.z,o[4]=M.x,o[5]=M.y,o[6]=M.z,o[8]=S.x,o[9]=S.y,o[10]=S.z,o[0]*l+o[1]*h+o[2]*_<0&&(s[0]=-v),o[4]*u+o[5]*c+o[6]*d<0&&(s[1]=-g),o[8]*f+o[9]*m+o[10]*p<0&&(s[2]=-E),!0},t.decomposeYawPitchRoll=function(e){var t=e.elements,n=Math.asin(-this.elements[9]);t[1]=n;Math.cos(n)>Mt.zeroTolerance?(t[2]=Math.atan2(this.elements[1],this.elements[5]),t[0]=Math.atan2(this.elements[8],this.elements[10])):(t[2]=Math.atan2(-this.elements[4],this.elements[0]),t[0]=0)},t.normalize=function(){var e=this.elements,t=e[0],n=e[1],i=e[2],r=Math.sqrt(t*t+n*n+i*i);if(!r)return e[0]=0,e[1]=0,void(e[2]=0);1!=r&&(r=1/r,e[0]=t*r,e[1]=n*r,e[2]=i*r)},t.transpose=function(){var e,t;return e=this.elements,t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this},t.invert=function(e){var t=this.elements,n=e.elements,i=t[0],r=t[1],a=t[2],o=t[3],s=t[4],l=t[5],h=t[6],_=t[7],u=t[8],c=t[9],d=t[10],f=t[11],m=t[12],p=t[13],v=t[14],g=t[15],E=i*l-r*s,S=i*h-a*s,D=i*_-o*s,T=r*h-a*l,x=r*_-o*l,M=a*_-o*h,R=u*p-c*m,A=u*v-d*m,I=u*g-f*m,y=c*v-d*p,C=c*g-f*p,N=d*g-f*v,w=E*N-S*C+D*y+T*I-x*A+M*R;0!==Math.abs(w)&&(w=1/w,n[0]=(l*N-h*C+_*y)*w,n[1]=(a*C-r*N-o*y)*w,n[2]=(p*M-v*x+g*T)*w,n[3]=(d*x-c*M-f*T)*w,n[4]=(h*I-s*N-_*A)*w,n[5]=(i*N-a*I+o*A)*w,n[6]=(v*D-m*M-g*S)*w,n[7]=(u*M-d*D+f*S)*w,n[8]=(s*C-l*I+_*R)*w,n[9]=(r*I-i*C-o*R)*w,n[10]=(m*x-p*D+g*E)*w,n[11]=(c*D-u*x-f*E)*w,n[12]=(l*A-s*y-h*R)*w,n[13]=(i*y-r*A+a*R)*w,n[14]=(p*S-m*T-v*E)*w,n[15]=(u*T-c*S+d*E)*w)},t.identity=function(){var e=this.elements;e[1]=e[2]=e[3]=e[4]=e[6]=e[7]=e[8]=e[9]=e[11]=e[12]=e[13]=e[14]=0,e[0]=e[5]=e[10]=e[15]=1},t.cloneTo=function(e){var t,n,i;if(n=this.elements,i=e.elements,n!==i)for(t=0;t<16;++t)i[t]=n[t]},t.clone=function(){var e=new this.constructor;return this.cloneTo(e),e},t.getTranslationVector=function(e){var t=this.elements,n=e.elements;n[0]=t[12],n[1]=t[13],n[2]=t[14]},t.setTranslationVector=function(e){var t=this.elements,n=e.elements;t[12]=n[0],t[13]=n[1],t[14]=n[2]},t.getForward=function(e){var t=this.elements,n=e.elements;n[0]=-t[8],n[1]=-t[9],n[2]=-t[10]},t.setForward=function(e){var t=this.elements,n=e.elements;t[8]=-n[0],t[9]=-n[1],t[10]=-n[2]},e.createRotationX=function(e,t){var n=t.elements,i=Math.sin(e),r=Math.cos(e);n[1]=n[2]=n[3]=n[4]=n[7]=n[8]=n[11]=n[12]=n[13]=n[14]=0,n[0]=n[15]=1,n[5]=n[10]=r,n[6]=i,n[9]=-i},e.createRotationY=function(e,t){var n=t.elements,i=Math.sin(e),r=Math.cos(e);n[1]=n[3]=n[4]=n[6]=n[7]=n[9]=n[11]=n[12]=n[13]=n[14]=0,n[5]=n[15]=1,n[0]=n[10]=r,n[2]=-i,n[8]=i},e.createRotationZ=function(e,t){var n=t.elements,i=Math.sin(e),r=Math.cos(e);n[2]=n[3]=n[6]=n[7]=n[8]=n[9]=n[11]=n[12]=n[13]=n[14]=0,n[10]=n[15]=1,n[0]=n[5]=r,n[1]=i,n[4]=-i},e.createRotationYawPitchRoll=function(t,n,i,r){Ct.createFromYawPitchRoll(t,n,i,e._tempQuaternion),e.createRotationQuaternion(e._tempQuaternion,r)},e.createRotationAxis=function(e,t,n){var i=e.elements,r=i[0],a=i[1],o=i[2],s=Math.cos(t),l=Math.sin(t),h=r*r,_=a*a,u=o*o,c=r*a,d=r*o,f=a*o,m=n.elements;m[3]=m[7]=m[11]=m[12]=m[13]=m[14]=0,m[15]=1,m[0]=h+s*(1-h),m[1]=c-s*c+l*o,m[2]=d-s*d-l*a,m[4]=c-s*c-l*o,m[5]=_+s*(1-_),m[6]=f-s*f+l*r,m[8]=d-s*d+l*a,m[9]=f-s*f-l*r,m[10]=u+s*(1-u)},e.createRotationQuaternion=function(e,t){var n=e.elements,i=t.elements,r=n[0],a=n[1],o=n[2],s=n[3],l=r*r,h=a*a,_=o*o,u=r*a,c=o*s,d=o*r,f=a*s,m=a*o,p=r*s;i[3]=i[7]=i[11]=i[12]=i[13]=i[14]=0,i[15]=1,i[0]=1-2*(h+_),i[1]=2*(u+c),i[2]=2*(d-f),i[4]=2*(u-c),i[5]=1-2*(_+l),i[6]=2*(m+p),i[8]=2*(d+f),i[9]=2*(m-p),i[10]=1-2*(h+l)},e.createTranslate=function(e,t){var n=e.elements,i=t.elements;i[4]=i[8]=i[1]=i[9]=i[2]=i[6]=i[3]=i[7]=i[11]=0,i[0]=i[5]=i[10]=i[15]=1,i[12]=n[0],i[13]=n[1],i[14]=n[2]},e.createScaling=function(e,t){var n=e.elements,i=t.elements;i[0]=n[0],i[5]=n[1],i[10]=n[2],i[1]=i[4]=i[8]=i[12]=i[9]=i[13]=i[2]=i[6]=i[14]=i[3]=i[7]=i[11]=0,i[15]=1},e.multiply=function(e,t,n){var i,r,a,o,s,l,h,_;if(r=n.elements,a=e.elements,o=t.elements,r===o)for(o=new Float32Array(16),i=0;i<16;++i)o[i]=r[i];for(i=0;i<4;i++)s=a[i],l=a[i+4],h=a[i+8],_=a[i+12],r[i]=s*o[0]+l*o[1]+h*o[2]+_*o[3],r[i+4]=s*o[4]+l*o[5]+h*o[6]+_*o[7],r[i+8]=s*o[8]+l*o[9]+h*o[10]+_*o[11],r[i+12]=s*o[12]+l*o[13]+h*o[14]+_*o[15]},e.createFromQuaternion=function(e,t){var n=t.elements,i=e.elements,r=i[0],a=i[1],o=i[2],s=i[3],l=r+r,h=a+a,_=o+o,u=r*l,c=a*l,d=a*h,f=o*l,m=o*h,p=o*_,v=s*l,g=s*h,E=s*_;n[0]=1-d-p,n[1]=c+E,n[2]=f-g,n[3]=0,n[4]=c-E,n[5]=1-u-p,n[6]=m+v,n[7]=0,n[8]=f+g,n[9]=m-v,n[10]=1-u-d,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1},e.createAffineTransformation=function(e,t,n,i){var r=e.elements,a=t.elements,o=n.elements,s=i.elements,l=a[0],h=a[1],_=a[2],u=a[3],c=l+l,d=h+h,f=_+_,m=l*c,p=l*d,v=l*f,g=h*d,E=h*f,S=_*f,D=u*c,T=u*d,x=u*f,M=o[0],R=o[1],A=o[2];s[0]=(1-(g+S))*M,s[1]=(p+x)*M,s[2]=(v-T)*M,s[3]=0,s[4]=(p-x)*R,s[5]=(1-(m+S))*R,s[6]=(E+D)*R,s[7]=0,s[8]=(v+T)*A,s[9]=(E-D)*A,s[10]=(1-(m+g))*A,s[11]=0,s[12]=r[0],s[13]=r[1],s[14]=r[2],s[15]=1},e.createLookAt=function(t,n,i,r){var a=r.elements,o=e._tempVector0,s=e._tempVector1,l=e._tempVector2;Vt.subtract(t,n,l),Vt.normalize(l,l),Vt.cross(i,l,o),Vt.normalize(o,o),Vt.cross(l,o,s),r.identity(),a[0]=o.x,a[4]=o.y,a[8]=o.z,a[1]=s.x,a[5]=s.y,a[9]=s.z,a[2]=l.x,a[6]=l.y,a[10]=l.z,a[12]=-Vt.dot(o,t),a[13]=-Vt.dot(s,t),a[14]=-Vt.dot(l,t)},e.createPerspective=function(e,t,n,i,r){var a=r.elements,o=1/Math.tan(e/2),s=1/(n-i);a[0]=o/t,a[5]=o,a[10]=(i+n)*s,a[11]=-1,a[14]=2*i*n*s,a[1]=a[2]=a[3]=a[4]=a[6]=a[7]=a[8]=a[9]=a[12]=a[13]=a[15]=0},e.createOrthoOffCenterRH=function(e,t,n,i,r,a,o){var s=o.elements,l=1/(e-t),h=1/(n-i),_=1/(r-a);s[1]=s[2]=s[3]=s[4]=s[6]=s[7]=s[8]=s[9]=s[11]=0,s[15]=1,s[0]=-2*l,s[5]=-2*h,s[10]=2*_,s[12]=(e+t)*l,s[13]=(i+n)*h,s[14]=(a+r)*_},e.translation=function(e,t){var n=e.elements,i=t.elements;i[0]=i[5]=i[10]=i[15]=1,i[12]=n[0],i[13]=n[1],i[14]=n[2]},i(e,["_tempMatrix4x4",function(){return this._tempMatrix4x4=new e},"_tempVector0",function(){return this._tempVector0=new Vt},"_tempVector1",function(){return this._tempVector1=new Vt},"_tempVector2",function(){return this._tempVector2=new Vt},"_tempQuaternion",function(){return this._tempQuaternion=new Ct},"DEFAULT",function(){return this.DEFAULT=new e},"ZERO",function(){return this.ZERO=new e(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}]),e}(),It=function(){function e(e,t){this.extents=null,this.transformation=null,this.extents=e,this.transformation=t}r(e,"laya.d3.math.OrientedBoundBox");var t=e.prototype;return t.getCorners=function(t){var n=e._tempV30.elements,i=e._tempV31.elements,r=e._tempV32.elements,a=this.extents.elements;n[0]=a[0],n[1]=n[2]=0,i[1]=a[1],i[0]=i[2]=0,r[2]=a[2],r[0]=r[1]=0,Vt.TransformNormal(e._tempV30,this.transformation,e._tempV30),Vt.TransformNormal(e._tempV31,this.transformation,e._tempV31),Vt.TransformNormal(e._tempV32,this.transformation,e._tempV32);var o=e._tempV33;this.transformation.getTranslationVector(o),t.length=8,Vt.add(o,e._tempV30,e._tempV34),Vt.add(e._tempV34,e._tempV31,e._tempV34),Vt.add(e._tempV34,e._tempV32,t[0]),Vt.add(o,e._tempV30,e._tempV34),Vt.add(e._tempV34,e._tempV31,e._tempV34),Vt.subtract(e._tempV34,e._tempV32,t[1]),Vt.subtract(o,e._tempV30,e._tempV34),Vt.add(e._tempV34,e._tempV31,e._tempV34),Vt.subtract(e._tempV34,e._tempV32,t[2]),Vt.subtract(o,e._tempV30,e._tempV34),Vt.add(e._tempV34,e._tempV31,e._tempV34),Vt.add(e._tempV34,e._tempV32,t[3]),Vt.add(o,e._tempV30,e._tempV34),Vt.subtract(e._tempV34,e._tempV31,e._tempV34),Vt.add(e._tempV34,e._tempV32,t[4]),Vt.add(o,e._tempV30,e._tempV34),Vt.subtract(e._tempV34,e._tempV31,e._tempV34),Vt.subtract(e._tempV34,e._tempV32,t[5]),Vt.subtract(o,e._tempV30,e._tempV34),Vt.subtract(e._tempV34,e._tempV31,e._tempV34),Vt.subtract(e._tempV34,e._tempV32,t[6]),Vt.subtract(o,e._tempV30,e._tempV34),Vt.subtract(e._tempV34,e._tempV31,e._tempV34),Vt.add(e._tempV34,e._tempV32,t[7])},t.transform=function(e){At.multiply(this.transformation,e,this.transformation)},t.scale=function(e){Vt.multiply(this.extents,e,this.extents)},t.translate=function(t){this.transformation.getTranslationVector(e._tempV30),Vt.add(e._tempV30,t,e._tempV31),this.transformation.setTranslationVector(e._tempV31)},t.Size=function(e){Vt.scale(this.extents,2,e)},t.getSize=function(t){var n=this.extents.elements;e._tempV30.x=n[0],e._tempV31.y=n[1],e._tempV32.z=n[2],Vt.TransformNormal(e._tempV30,this.transformation,e._tempV30),Vt.TransformNormal(e._tempV31,this.transformation,e._tempV31),Vt.TransformNormal(e._tempV31,this.transformation,e._tempV32);var i=t.elements;i[0]=Vt.scalarLength(e._tempV30),i[1]=Vt.scalarLength(e._tempV31),i[2]=Vt.scalarLength(e._tempV32)},t.getSizeSquared=function(t){var n=this.extents.elements;e._tempV30.x=n[0],e._tempV31.y=n[1],e._tempV32.z=n[2],Vt.TransformNormal(e._tempV30,this.transformation,e._tempV30),Vt.TransformNormal(e._tempV31,this.transformation,e._tempV31),Vt.TransformNormal(e._tempV31,this.transformation,e._tempV32);var i=t.elements;i[0]=Vt.scalarLengthSquared(e._tempV30),i[1]=Vt.scalarLengthSquared(e._tempV31),i[2]=Vt.scalarLengthSquared(e._tempV32)},t.getCenter=function(e){this.transformation.getTranslationVector(e)},t.containsPoint=function(t){var n=this.extents.elements,i=n[0],r=n[1],a=n[2];this.transformation.invert(e._tempM0),Vt.transformCoordinate(t,e._tempM0,e._tempV30);var o=e._tempV30.elements,s=Math.abs(o[0]),l=Math.abs(o[1]),h=Math.abs(o[2]);return Mt.nearEqual(s,i)&&Mt.nearEqual(l,r)&&Mt.nearEqual(h,a)?2:sl*l)return 0;var h=e._tempV30.elements,_=h[0],u=h[1],c=h[2],d=e._tempV32.elements,f=d[0],m=d[1],p=d[2];return f+l<=_&&_<=r-l&&r-f>l&&m+l<=u&&u<=a-l&&a-m>l&&p+l<=c&&c<=o-l&&o-p>l?1:2},t.containsOrientedBoundBox=function(t){var n=0,i=0;t.getCorners(e._corners);var r=this.containsPoints(e._corners);if(0!=r)return r;var a=this.extents.elements;t.extents.cloneTo(e._tempV35);var o=e._tempV35.elements;e._getRows(this.transformation,e._rows1),e._getRows(t.transformation,e._rows2);var s=NaN,l=NaN,h=NaN;for(n=0;n<4;n++)for(i=0;i<4;i++)3==n||3==i?(e._tempM0.setElementByRowColumn(n,i,0),e._tempM1.setElementByRowColumn(n,i,0)):(h=Vt.dot(e._rows1[n],e._rows2[i]),e._tempM0.setElementByRowColumn(n,i,h),e._tempM1.setElementByRowColumn(n,i,Math.abs(h)));t.getCenter(e._tempV34),this.getCenter(e._tempV36),Vt.subtract(e._tempV34,e._tempV36,e._tempV30);var _=e._tempV31.elements;_[0]=Vt.dot(e._tempV30,e._rows1[0]),_[1]=Vt.dot(e._tempV30,e._rows1[1]),_[2]=Vt.dot(e._tempV30,e._rows1[2]);var u=e._tempV32.elements,c=e._tempV33.elements;for(n=0;n<3;n++)if(u[0]=e._tempM1.getElementByRowColumn(n,0),u[1]=e._tempM1.getElementByRowColumn(n,1),u[2]=e._tempM1.getElementByRowColumn(n,2),s=a[n],l=Vt.dot(e._tempV35,e._tempV32),Math.abs(_[n])>s+l)return 0;for(i=0;i<3;i++)if(u[0]=e._tempM1.getElementByRowColumn(0,i),u[1]=e._tempM1.getElementByRowColumn(1,i),u[2]=e._tempM1.getElementByRowColumn(2,i),c[0]=e._tempM0.getElementByRowColumn(0,i),c[1]=e._tempM0.getElementByRowColumn(1,i),c[2]=e._tempM0.getElementByRowColumn(2,i),s=Vt.dot(this.extents,e._tempV32),l=o[i],Math.abs(Vt.dot(e._tempV31,e._tempV33))>s+l)return 0;for(n=0;n<3;n++)for(i=0;i<3;i++){var d=(n+1)%3,f=(n+2)%3,m=(i+1)%3,p=(i+2)%3;if(s=a[d]*e._tempM1.getElementByRowColumn(f,i)+a[f]*e._tempM1.getElementByRowColumn(d,i),l=o[m]*e._tempM1.getElementByRowColumn(n,p)+o[p]*e._tempM1.getElementByRowColumn(n,m),Math.abs(_[f]*e._tempM0.getElementByRowColumn(d,i)-_[d]*e._tempM0.getElementByRowColumn(f,i))>s+l)return 0}return 2},t.containsLine=function(t,n){e._corners[0]=t,e._corners[1]=n;var i=this.containsPoints(e._corners);if(0!=i)return i;var r=this.extents.elements,a=r[0],o=r[1],s=r[2];this.transformation.invert(e._tempM0),Vt.transformCoordinate(t,e._tempM0,e._tempV30),Vt.transformCoordinate(n,e._tempM0,e._tempV31),Vt.add(e._tempV30,e._tempV31,e._tempV32),Vt.scale(e._tempV32,.5,e._tempV32),Vt.subtract(e._tempV30,e._tempV32,e._tempV33);var l=e._tempV33.elements,h=l[0],_=l[1],u=l[2],c=e._tempV34.elements,d=c[0]=Math.abs(l[0]),f=c[1]=Math.abs(l[1]),m=c[2]=Math.abs(l[2]),p=e._tempV32.elements,v=p[0],g=p[1],E=p[2];return Math.abs(v)>a+d?0:Math.abs(g)>o+f?0:Math.abs(E)>s+m?0:Math.abs(g*u-E*_)>o*m+s*f?0:Math.abs(v*u-E*h)>a*m+s*d?0:Math.abs(v*_-g*h)>a*f+o*d?0:2},t.containsBoundBox=function(t){var n=0,i=0,r=t.min,a=t.max;t.getCorners(e._corners);var o=this.containsPoints(e._corners);if(0!=o)return o;Vt.subtract(a,r,e._tempV30),Vt.scale(e._tempV30,.5,e._tempV30),Vt.add(r,e._tempV30,e._tempV30),Vt.subtract(a,e._tempV30,e._tempV31);var s=this.extents.elements,l=e._tempV31.elements;e._getRows(this.transformation,e._rows1),this.transformation.invert(e._tempM0);var h=NaN,_=NaN;for(n=0;n<3;n++)for(i=0;i<3;i++)e._tempM1.setElementByRowColumn(n,i,Math.abs(e._tempM0.getElementByRowColumn(n,i)));this.getCenter(e._tempV35),Vt.subtract(e._tempV30,e._tempV35,e._tempV32);var u=e._tempV31.elements;u[0]=Vt.dot(e._tempV32,e._rows1[0]),u[1]=Vt.dot(e._tempV32,e._rows1[1]),u[2]=Vt.dot(e._tempV32,e._rows1[2]);var c=e._tempV33.elements,d=e._tempV34.elements;for(n=0;n<3;n++)if(c[0]=e._tempM1.getElementByRowColumn(n,0),c[1]=e._tempM1.getElementByRowColumn(n,1),c[2]=e._tempM1.getElementByRowColumn(n,2),h=s[n],_=Vt.dot(e._tempV31,e._tempV33),Math.abs(u[n])>h+_)return 0;for(i=0;i<3;i++)if(c[0]=e._tempM1.getElementByRowColumn(0,i),c[1]=e._tempM1.getElementByRowColumn(1,i),c[2]=e._tempM1.getElementByRowColumn(2,i),d[0]=e._tempM0.getElementByRowColumn(0,i),d[1]=e._tempM0.getElementByRowColumn(1,i),d[2]=e._tempM0.getElementByRowColumn(2,i),h=Vt.dot(this.extents,e._tempV33),_=l[i],Math.abs(Vt.dot(e._tempV31,e._tempV34))>h+_)return 0;for(n=0;n<3;n++)for(i=0;i<3;i++){var f=(n+1)%3,m=(n+2)%3,p=(i+1)%3,v=(i+2)%3;if(h=s[f]*e._tempM1.getElementByRowColumn(m,i)+s[m]*e._tempM1.getElementByRowColumn(f,i),_=l[p]*e._tempM1.getElementByRowColumn(n,v)+l[v]*e._tempM1.getElementByRowColumn(n,p),Math.abs(u[m]*e._tempM0.getElementByRowColumn(f,i)-u[f]*e._tempM0.getElementByRowColumn(m,i))>h+_)return 0}return 2},t.intersectsRay=function(t,n){Vt.scale(this.extents,-1,e._tempV30),this.transformation.invert(e._tempM0),Vt.TransformNormal(t.direction,e._tempM0,e._ray.direction),Vt.transformCoordinate(t.origin,e._tempM0,e._ray.origin),e._boxBound1.min=e._tempV30,e._boxBound1.max=this.extents;var i=xt.intersectsRayAndBoxRP(e._ray,e._boxBound1,n);return-1!==i&&Vt.transformCoordinate(n,this.transformation,n),i},t._getLocalCorners=function(t){t.length=8;var n=this.extents.elements;e._tempV30.x=n[0],e._tempV31.y=n[1],e._tempV32.z=n[2],Vt.add(e._tempV30,e._tempV31,e._tempV33),Vt.add(e._tempV33,e._tempV32,t[0]),Vt.add(e._tempV30,e._tempV31,e._tempV33),Vt.subtract(e._tempV33,e._tempV32,t[1]),Vt.subtract(e._tempV31,e._tempV30,e._tempV33),Vt.subtract(e._tempV33,e._tempV30,t[2]),Vt.subtract(e._tempV31,e._tempV30,e._tempV33),Vt.add(e._tempV33,e._tempV32,t[3]),Vt.subtract(e._tempV30,e._tempV31,e._tempV33),Vt.add(e._tempV33,e._tempV32,t[4]),Vt.subtract(e._tempV30,e._tempV31,e._tempV33),Vt.subtract(e._tempV33,e._tempV32,t[5]),Vt.scale(t[0],-1,t[6]),Vt.subtract(e._tempV32,e._tempV30,e._tempV33),Vt.subtract(e._tempV33,e._tempV31,t[7])},t.equals=function(e){return this.extents==e.extents&&this.transformation==e.transformation},t.cloneTo=function(e){var t=e;this.extents.cloneTo(t.extents),this.transformation.cloneTo(t.transformation)},e.createByBoundBox=function(t,n){var i=t.min,r=t.max;Vt.subtract(r,i,e._tempV30),Vt.scale(e._tempV30,.5,e._tempV30),Vt.add(i,e._tempV30,e._tempV31),Vt.subtract(r,e._tempV31,e._tempV32),At.translation(e._tempV31,e._tempM0);var a=e._tempV32.clone(),o=e._tempM0.clone();n.extents=a,n.transformation=o},e.createByMinAndMaxVertex=function(t,n){Vt.subtract(n,t,e._tempV30),Vt.scale(e._tempV30,.5,e._tempV30),Vt.add(t,e._tempV30,e._tempV31),Vt.subtract(n,e._tempV31,e._tempV32),At.translation(e._tempV31,e._tempM0);return new e(e._tempV32,e._tempM0)},e._getRows=function(e,t){t.length=3;var n=e.elements,i=t[0].elements;i[0]=n[0],i[1]=n[1],i[2]=n[2];var r=t[1].elements;r[0]=n[4],r[1]=n[5],r[2]=n[6];var a=t[2].elements;a[0]=n[8],a[1]=n[9],a[2]=n[10]},e.getObbtoObbMatrix4x4=function(t,n,i,r){var a=t.transformation,o=n.transformation;if(i){e._getRows(a,e._rows1),e._getRows(o,e._rows2);for(var s=0;s<3;s++)for(var l=0;l<3;l++)r.setElementByRowColumn(s,l,Vt.dot(e._rows2[s],e._rows1[l]));n.getCenter(e._tempV30),t.getCenter(e._tempV31),Vt.subtract(e._tempV30,e._tempV31,e._tempV32);var h=r.elements;h[12]=Vt.dot(e._tempV32,e._rows1[0]),h[13]=Vt.dot(e._tempV32,e._rows1[1]),h[14]=Vt.dot(e._tempV32,e._rows1[2]),h[15]=1}else a.invert(e._tempM0),At.multiply(o,e._tempM0,r)},e.merge=function(t,n,i){var r=t.extents,a=t.transformation;e.getObbtoObbMatrix4x4(t,n,i,e._tempM0),n._getLocalCorners(e._corners),Vt.transformCoordinate(e._corners[0],e._tempM0,e._corners[0]),Vt.transformCoordinate(e._corners[1],e._tempM0,e._corners[1]),Vt.transformCoordinate(e._corners[2],e._tempM0,e._corners[2]),Vt.transformCoordinate(e._corners[3],e._tempM0,e._corners[3]),Vt.transformCoordinate(e._corners[4],e._tempM0,e._corners[4]),Vt.transformCoordinate(e._corners[5],e._tempM0,e._corners[5]),Vt.transformCoordinate(e._corners[6],e._tempM0,e._corners[6]),Vt.transformCoordinate(e._corners[7],e._tempM0,e._corners[7]),Vt.scale(r,-1,e._boxBound1.min),r.cloneTo(e._boxBound1.max),St.createfromPoints(e._corners,e._boxBound2),St.merge(e._boxBound2,e._boxBound1,e._boxBound3);var o=e._boxBound3.min,s=e._boxBound3.max;Vt.subtract(s,o,e._tempV30),Vt.scale(e._tempV30,.5,e._tempV30),Vt.add(o,e._tempV30,e._tempV32),Vt.subtract(s,e._tempV32,r),Vt.transformCoordinate(e._tempV32,a,e._tempV33)},i(e,["_tempV30",function(){return this._tempV30=new Vt},"_tempV31",function(){return this._tempV31=new Vt},"_tempV32",function(){return this._tempV32=new Vt},"_tempV33",function(){return this._tempV33=new Vt},"_tempV34",function(){return this._tempV34=new Vt},"_tempV35",function(){return this._tempV35=new Vt},"_tempV36",function(){return this._tempV36=new Vt},"_tempM0",function(){return this._tempM0=new At},"_tempM1",function(){return this._tempM1=new At},"_corners",function(){return this._corners=[new Vt,new Vt,new Vt,new Vt,new Vt,new Vt,new Vt,new Vt]},"_rows1",function(){return this._rows1=[new Vt,new Vt,new Vt]},"_rows2",function(){return this._rows2=[new Vt,new Vt,new Vt]},"_ray",function(){return this._ray=new wt(new Vt,new Vt)},"_boxBound1",function(){return this._boxBound1=new St(new Vt,new Vt)},"_boxBound2",function(){return this._boxBound2=new St(new Vt,new Vt)},"_boxBound3",function(){return this._boxBound3=new St(new Vt,new Vt)}]),e}(),yt=function(){function e(e,t){this.normal=null,this.distance=NaN,void 0===t&&(t=0),this.normal=e,this.distance=t}r(e,"laya.d3.math.Plane");return e.prototype.normalize=function(){var e=this.normal.elements,t=e[0],n=e[1],i=e[2],r=1/Math.sqrt(t*t+n*n+i*i);e[0]=t*r,e[1]=n*r,e[2]=i*r,this.distance*=r},e.createPlaneBy3P=function(t,n,i){var r=t.elements,a=n.elements,o=i.elements,s=a[0]-r[0],l=a[1]-r[1],h=a[2]-r[2],_=o[0]-r[0],u=o[1]-r[1],c=o[2]-r[2],d=l*c-h*u,f=h*_-s*c,m=s*u-l*_,p=1/Math.sqrt(d*d+f*f+m*m),v=d*p,g=f*p,E=m*p,S=e._TEMPVec3.elements;S[0]=v,S[1]=g,S[2]=E;var D=-(v*r[0]+g*r[1]+E*r[2]);return new e(e._TEMPVec3,D)},e.PlaneIntersectionType_Back=0,e.PlaneIntersectionType_Front=1,e.PlaneIntersectionType_Intersecting=2,i(e,["_TEMPVec3",function(){return this._TEMPVec3=new Vt}]),e}(),Ct=function(){function e(e,t,n,i){this.elements=new Float32Array(4),void 0===e&&(e=0),void 0===t&&(t=0),void 0===n&&(n=0),void 0===i&&(i=1),this.elements[0]=e,this.elements[1]=t,this.elements[2]=n,this.elements[3]=i}r(e,"laya.d3.math.Quaternion");var t=e.prototype;return n.imps(t,{"laya.d3.core.IClone":!0}),t.scaling=function(e,t){var n=t.elements,i=this.elements;n[0]=i[0]*e,n[1]=i[1]*e,n[2]=i[2]*e,n[3]=i[3]*e},t.normalize=function(e){var t=e.elements,n=this.elements,i=n[0],r=n[1],a=n[2],o=n[3],s=i*i+r*r+a*a+o*o;s>0&&(s=1/Math.sqrt(s),t[0]=i*s,t[1]=r*s,t[2]=a*s,t[3]=o*s)},t.length=function(){var e=this.elements,t=e[0],n=e[1],i=e[2],r=e[3];return Math.sqrt(t*t+n*n+i*i+r*r)},t.rotateX=function(e,t){var n=t.elements,i=this.elements;e*=.5;var r=i[0],a=i[1],o=i[2],s=i[3],l=Math.sin(e),h=Math.cos(e);n[0]=r*h+s*l,n[1]=a*h+o*l,n[2]=o*h-a*l,n[3]=s*h-r*l},t.rotateY=function(e,t){var n=t.elements,i=this.elements;e*=.5;var r=i[0],a=i[1],o=i[2],s=i[3],l=Math.sin(e),h=Math.cos(e);n[0]=r*h-o*l,n[1]=a*h+s*l,n[2]=o*h+r*l,n[3]=s*h-a*l},t.rotateZ=function(e,t){var n=t.elements,i=this.elements;e*=.5;var r=i[0],a=i[1],o=i[2],s=i[3],l=Math.sin(e),h=Math.cos(e);n[0]=r*h+a*l,n[1]=a*h-r*l,n[2]=o*h+s*l,n[3]=s*h-o*l},t.getYawPitchRoll=function(t){Vt.transformQuat(Vt.ForwardRH,this,e.TEMPVector31),Vt.transformQuat(Vt.Up,this,e.TEMPVector32);var n=e.TEMPVector32.elements;e.angleTo(Vt.ZERO,e.TEMPVector31,e.TEMPVector33);var i=e.TEMPVector33.elements;i[0]==Math.PI/2?(i[1]=e.arcTanAngle(n[2],n[0]),i[2]=0):i[0]==-Math.PI/2?(i[1]=e.arcTanAngle(-n[2],-n[0]),i[2]=0):(At.createRotationY(-i[1],e.TEMPMatrix0),At.createRotationX(-i[0],e.TEMPMatrix1),Vt.transformCoordinate(e.TEMPVector32,e.TEMPMatrix0,e.TEMPVector32),Vt.transformCoordinate(e.TEMPVector32,e.TEMPMatrix1,e.TEMPVector32),i[2]=e.arcTanAngle(n[1],-n[0])),i[1]<=-Math.PI&&(i[1]=Math.PI),i[2]<=-Math.PI&&(i[2]=Math.PI),i[1]>=Math.PI&&i[2]>=Math.PI&&(i[1]=0,i[2]=0,i[0]=Math.PI-i[0]);var r=t.elements;r[0]=i[1],r[1]=i[0],r[2]=i[2]},t.invert=function(e){var t=e.elements,n=this.elements,i=n[0],r=n[1],a=n[2],o=n[3],s=i*i+r*r+a*a+o*o,l=s?1/s:0;t[0]=-i*l,t[1]=-r*l,t[2]=-a*l,t[3]=o*l},t.identity=function(){var e=this.elements;e[0]=0,e[1]=0,e[2]=0,e[3]=1},t.fromArray=function(e,t){void 0===t&&(t=0),this.elements[0]=e[t+0],this.elements[1]=e[t+1],this.elements[2]=e[t+2],this.elements[3]=e[t+3]},t.cloneTo=function(e){var t,n,i;if(n=this.elements,i=e.elements,n!==i)for(t=0;t<4;++t)i[t]=n[t]},t.clone=function(){var e=new this.constructor;return this.cloneTo(e),e},t.equals=function(e){var t=this.elements,n=e.elements;return Mt.nearEqual(t[0],n[0])&&Mt.nearEqual(t[1],n[1])&&Mt.nearEqual(t[2],n[2])&&Mt.nearEqual(t[3],n[3])},t.lengthSquared=function(){var e=this.elements[0],t=this.elements[1],n=this.elements[2],i=this.elements[3];return e*e+t*t+n*n+i*i},a(0,t,"x",function(){return this.elements[0]}),a(0,t,"y",function(){return this.elements[1]}),a(0,t,"z",function(){return this.elements[2]}),a(0,t,"w",function(){return this.elements[3]}),e.createFromYawPitchRoll=function(e,t,n,i){var r=.5*n,a=.5*t,o=.5*e,s=Math.sin(r),l=Math.cos(r),h=Math.sin(a),_=Math.cos(a),u=Math.sin(o),c=Math.cos(o),d=i.elements;d[0]=c*h*l+u*_*s,d[1]=u*_*l-c*h*s,d[2]=c*_*s-u*h*l,d[3]=c*_*l+u*h*s},e.multiply=function(e,t,n){var i=e.elements,r=t.elements,a=n.elements,o=i[0],s=i[1],l=i[2],h=i[3],_=r[0],u=r[1],c=r[2],d=r[3],f=s*c-l*u,m=l*_-o*c,p=o*u-s*_,v=o*_+s*u+l*c;a[0]=o*d+_*h+f,a[1]=s*d+u*h+m,a[2]=l*d+c*h+p,a[3]=h*d-v},e.arcTanAngle=function(e,t){return 0==e?1==t?Math.PI/2:-Math.PI/2:e>0?Math.atan(t/e):e<0?t>0?Math.atan(t/e)+Math.PI:Math.atan(t/e)-Math.PI:0},e.angleTo=function(t,n,i){Vt.subtract(n,t,e.TEMPVector30),Vt.normalize(e.TEMPVector30,e.TEMPVector30),i.elements[0]=Math.asin(e.TEMPVector30.y),i.elements[1]=e.arcTanAngle(-e.TEMPVector30.z,-e.TEMPVector30.x)},e.createFromAxisAngle=function(e,t,n){var i=n.elements,r=e.elements;t*=.5;var a=Math.sin(t);i[0]=a*r[0],i[1]=a*r[1],i[2]=a*r[2],i[3]=Math.cos(t)},e.createFromMatrix3x3=function(e,t){var n,i=t.elements,r=e.elements,a=r[0]+r[4]+r[8];if(a>0)n=Math.sqrt(a+1),i[3]=.5*n,n=.5/n,i[0]=(r[5]-r[7])*n,i[1]=(r[6]-r[2])*n,i[2]=(r[1]-r[3])*n;else{var o=0;r[4]>r[0]&&(o=1),r[8]>r[3*o+o]&&(o=2);var s=(o+1)%3,l=(o+2)%3;n=Math.sqrt(r[3*o+o]-r[3*s+s]-r[3*l+l]+1),i[o]=.5*n,n=.5/n,i[3]=(r[3*s+l]-r[3*l+s])*n,i[s]=(r[3*s+o]+r[3*o+s])*n,i[l]=(r[3*l+o]+r[3*o+l])*n}},e.createFromMatrix4x4=function(e,t){var n,i,r=e.elements,a=t.elements,o=r[0]+r[5]+r[10];o>0?(n=Math.sqrt(o+1),a[3]=.5*n,n=.5/n,a[0]=(r[6]-r[9])*n,a[1]=(r[8]-r[2])*n,a[2]=(r[1]-r[4])*n):r[0]>=r[5]&&r[0]>=r[10]?(i=.5/(n=Math.sqrt(1+r[0]-r[5]-r[10])),a[0]=.5*n,a[1]=(r[1]+r[4])*i,a[2]=(r[2]+r[8])*i,a[3]=(r[6]-r[9])*i):r[5]>r[10]?(i=.5/(n=Math.sqrt(1+r[5]-r[0]-r[10])),a[0]=(r[4]+r[1])*i,a[1]=.5*n,a[2]=(r[9]+r[6])*i,a[3]=(r[8]-r[2])*i):(i=.5/(n=Math.sqrt(1+r[10]-r[0]-r[5])),a[0]=(r[8]+r[2])*i,a[1]=(r[9]+r[6])*i,a[2]=.5*n,a[3]=(r[1]-r[4])*i)},e.slerp=function(e,t,n,i){var r,a,o,s,l,h=e.elements,_=t.elements,u=i.elements,c=h[0],d=h[1],f=h[2],m=h[3],p=_[0],v=_[1],g=_[2],E=_[3];return(a=c*p+d*v+f*g+m*E)<0&&(a=-a,p=-p,v=-v,g=-g,E=-E),1-a>1e-6?(r=Math.acos(a),o=Math.sin(r),s=Math.sin((1-n)*r)/o,l=Math.sin(n*r)/o):(s=1-n,l=n),u[0]=s*c+l*p,u[1]=s*d+l*v,u[2]=s*f+l*g,u[3]=s*m+l*E,u},e.lerp=function(e,t,n,i){var r=i.elements,a=e.elements,o=t.elements,s=a[0],l=a[1],h=a[2],_=a[3];r[0]=s+n*(o[0]-s),r[1]=l+n*(o[1]-l),r[2]=h+n*(o[2]-h),r[3]=_+n*(o[3]-_)},e.add=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements;i[0]=r[0]+a[0],i[1]=r[1]+a[1],i[2]=r[2]+a[2],i[3]=r[3]+a[3]},e.dot=function(e,t){var n=e.elements,i=t.elements;return n[0]*i[0]+n[1]*i[1]+n[2]*i[2]+n[3]*i[3]},e.rotationLookAt=function(t,n,i){e.lookAt(Vt.ZERO,t,n,i)},e.lookAt=function(t,n,i,r){Rt.lookAt(t,n,i,e._tempMatrix3x3),e.rotationMatrix(e._tempMatrix3x3,r)},e.invert=function(e,t){var n=e.elements,i=t.elements,r=e.lengthSquared();Mt.isZero(r)||(r=1/r,i[0]=-n[0]*r,i[1]=-n[1]*r,i[2]=-n[2]*r,i[3]=n[3]*r)},e.rotationMatrix=function(e,t){var n=e.elements,i=n[0],r=n[1],a=n[2],o=n[3],s=n[4],l=n[5],h=n[6],_=n[7],u=n[8],c=t.elements,d=NaN,f=NaN,m=i+s+u;m>0?(d=Math.sqrt(m+1),c[3]=.5*d,d=.5/d,c[0]=(l-_)*d,c[1]=(h-a)*d,c[2]=(r-o)*d):i>=s&&i>=u?(f=.5/(d=Math.sqrt(1+i-s-u)),c[0]=.5*d,c[1]=(r+o)*f,c[2]=(a+h)*f,c[3]=(l-_)*f):s>u?(f=.5/(d=Math.sqrt(1+s-i-u)),c[0]=(o+r)*f,c[1]=.5*d,c[2]=(_+l)*f,c[3]=(h-a)*f):(f=.5/(d=Math.sqrt(1+u-i-s)),c[0]=(h+a)*f,c[1]=(_+l)*f,c[2]=.5*d,c[3]=(r-o)*f)},e.DEFAULT=new e,i(e,["TEMPVector30",function(){return this.TEMPVector30=new Vt},"TEMPVector31",function(){return this.TEMPVector31=new Vt},"TEMPVector32",function(){return this.TEMPVector32=new Vt},"TEMPVector33",function(){return this.TEMPVector33=new Vt},"TEMPMatrix0",function(){return this.TEMPMatrix0=new At},"TEMPMatrix1",function(){return this.TEMPMatrix1=new At},"_tempMatrix3x3",function(){return this._tempMatrix3x3=new Rt},"NAN",function(){return this.NAN=new e(NaN,NaN,NaN,NaN)}]),e}(),Nt=function(){function e(e){this._temp=new Uint32Array(1),this.seeds=new Uint32Array(4),this.seeds[0]=e,this.seeds[1]=1812433253*this.seeds[0]+1,this.seeds[2]=1812433253*this.seeds[1]+1,this.seeds[3]=1812433253*this.seeds[2]+1}r(e,"laya.d3.math.Rand");var t=e.prototype;return t.getUint=function(){return this._temp[0]=this.seeds[0]^this.seeds[0]<<11,this.seeds[0]=this.seeds[1],this.seeds[1]=this.seeds[2],this.seeds[2]=this.seeds[3],this.seeds[3]=this.seeds[3]^this.seeds[3]>>>19^this._temp[0]^this._temp[0]>>>8,this.seeds[3]},t.getFloat=function(){return this.getUint(),(8388607&this.seeds[3])*(1/8388607)},t.getSignedFloat=function(){return 2*this.getFloat()-1},a(0,t,"seed",function(){return this.seeds[0]},function(e){this.seeds[0]=e,this.seeds[1]=1812433253*this.seeds[0]+1,this.seeds[2]=1812433253*this.seeds[1]+1,this.seeds[3]=1812433253*this.seeds[2]+1}),e.getFloatFromInt=function(e){return 1/8388607*(8388607&e)},e.getByteFromInt=function(e){return(8388607&e)>>>15},e}(),wt=(function(){function e(e){if(this._state0U=NaN,this._state0L=NaN,this._state1U=NaN,this._state1L=NaN,!(e instanceof Array)||4!==e.length)throw new Error("Rand:Seed must be an array with 4 numbers");this._state0U=0|e[0],this._state0L=0|e[1],this._state1U=0|e[2],this._state1L=0|e[3]}r(e,"laya.d3.math.RandX");var t=e.prototype;t.randomint=function(){var e=this._state0U,t=this._state0L,n=this._state1U,i=this._state1L,r=(i>>>0)+(t>>>0),a=n+e+(r/2>>>31)>>>0,o=r>>>0;this._state0U=n,this._state0L=i;var s=0,l=0,h=0,_=0;s=(e^=s=e<<23|(-512&t)>>>9)^n,l=(t^=l=t<<23)^i;s^=h=e>>>18,l^=_=t>>>18|(262143&e)<<14;return h=n>>>5,_=i>>>5|(31&n)<<27,s^=h,l^=_,this._state1U=s,this._state1L=l,[a,o]},t.random=function(){var t=this.randomint(),n=t[0],i=1023<<20|n>>>12,r=0|(t[1]>>>12|(4095&n)<<20);e._CONVERTION_BUFFER.setUint32(0,i,!1),e._CONVERTION_BUFFER.setUint32(4,r,!1);return Nt._CONVERTION_BUFFER.getFloat64(0,!1)-1},i(e,["_CONVERTION_BUFFER",function(){return this._CONVERTION_BUFFER=new DataView(new ArrayBuffer(8))},"defaultRand",function(){return this.defaultRand=new Nt([0,Date.now()/65536,0,Date.now()%65536])}])}(),function(){function e(e,t){this.origin=null,this.direction=null,this.origin=e,this.direction=t}return r(e,"laya.d3.math.Ray"),e}()),Ot=function(){function e(e,t){this.elements=new Float32Array(2),void 0===e&&(e=0),void 0===t&&(t=0);var n=this.elements;n[0]=e,n[1]=t}r(e,"laya.d3.math.Vector2");var t=e.prototype;return n.imps(t,{"laya.d3.core.IClone":!0}),t.fromArray=function(e,t){void 0===t&&(t=0),this.elements[0]=e[t+0],this.elements[1]=e[t+1]},t.cloneTo=function(e){var t=e.elements,n=this.elements;t[0]=n[0],t[1]=n[1]},t.clone=function(){var e=new this.constructor;return this.cloneTo(e),e},a(0,t,"x",function(){return this.elements[0]},function(e){this.elements[0]=e}),a(0,t,"y",function(){return this.elements[1]},function(e){this.elements[1]=e}),e.scale=function(e,t,n){var i=n.elements,r=e.elements;i[0]=r[0]*t,i[1]=r[1]*t},i(e,["ZERO",function(){return this.ZERO=new e(0,0)},"ONE",function(){return this.ONE=new e(1,1)}]),e}(),Vt=function(){function e(e,t,n){this.elements=new Float32Array(3),void 0===e&&(e=0),void 0===t&&(t=0),void 0===n&&(n=0);var i=this.elements;i[0]=e,i[1]=t,i[2]=n}r(e,"laya.d3.math.Vector3");var t=e.prototype;return n.imps(t,{"laya.d3.core.IClone":!0}),t.fromArray=function(e,t){void 0===t&&(t=0),this.elements[0]=e[t+0],this.elements[1]=e[t+1],this.elements[2]=e[t+2]},t.cloneTo=function(e){var t=e.elements,n=this.elements;t[0]=n[0],t[1]=n[1],t[2]=n[2]},t.clone=function(){var e=new this.constructor;return this.cloneTo(e),e},t.toDefault=function(){this.elements[0]=0,this.elements[1]=0,this.elements[2]=0},a(0,t,"x",function(){return this.elements[0]},function(e){this.elements[0]=e}),a(0,t,"y",function(){return this.elements[1]},function(e){this.elements[1]=e}),a(0,t,"z",function(){return this.elements[2]},function(e){this.elements[2]=e}),e.distanceSquared=function(e,t){var n=e.elements,i=t.elements,r=n[0]-i[0],a=n[1]-i[1],o=n[2]-i[2];return r*r+a*a+o*o},e.distance=function(e,t){var n=e.elements,i=t.elements,r=n[0]-i[0],a=n[1]-i[1],o=n[2]-i[2];return Math.sqrt(r*r+a*a+o*o)},e.min=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements;i[0]=Math.min(r[0],a[0]),i[1]=Math.min(r[1],a[1]),i[2]=Math.min(r[2],a[2])},e.max=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements;i[0]=Math.max(r[0],a[0]),i[1]=Math.max(r[1],a[1]),i[2]=Math.max(r[2],a[2])},e.transformQuat=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements,o=r[0],s=r[1],l=r[2],h=a[0],_=a[1],u=a[2],c=a[3],d=c*o+_*l-u*s,f=c*s+u*o-h*l,m=c*l+h*s-_*o,p=-h*o-_*s-u*l;i[0]=d*c+p*-h+f*-u-m*-_,i[1]=f*c+p*-_+m*-h-d*-u,i[2]=m*c+p*-u+d*-_-f*-h},e.scalarLength=function(e){var t=e.elements,n=t[0],i=t[1],r=t[2];return Math.sqrt(n*n+i*i+r*r)},e.scalarLengthSquared=function(e){var t=e.elements,n=t[0],i=t[1],r=t[2];return n*n+i*i+r*r},e.normalize=function(e,t){var n=e.elements,i=t.elements,r=n[0],a=n[1],o=n[2],s=r*r+a*a+o*o;s>0&&(s=1/Math.sqrt(s),i[0]=n[0]*s,i[1]=n[1]*s,i[2]=n[2]*s)},e.multiply=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements;i[0]=r[0]*a[0],i[1]=r[1]*a[1],i[2]=r[2]*a[2]},e.scale=function(e,t,n){var i=n.elements,r=e.elements;i[0]=r[0]*t,i[1]=r[1]*t,i[2]=r[2]*t},e.lerp=function(e,t,n,i){var r=i.elements,a=e.elements,o=t.elements,s=a[0],l=a[1],h=a[2];r[0]=s+n*(o[0]-s),r[1]=l+n*(o[1]-l),r[2]=h+n*(o[2]-h)},e.transformV3ToV3=function(t,n,i){var r=e._tempVector4;e.transformV3ToV4(t,n,r);var a=r.elements,o=i.elements;o[0]=a[0],o[1]=a[1],o[2]=a[2]},e.transformV3ToV4=function(e,t,n){var i=e.elements,r=i[0],a=i[1],o=i[2],s=t.elements,l=n.elements;l[0]=r*s[0]+a*s[4]+o*s[8]+s[12],l[1]=r*s[1]+a*s[5]+o*s[9]+s[13],l[2]=r*s[2]+a*s[6]+o*s[10]+s[14],l[3]=r*s[3]+a*s[7]+o*s[11]+s[15]},e.TransformNormal=function(e,t,n){var i=e.elements,r=i[0],a=i[1],o=i[2],s=t.elements,l=n.elements;l[0]=r*s[0]+a*s[4]+o*s[8],l[1]=r*s[1]+a*s[5]+o*s[9],l[2]=r*s[2]+a*s[6]+o*s[10]},e.transformCoordinate=function(t,n,i){var r=e._tempVector4.elements,a=t.elements,o=a[0],s=a[1],l=a[2],h=n.elements;r[0]=o*h[0]+s*h[4]+l*h[8]+h[12],r[1]=o*h[1]+s*h[5]+l*h[9]+h[13],r[2]=o*h[2]+s*h[6]+l*h[10]+h[14],r[3]=1/(o*h[3]+s*h[7]+l*h[11]+h[15]);var _=i.elements;_[0]=r[0]*r[3],_[1]=r[1]*r[3],_[2]=r[2]*r[3]},e.Clamp=function(e,t,n,i){var r=e.elements,a=r[0],o=r[1],s=r[2],l=t.elements,h=l[0],_=l[1],u=l[2],c=n.elements,d=c[0],f=c[1],m=c[2],p=i.elements;a=(a=a>d?d:a)f?f:o)<_?_:o,s=(s=s>m?m:s)0&&(i[0]=n[0]*r,i[1]=n[1]*r,i[2]=n[2]*r,i[3]=n[3]*r)},e.add=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements;i[0]=r[0]+a[0],i[1]=r[1]+a[1],i[2]=r[2]+a[2],i[3]=r[3]+a[3]},e.subtract=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements;i[0]=r[0]-a[0],i[1]=r[1]-a[1],i[2]=r[2]-a[2],i[3]=r[3]-a[3]},e.multiply=function(e,t,n){var i=n.elements,r=e.elements,a=t.elements;i[0]=r[0]*a[0],i[1]=r[1]*a[1],i[2]=r[2]*a[2],i[3]=r[3]*a[3]},e.scale=function(e,t,n){var i=n.elements,r=e.elements;i[0]=r[0]*t,i[1]=r[1]*t,i[2]=r[2]*t,i[3]=r[3]*t},e.Clamp=function(e,t,n,i){var r=e.elements,a=r[0],o=r[1],s=r[2],l=r[3],h=t.elements,_=h[0],u=h[1],c=h[2],d=h[3],f=n.elements,m=f[0],p=f[1],v=f[2],g=f[3],E=i.elements;a=(a=a>m?m:a)<_?_:a,o=(o=o>p?p:o)v?v:s)g?g:l)1&&(this._alphaBlending=1)}),a(0,t,"envDiffuseSHBlue",null,function(e){this.__ownerCamera._shaderValues.setValue(12,e)}),a(0,t,"colorIntensity",function(){return this._colorIntensity},function(e){this._colorIntensity=e,this._colorIntensity<0&&(this._colorIntensity=0)}),a(0,t,"envDiffuseSHGreen",null,function(e){this.__ownerCamera._shaderValues.setValue(11,e)}),a(0,t,"envDiffuseSHRed",null,function(e){this.__ownerCamera._shaderValues.setValue(10,e)}),a(0,t,"environmentDiffuse",function(){return this._environmentDiffuse},function(e){e.minFifter=9728,this._environmentDiffuse=e,this.__ownerCamera&&this._setEnvironmentDiffuse()}),a(0,t,"environmentSpecular",function(){return this._environmentSpecular},function(e){this._environmentSpecular=e,this.__ownerCamera&&this._setEnvironmentSpecular()}),e.MVPMATRIX=0,e.INTENSITY=1,e.ALPHABLENDING=2,e.DIFFUSETEXTURE=3,e}(),Ft=function(){function e(e){this._mesh=null,this._boneIndicesList=null,this._subIndexBufferStart=null,this._subIndexBufferCount=null,this._skinAnimationDatas=null,this._bufferUsage=null,this._indexInMesh=0,this._vertexBuffer=null,this._vertexStart=0,this._vertexCount=0,this._indexBuffer=null,this._indexStart=0,this._indexCount=0,this._indices=null,this._bufferUsage={},this._mesh=e,this._boneIndicesList=[],this._subIndexBufferStart=[],this._subIndexBufferCount=[]}r(e,"laya.d3.resource.models.SubMesh");var t=e.prototype;return n.imps(t,{"laya.d3.core.render.IRenderable":!0,"laya.resource.IDispose":!0}),t._getVertexBuffer=function(e){return void 0===e&&(e=0),0===e?this._vertexBuffer:null},t._getIndexBuffer=function(){return this._indexBuffer},t._getStaticBatchBakedVertexs=function(t,n){var i,r,a=this._vertexBuffer,o=a.vertexDeclaration,s=o.getVertexElementByUsage(0).offset/4,l=o.getVertexElementByUsage(3).offset/4,h=n.meshRender.lightmapScaleOffset,_=0,u=0,c=0,d=0,f=0,m=0;if(h)if(r=o.getVertexElementByUsage(15))c=o.vertexStride/4,i=this._vertexCount>0?a.getData().slice(this._vertexStart*c,(this._vertexStart+this._vertexCount)*c):a.getData().slice(),d=r.offset/4;else{c=(m=o.vertexStride/4)+2,i=this._vertexCount?new Float32Array(this._vertexCount*(a.vertexDeclaration.vertexStride/4+2)):new Float32Array(a.vertexCount*(a.vertexDeclaration.vertexStride/4+2)),d=(f=o.getVertexElementByUsage(2).offset/4)+2;var p=a.getData();for(_=0,u=p.length/m;_0?(this._vertexStart+_)*m:_*m;var g=_*c,E=0;for(E=0;E1){var r=this._boneIndicesList.length;if(r>1){for(var a=0;a0?this._indices:this._indexBuffer.getData()},t.dispose=function(){this._indexBuffer.destroy(),this._vertexBuffer.destroy(),this._mesh=null,this._boneIndicesList=null,this._subIndexBufferStart=null,this._subIndexBufferCount=null,this._skinAnimationDatas=null,this._bufferUsage=null,this._vertexBuffer=null,this._indexBuffer=null},a(0,t,"_vertexBufferCount",function(){return 1}),a(0,t,"triangleCount",function(){return this._indexBuffer.indexCount/3}),i(e,["_tempVector30",function(){return this._tempVector30=new Vt},"_tempVector31",function(){return this._tempVector31=new Vt},"_tempQuaternion0",function(){return this._tempQuaternion0=new Ct},"_tempMatrix4x40",function(){return this._tempMatrix4x40=new At},"_tempMatrix4x41",function(){return this._tempMatrix4x41=new At}]),e}(),Bt=function(){function e(e){this.defineCounter=0,this.defines=null,e?(this.defineCounter=e.defineCounter,this.defines=e.defines.slice()):(this.defineCounter=0,this.defines=[])}r(e,"laya.d3.shader.ShaderDefines",null,"ShaderDefines$1");return e.prototype.registerDefine=function(e){var t=Math.pow(2,this.defineCounter++);return this.defines[t]=e,t},e}(),Ut=function(){function e(){}return r(e,"laya.d3.shader.ShaderInit3D"),e.__init__=function(){un._globalRegDefine("HIGHPRECISION",un.SHADERDEFINE_HIGHPRECISION),un._globalRegDefine("FOG",un.SHADERDEFINE_FOG),un._globalRegDefine("DIRECTIONLIGHT",un.SHADERDEFINE_DIRECTIONLIGHT),un._globalRegDefine("POINTLIGHT",un.SHADERDEFINE_POINTLIGHT),un._globalRegDefine("SPOTLIGHT",un.SHADERDEFINE_SPOTLIGHT),un._globalRegDefine("UV",un.SHADERDEFINE_UV0),un._globalRegDefine("COLOR",un.SHADERDEFINE_COLOR),un._globalRegDefine("UV1",un.SHADERDEFINE_UV1),un._globalRegDefine("CASTSHADOW",Gt.SHADERDEFINE_CAST_SHADOW),un._globalRegDefine("SHADOWMAP_PSSM1",Gt.SHADERDEFINE_SHADOW_PSSM1),un._globalRegDefine("SHADOWMAP_PSSM2",Gt.SHADERDEFINE_SHADOW_PSSM2),un._globalRegDefine("SHADOWMAP_PSSM3",Gt.SHADERDEFINE_SHADOW_PSSM3),un._globalRegDefine("SHADOWMAP_PCF_NO",Gt.SHADERDEFINE_SHADOW_PCF_NO),un._globalRegDefine("SHADOWMAP_PCF1",Gt.SHADERDEFINE_SHADOW_PCF1),un._globalRegDefine("SHADOWMAP_PCF2",Gt.SHADERDEFINE_SHADOW_PCF2),un._globalRegDefine("SHADOWMAP_PCF3",Gt.SHADERDEFINE_SHADOW_PCF3),un._globalRegDefine("DEPTHFOG",un.SAHDERDEFINE_DEPTHFOG),Bn.addInclude("LightHelper.glsl","\nstruct DirectionLight\n{\n vec3 Direction;\n vec3 Diffuse;\n};\n\nstruct PointLight\n{\n vec3 Diffuse;\n vec3 Attenuation;\n vec3 Position;\n float Range;\n};\n\nstruct SpotLight\n{\n vec3 Diffuse;\n vec3 Attenuation;\n vec3 Position;\n vec3 Direction;\n float Spot;\n float Range;\n};\n\n\nvec3 NormalSampleToWorldSpace(vec3 normalMapSample, vec3 unitNormal, vec3 tangent)\n{\n\tvec3 normalT = 2.0*normalMapSample - 1.0;\n\n\t// Build orthonormal basis.\n\tvec3 N = normalize(unitNormal);\n\tvec3 T = normalize(tangent- dot(tangent, N)*N);\n\tvec3 B = cross(T, N);\n\n\tmat3 TBN = mat3(T, B, N);\n\n\t// Transform from tangent space to world space.\n\tvec3 bumpedNormal = TBN*normalT;\n\n\treturn bumpedNormal;\n}\n\n\nvoid computeDirectionLight(in vec3 matDif,in vec3 matAmb,in vec4 matSpe,in DirectionLight dirLight,in vec3 ambinentColor,in vec3 normal,in vec3 toEye,out vec3 dif,out vec3 amb,out vec3 spec)\n{\n\tdif=vec3(0.0);//不初始化在IOS中闪烁,PC中不会闪烁\n\tamb=vec3(0.0);\n\tspec=vec3(0.0);\n\tvec3 lightVec=-normalize(dirLight.Direction);\n\t\n\tamb=matAmb*ambinentColor;\n\t\n\tfloat diffuseFactor=dot(lightVec, normal);\n\t\n\tif(diffuseFactor>0.0)\n\t{\n\t vec3 v = reflect(-lightVec, normal);\n\t float specFactor = pow(max(dot(v, toEye), 0.0), matSpe.w);\n\t \n\t dif = diffuseFactor * matDif * dirLight.Diffuse;\n\t spec = specFactor * matSpe.rgb;\n\t}\n\t\n}\n\nvoid computePointLight(in vec3 matDif,in vec3 matAmb,in vec4 matSpe,in PointLight poiLight,in vec3 ambinentColor, in vec3 pos,in vec3 normal,in vec3 toEye,out vec3 dif,out vec3 amb,out vec3 spec)\n{\n\tdif=vec3(0.0);\n\tamb=vec3(0.0);\n\tspec=vec3(0.0);\n\tvec3 lightVec = poiLight.Position - pos;\n\t\t\n\tfloat d = length(lightVec);\n\t\n\tif( d > poiLight.Range )\n\t\treturn;\n\t\t\n\tlightVec /= d; \n\t\n\tamb = matAmb*ambinentColor;\t\n\n\tfloat diffuseFactor = dot(lightVec, normal);\n\n\tif( diffuseFactor > 0.0 )\n\t{\n\t\tvec3 v= reflect(-lightVec, normal);\n\t\tfloat specFactor = pow(max(dot(v, toEye), 0.0), matSpe.w);\n\t\t\t\t\t\n\t\tdif = diffuseFactor * matDif * poiLight.Diffuse;\n\t\tspec = specFactor * matSpe.rgb;\n\t}\n\n\tfloat attenuate = 1.0 / dot(poiLight.Attenuation, vec3(1.0, d, d*d));\n\n\tdif *= attenuate;\n\tspec*= attenuate;\n}\n\nvoid ComputeSpotLight(in vec3 matDif,in vec3 matAmb,in vec4 matSpe,in SpotLight spoLight,in vec3 ambinentColor,in vec3 pos, in vec3 normal,in vec3 toEye,out vec3 dif,out vec3 amb,out vec3 spec)\n{\n\tamb = vec3(0.0);\n\tdif =vec3(0.0);\n\tspec= vec3(0.0);\n\tvec3 lightVec = spoLight.Position - pos;\n\t\t\n\tfloat d = length(lightVec);\n\t\n\tif( d > spoLight.Range)\n\t\treturn;\n\t\t\n\tlightVec /= d; \n\t\n\tamb = matAmb*ambinentColor;\t\n\n\tfloat diffuseFactor = dot(lightVec, normal);\n\n\tif(diffuseFactor > 0.0)\n\t{\n\t\tvec3 v= reflect(-lightVec, normal);\n\t\tfloat specFactor = pow(max(dot(v, toEye), 0.0), matSpe.w);\n\t\t\t\t\t\n\t\tdif = diffuseFactor * matDif * spoLight.Diffuse;\n\t\tspec = specFactor * matSpe.rgb;\n\t}\n\t\n\tfloat spot = pow(max(dot(-lightVec, normalize(spoLight.Direction)), 0.0), spoLight.Spot);\n\n\tfloat attenuate = spot/dot(spoLight.Attenuation, vec3(1.0, d, d*d));\n\n\tamb *= spot;\n\tdif *= attenuate;\n\tspec*= attenuate;\n}\n\n"),Bn.addInclude("Lighting.glsl","\nstruct DirectionLight\n{\n\tvec3 Color;\n\tvec3 Direction;\n};\n\nstruct PointLight\n{\n\tvec3 Color;\n\tvec3 Position;\n\tfloat Range;\n};\n\nstruct SpotLight\n{\n\tvec3 Color;\n\tvec3 Position;\n\tvec3 Direction;\n\tfloat Spot;\n\tfloat Range;\n};\n\n// U3D中使用衰减纹理,此函数模拟并非正确\n//float U3DAttenuation(in vec3 L,in float invLightRadius)\n//{\n//\tfloat fRatio = clamp(length(L) * invLightRadius,0.0,1.0);\n//\tfRatio *= fRatio;\n//\treturn 1.0 / (1.0 + 25.0 * fRatio)* clamp(4.0*(1.0 - fRatio),0.0,1.0); //fade to black as if 4 pixel texture\n//} \n\n// Same as Just Cause 2 and Crysis 2 (you can read GPU Pro 1 book for more information)\nfloat BasicAttenuation(in vec3 L,in float invLightRadius)\n{\n\tvec3 distance = L * invLightRadius;\n\tfloat attenuation = clamp(1.0 - dot(distance, distance),0.0,1.0); // Equals float attenuation = saturate(1.0f - dot(L, L) / (lightRadius * lightRadius)); \t\n\treturn attenuation * attenuation;\n} \n\n// Inspired on http://fools.slindev.com/viewtopic.php?f=11&t=21&view=unread#unread\t\nfloat NaturalAttenuation(in vec3 L,in float invLightRadius)\n{\n\tfloat attenuationFactor = 30.0;\n\tvec3 distance = L * invLightRadius;\n\tfloat attenuation = dot(distance, distance); // Equals float attenuation = dot(L, L) / (lightRadius * lightRadius);\n\tattenuation = 1.0 / (attenuation * attenuationFactor + 1.0);\n\t// Second we move down the function therewith it reaches zero at abscissa 1:\n\tattenuationFactor = 1.0 / (attenuationFactor + 1.0); //attenuationFactor contains now the value we have to subtract\n\tattenuation = max(attenuation - attenuationFactor, 0.0); // The max fixes a bug.\n\t// Finally we expand the equation along the y-axis so that it starts with a function value of 1 again.\n\tattenuation /= 1.0 - attenuationFactor;\n\treturn attenuation;\n} \n\nvoid LayaAirBlinnPhongLight (in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir,in vec3 lightColor, in vec3 lightVec,out vec3 diffuseColor,out vec3 specularColor)\n{\n mediump vec3 h = normalize(viewDir-lightVec);\n lowp float ln = max (0.0, dot (-lightVec,normal));\n float nh = max (0.0, dot (h,normal));\n\tdiffuseColor=lightColor * ln;\n\tspecularColor=lightColor *specColor*pow (nh, specColorIntensity*128.0) * gloss;\n}\n\nvoid LayaAirBlinnPhongDiectionLight (in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in DirectionLight light,out vec3 diffuseColor,out vec3 specularColor)\n{\n\tvec3 lightVec=normalize(light.Direction);\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,lightVec,diffuseColor,specularColor);\n}\n\nvoid LayaAirBlinnPhongPointLight (in vec3 pos,in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in PointLight light,out vec3 diffuseColor,out vec3 specularColor)\n{\n\tvec3 lightVec = pos-light.Position;\n\t//if( length(lightVec) > light.Range )\n\t//\treturn;\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,lightVec/length(lightVec),diffuseColor,specularColor);\n\tfloat attenuate = BasicAttenuation(lightVec, 1.0/light.Range);\n\tdiffuseColor *= attenuate;\n\tspecularColor*= attenuate;\n}\n\nvoid LayaAirBlinnPhongSpotLight (in vec3 pos,in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in SpotLight light,out vec3 diffuseColor,out vec3 specularColor)\n{\n\tvec3 lightVec = pos-light.Position;\n\t//if( length(lightVec) > light.Range )\n\t//\treturn;\n\tvec3 normalLightVec=lightVec/length(lightVec);\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,normalLightVec,diffuseColor,specularColor);\n\tfloat spot = pow(max(dot(normalLightVec, normalize(light.Direction)), 0.0), light.Spot);\n\tfloat attenuate = spot*BasicAttenuation(lightVec, 1.0/light.Range);\n\tdiffuseColor *= attenuate;\n\tspecularColor*= attenuate;\n}\n\nvec3 NormalSampleToWorldSpace(vec3 normalMapSample, vec3 unitNormal, vec3 tangent,vec3 binormal)\n{\n\tvec3 normalT =vec3(2.0*normalMapSample.x - 1.0,1.0-2.0*normalMapSample.y,2.0*normalMapSample.z - 1.0);\n\t\n\t// Build orthonormal basis.\n\tvec3 N = normalize(unitNormal);\n\tvec3 T = normalize(tangent);\n\tvec3 B = normalize(binormal);\n\tmat3 TBN = mat3(T, B, N);\n\t\n\t// Transform from tangent space to world space.\n\tvec3 bumpedNormal = TBN*normalT;\n\n\treturn bumpedNormal;\n}\n\n\n"),Bn.addInclude("ShadowHelper.glsl","uniform sampler2D u_shadowMap1;\nuniform sampler2D u_shadowMap2;\nuniform sampler2D u_shadowMap3;\nuniform vec2\t u_shadowPCFoffset;\nuniform vec4 u_shadowPSSMDistance;\nvec4 packDepth(const in float depth)\n{\n\tconst vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n\tconst vec4 bitMask\t= vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n\tvec4 res = mod(depth*bitShift*vec4(255), vec4(256))/vec4(255);\n\tres -= res.xxyz * bitMask;\n\treturn res;\n}\nfloat unpackDepth(const in vec4 rgbaDepth)\n{\n\tconst vec4 bitShift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n\tfloat depth = dot(rgbaDepth, bitShift);\n\treturn depth;\n}\nfloat tex2DPCF( sampler2D shadowMap,vec2 texcoord,vec2 invsize,float zRef )\n{\n\tvec2 texelpos =texcoord / invsize;\n\tvec2 lerps = fract( texelpos );\n\tfloat sourcevals[4];\n\tsourcevals[0] = float( unpackDepth(texture2D(shadowMap,texcoord)) > zRef );\n\tsourcevals[1] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(invsize.x,0))) > zRef );\n\tsourcevals[2] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(0,invsize.y))) > zRef );\n\tsourcevals[3] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(invsize.x, invsize.y) )) > zRef );\n\treturn mix( mix(sourcevals[0],sourcevals[2],lerps.y),mix(sourcevals[1],sourcevals[3],lerps.y),lerps.x );\n}\nfloat getShadowPSSM3( sampler2D shadowMap1,sampler2D shadowMap2,sampler2D shadowMap3,mat4 lightShadowVP[4],vec4 pssmDistance,vec2 shadowPCFOffset,vec3 worldPos,float posViewZ,float zBias )\n{\n\tfloat value = 1.0;\n\tint nPSNum = int(posViewZ>pssmDistance.x);\n\tnPSNum += int(posViewZ>pssmDistance.y);\n\tnPSNum += int(posViewZ>pssmDistance.z);\n\t//真SB,webgl不支持在PS中直接访问数组\n\tmat4 lightVP;\n\tif( nPSNum == 0 )\n\t{\n\t\tlightVP = lightShadowVP[1];\n\t}\n\telse if( nPSNum == 1 )\n\t{\n\t\tlightVP = lightShadowVP[2];\n\t}\n\telse if( nPSNum == 2 )\n\t{\n\t\tlightVP = lightShadowVP[3];\n\t}\n\tvec4 vLightMVPPos = lightVP * vec4(worldPos,1.0);\n\t//为了效率,在CPU计算/2.0 + 0.5\n\t//vec3 vText = (vLightMVPPos.xyz / vLightMVPPos.w)/2.0 + 0.5;\n\tvec3 vText = vLightMVPPos.xyz / vLightMVPPos.w;\n\tfloat fMyZ = vText.z - zBias;\n\t/*\n\tbvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\n\tbool bInFrustum = all( bInFrustumVec );\n\tbvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\n\tbool bFrustumTest = all( bFrustumTestVec );\n\tif ( bFrustumTest ) \n\t*/\n\tif( fMyZ <= 1.0 )\n\t{\n\t\tfloat zdepth=0.0;\n#ifdef SHADOWMAP_PCF3\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset,\tfMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset,\tfMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset,\tfMyZ );\n\t\t\tvalue = value/4.0;\n\t\t} \n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n\t\telse if( nPSNum == 2 )\n\t\t{\n\t\t\tvec4 color = texture2D( shadowMap3,vText.xy );\n\t\t\tzdepth = unpackDepth(color);\n\t\t\tvalue = float(fMyZ < zdepth);\n\t\t}\n#endif\n#ifdef SHADOWMAP_PCF2\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n\t\telse if( nPSNum == 2 )\n\t\t{\n\t\t\tvec4 color = texture2D( shadowMap3,vText.xy );\n\t\t\tzdepth = unpackDepth(color);\n\t\t\tvalue = float(fMyZ < zdepth);\n\t\t}\n\n#endif\n#ifdef SHADOWMAP_PCF1\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tvec4 color = texture2D( shadowMap2,vText.xy );\n\t\t\tzdepth = unpackDepth(color);\n\t\t\tvalue = float(fMyZ < zdepth);\n\t\t}\n\t\telse if( nPSNum == 2 )\n\t\t{\n\t\t\tvec4 color = texture2D( shadowMap3,vText.xy );\n\t\t\tzdepth = unpackDepth(color);\n\t\t\tvalue = float(fMyZ < zdepth);\n\t\t}\n#endif\n#ifdef SHADOWMAP_PCF_NO\n\t\tvec4 color;\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tcolor = texture2D( shadowMap1,vText.xy );\n\t\t}\n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tcolor = texture2D( shadowMap2,vText.xy );\n\t\t}\n\t\telse if( nPSNum == 2 )\n\t\t{\n\t\t\tcolor = texture2D( shadowMap3,vText.xy );\n\t\t}\n\t\tzdepth = unpackDepth(color);\n\t\tvalue = float(fMyZ < zdepth);\n#endif\n\t}\n\treturn value;\n}\nfloat getShadowPSSM2( sampler2D shadowMap1,sampler2D shadowMap2,mat4 lightShadowVP[4],vec4 pssmDistance,vec2 shadowPCFOffset,vec3 worldPos,float posViewZ,float zBias )\n{\n\tfloat value = 1.0;\n\tint nPSNum = int(posViewZ>pssmDistance.x);\n\tnPSNum += int(posViewZ>pssmDistance.y);\n\t//真SB,webgl不支持在PS中直接访问数组\n\tmat4 lightVP;\n\tif( nPSNum == 0 )\n\t{\n\t\tlightVP = lightShadowVP[1];\n\t}\n\telse if( nPSNum == 1 )\n\t{\n\t\tlightVP = lightShadowVP[2];\n\t}\n\tvec4 vLightMVPPos = lightVP * vec4(worldPos,1.0);\n\t//为了效率,在CPU计算/2.0 + 0.5\n\t//vec3 vText = (vLightMVPPos.xyz / vLightMVPPos.w)/2.0 + 0.5;\n\tvec3 vText = vLightMVPPos.xyz / vLightMVPPos.w;\n\tfloat fMyZ = vText.z - zBias;\n\t/*\n\tbvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\n\tbool bInFrustum = all( bInFrustumVec );\n\tbvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\n\tbool bFrustumTest = all( bFrustumTestVec );\n\tif ( bFrustumTest ) \n\t*/\n\tif( fMyZ <= 1.0 )\n\t{\n\t\tfloat zdepth=0.0;\n#ifdef SHADOWMAP_PCF3\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset,\tfMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset,\tfMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset,\tfMyZ );\n\t\t\tvalue = value/4.0;\n\t\t}\n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n#endif\n#ifdef SHADOWMAP_PCF2\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n#endif\n#ifdef SHADOWMAP_PCF1\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n\t\t}\n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tvec4 color = texture2D( shadowMap2,vText.xy );\n\t\t\tzdepth = unpackDepth(color);\n\t\t\tvalue = float(fMyZ < zdepth);\n\t\t}\n#endif\n#ifdef SHADOWMAP_PCF_NO\n\t\tvec4 color;\n\t\tif ( nPSNum == 0 )\n\t\t{\n\t\t\tcolor = texture2D( shadowMap1,vText.xy );\n\t\t}\n\t\telse if( nPSNum == 1 )\n\t\t{\n\t\t\tcolor = texture2D( shadowMap2,vText.xy );\n\t\t}\n\t\tzdepth = unpackDepth(color);\n\t\tvalue = float(fMyZ < zdepth);\n#endif\n\t}\n\treturn value;\n}\nfloat getShadowPSSM1( sampler2D shadowMap1,vec4 lightMVPPos,vec4 pssmDistance,vec2 shadowPCFOffset,float posViewZ,float zBias )\n{\n\tfloat value = 1.0;\n\tif( posViewZ < pssmDistance.x )\n\t{\n\t\tvec3 vText = lightMVPPos.xyz / lightMVPPos.w;\n\t\tfloat fMyZ = vText.z - zBias;\n\t\t/*\n\t\tbvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\n\t\tbool bInFrustum = all( bInFrustumVec );\n\t\tbvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\n\t\tbool bFrustumTest = all( bFrustumTestVec );\n\t\t*/\n\t\tif ( fMyZ <= 1.0 ) \n\t\t{\n\t\t\tfloat zdepth=0.0;\n#ifdef SHADOWMAP_PCF3\n\t\t\tvalue = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset,fMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset,fMyZ );\n\t\t\tvalue += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset,fMyZ );\n\t\t\tvalue = value/4.0;\n#endif\n#ifdef SHADOWMAP_PCF2\t\t\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n#endif\n#ifdef SHADOWMAP_PCF1\n\t\t\tvalue = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n#endif\n#ifdef SHADOWMAP_PCF_NO\t\t\n\t\t\tvec4 color = texture2D( shadowMap1,vText.xy );\n\t\t\tzdepth = unpackDepth(color);\n\t\t\tvalue = float(fMyZ < zdepth);\n#endif\n\t\t}\n\t}\n\treturn value;\n}"),Bn.addInclude("WaveFunction.glsl","\nuniform vec2 u_WaveInfoD[20];\nuniform vec4 u_WaveInfo[20];\n\nuniform float TEXWAVE_UV_SCALE ;//= 20.0; //每texwidth像素代表的实际距离\n/**\n\t这里的计算都是\n*/\n\n/**\n* 计算一个波形\n* 开始计算的时候都按照z向上,最后输出的时候,颠倒一下。\n* @param tm {float} 毫秒\n*/\nvoid calcGerstnerWave(float curtm, vec3 pos, float deep, vec2 uvpos, out vec3 opos, out vec3 B, out vec3 T, out vec3 N, out float foamS){\n\tfloat tm = curtm/1000.;\n\topos = pos;\n\tvec3 wpos=vec3(0.);\t\t//累加的位置\n\tN=vec3(0.,0.,0.);\t//输出的法线初始化一下\n\tT=vec3(0.,0.,0.);\n\tB=vec3(0.,0.,0.);\n\tvec2 cD ;//= D;\n\t//float deepAtt = max(0.,min(deep,1.0));\n\t//A*=deepAtt; //TODO\n\t\n\tfor( int i=0; i<4; i++){\n\t\tcD = u_WaveInfoD[i];//vec2(wi.winfo[0],wi.winfo[1]);// wi.vDir;\n\t\tfloat Q = u_WaveInfo[i].x;//wi.QorK;\n\t\tfloat A = u_WaveInfo[i].y;//wi.A;\n\t\tfloat W = u_WaveInfo[i].z;//wi.omega;\n\t\tfloat P = u_WaveInfo[i].w;//wi.phi;\n\t\tfloat dop = dot(cD,uvpos);\n\t\tfloat c = cos(dop*W - tm*P);//TODO 优化\n\t\tfloat s = sin(dop*W - tm*P);\n\t\tfloat AWs = A*W*s;\n\t\tfloat AWc = A*W*c;\n\t\tfloat _QxyAWs = -Q*cD.x*cD.y*AWs;\n\t\t\n\t\twpos += vec3(Q*A*cD.x*c,\n\t\t\t\t\tQ*A*cD.y*c,\n\t\t\t\t\tA*s);\n\t\tN += vec3(-cD.x*AWc,\n\t\t\t\t-cD.y*AWc,\n\t\t\t\tQ*AWs);//记得最后1-\n\t\tT += vec3(_QxyAWs,\n\t\t\t\tQ*cD.y*cD.y*AWs,//记得1-\n\t\t\t\tcD.y*AWc\n\t\t\t);\n\t\tB += vec3(Q*cD.x*cD.x*AWs,//记得1-\n\t\t\t\t_QxyAWs,\n\t\t\t\tcD.x*AWc\n\t\t\t);\n\t\t//float v1 = exp(-tan((dop*W - tm*P)/2.+1.07));//除2,+pi/2 这样正好能对齐\n#ifdef USE_FOAM\t\t\n\t\tfloat v1 = 0.5-sin((dop*W - tm*P)/1.+2.0)/2.;\n\t\tfoamS += pow(v1,9.)/4.;\n#endif\n\t}\n\tT.y=1.-T.y; B.x=1.-B.x;N.z=1.-N.z;\n\topos += vec3(wpos.x,wpos.z*min(deep/10.,1.),wpos.y);\n\t//y和z交换一下。现在根据uv计算的位置,所以直接交换yz就行。其他情况下有问题么\n\tT.xyz=T.xzy;\n\tB.xyz=B.xzy;\n\tN.xyz=N.xzy;\n}\n\n\nvoid calcWave(float curtm, vec2 uv, out vec3 B, out vec3 T, out vec3 N){\n\tfloat tm = curtm/1000.;\n\tN=vec3(0.,0.,0.);\t//输出的法线初始化一下\n\tvec2 uvpos = uv*TEXWAVE_UV_SCALE; //TODO 这个范围是什么 就是1?\n\tuvpos.y*=-1.;\n\tvec2 cD;// = D;\n\tconst int NumWaves = 4;\n\tfloat scale = 1./float(NumWaves);\n\tfor( int i=0; i=normalizedAge)\n\t\t{\n\t\t\tvec2 lastGradientNumber=gradientNumbers[i-1];\n\t\t\tfloat lastKey=lastGradientNumber.x;\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\n\t\t\tcurValue=mix(lastGradientNumber.y,gradientNumber.y,age);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn curValue;\n}\n#endif\n\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)||defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\nfloat getTotalValueFromGradientFloat(in vec2 gradientNumbers[4],in float normalizedAge)\n{\n\tfloat totalValue=0.0;\n\tfor(int i=1;i<4;i++)\n\t{\n\t\tvec2 gradientNumber=gradientNumbers[i];\n\t\tfloat key=gradientNumber.x;\n\t\tvec2 lastGradientNumber=gradientNumbers[i-1];\n\t\tfloat lastValue=lastGradientNumber.y;\n\t\t\n\t\tif(key>=normalizedAge){\n\t\t\tfloat lastKey=lastGradientNumber.x;\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\n\t\t\ttotalValue+=(lastValue+mix(lastValue,gradientNumber.y,age))/2.0*a_ShapePositionStartLifeTime.w*(normalizedAge-lastKey);\n\t\t\tbreak;\n\t\t}\n\t\telse{\n\t\t\ttotalValue+=(lastValue+gradientNumber.y)/2.0*a_ShapePositionStartLifeTime.w*(key-lastGradientNumber.x);\n\t\t}\n\t}\n\treturn totalValue;\n}\n#endif\n\n#if defined(COLOROVERLIFETIME)||defined(RANDOMCOLOROVERLIFETIME)\nvec4 getColorFromGradient(in vec2 gradientAlphas[4],in vec4 gradientColors[4],in float normalizedAge)\n{\n\tvec4 overTimeColor;\n\tfor(int i=1;i<4;i++)\n\t{\n\t\tvec2 gradientAlpha=gradientAlphas[i];\n\t\tfloat alphaKey=gradientAlpha.x;\n\t\tif(alphaKey>=normalizedAge)\n\t\t{\n\t\t\tvec2 lastGradientAlpha=gradientAlphas[i-1];\n\t\t\tfloat lastAlphaKey=lastGradientAlpha.x;\n\t\t\tfloat age=(normalizedAge-lastAlphaKey)/(alphaKey-lastAlphaKey);\n\t\t\toverTimeColor.a=mix(lastGradientAlpha.y,gradientAlpha.y,age);\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tfor(int i=1;i<4;i++)\n\t{\n\t\tvec4 gradientColor=gradientColors[i];\n\t\tfloat colorKey=gradientColor.x;\n\t\tif(colorKey>=normalizedAge)\n\t\t{\n\t\t\tvec4 lastGradientColor=gradientColors[i-1];\n\t\t\tfloat lastColorKey=lastGradientColor.x;\n\t\t\tfloat age=(normalizedAge-lastColorKey)/(colorKey-lastColorKey);\n\t\t\toverTimeColor.rgb=mix(gradientColors[i-1].yzw,gradientColor.yzw,age);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn overTimeColor;\n}\n#endif\n\n\n#if defined(TEXTURESHEETANIMATIONCURVE)||defined(TEXTURESHEETANIMATIONRANDOMCURVE)\nfloat getFrameFromGradient(in vec2 gradientFrames[4],in float normalizedAge)\n{\n\tfloat overTimeFrame;\n\tfor(int i=1;i<4;i++)\n\t{\n\t\tvec2 gradientFrame=gradientFrames[i];\n\t\tfloat key=gradientFrame.x;\n\t\tif(key>=normalizedAge)\n\t\t{\n\t\t\tvec2 lastGradientFrame=gradientFrames[i-1];\n\t\t\tfloat lastKey=lastGradientFrame.x;\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\n\t\t\toverTimeFrame=mix(lastGradientFrame.y,gradientFrame.y,age);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn floor(overTimeFrame);\n}\n#endif\n\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\nvec3 computeParticleLifeVelocity(in float normalizedAge)\n{\n vec3 outLifeVelocity;\n #ifdef VELOCITYOVERLIFETIMECONSTANT\n\t outLifeVelocity=u_VOLVelocityConst; \n #endif\n #ifdef VELOCITYOVERLIFETIMECURVE\n outLifeVelocity= vec3(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\n #endif\n #ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\n\t outLifeVelocity=mix(u_VOLVelocityConst,u_VOLVelocityConstMax,vec3(a_Random1.y,a_Random1.z,a_Random1.w)); \n #endif\n #ifdef VELOCITYOVERLIFETIMERANDOMCURVE\n outLifeVelocity=vec3(mix(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y),\n\t mix(getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z),\n\t\t\t\t\t mix(getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\n #endif\n\t\t\t\t\t\n return outLifeVelocity;\n} \n#endif\n\nvec3 computeParticlePosition(in vec3 startVelocity, in vec3 lifeVelocity,in float age,in float normalizedAge,vec3 gravityVelocity,vec4 worldRotation)\n{\n vec3 startPosition;\n vec3 lifePosition;\n #if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n\t#ifdef VELOCITYOVERLIFETIMECONSTANT\n\t\t startPosition=startVelocity*age;\n\t\t lifePosition=lifeVelocity*age;\n\t#endif\n\t#ifdef VELOCITYOVERLIFETIMECURVE\n\t\t startPosition=startVelocity*age;\n\t\t lifePosition=vec3(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\n\t#endif\n\t#ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\n\t\t startPosition=startVelocity*age;\n\t\t lifePosition=lifeVelocity*age;\n\t#endif\n\t#ifdef VELOCITYOVERLIFETIMERANDOMCURVE\n\t\t startPosition=startVelocity*age;\n\t\t lifePosition=vec3(mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y)\n\t ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z)\n\t ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\n\t#endif\n\t\n\tvec3 finalPosition;\n\tif(u_VOLSpaceType==0){\n\t if(u_ScalingMode!=2)\n\t finalPosition =rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition),worldRotation);\n\t else\n\t finalPosition =rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition,worldRotation);\n\t}\n\telse{\n\t if(u_ScalingMode!=2)\n\t finalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation)+lifePosition;\n\t else\n\t finalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation)+lifePosition;\n\t}\n #else\n\t startPosition=startVelocity*age;\n\t vec3 finalPosition;\n\t if(u_ScalingMode!=2)\n\t finalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation);\n\t else\n\t finalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation);\n #endif\n \n if(u_SimulationSpace==0)\n finalPosition=finalPosition+a_SimulationWorldPostion;\n else if(u_SimulationSpace==1) \n finalPosition=finalPosition+u_WorldPosition;\n \n finalPosition+=0.5*gravityVelocity*age;\n \n return finalPosition;\n}\n\n\nvec4 computeParticleColor(in vec4 color,in float normalizedAge)\n{\n\t#ifdef COLOROVERLIFETIME\n\t color*=getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge);\n\t#endif\n\t\n\t#ifdef RANDOMCOLOROVERLIFETIME\n\t color*=mix(getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge),getColorFromGradient(u_MaxColorOverLifeGradientAlphas,u_MaxColorOverLifeGradientColors,normalizedAge),a_Random0.y);\n\t#endif\n\n return color;\n}\n\nvec2 computeParticleSizeBillbard(in vec2 size,in float normalizedAge)\n{\n\t#ifdef SIZEOVERLIFETIMECURVE\n\t\tsize*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\n\t#endif\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVES\n\t size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \n\t#endif\n\t#ifdef SIZEOVERLIFETIMECURVESEPERATE\n\t\tsize*=vec2(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge));\n\t#endif\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\n\t size*=vec2(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\n\t ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z));\n\t#endif\n\treturn size;\n}\n\n#ifdef RENDERMODE_MESH\nvec3 computeParticleSizeMesh(in vec3 size,in float normalizedAge)\n{\n\t#ifdef SIZEOVERLIFETIMECURVE\n\t\tsize*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\n\t#endif\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVES\n\t size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \n\t#endif\n\t#ifdef SIZEOVERLIFETIMECURVESEPERATE\n\t\tsize*=vec3(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge));\n\t#endif\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\n\t size*=vec3(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\n\t ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z)\n\t\t,mix(getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxZ,normalizedAge),a_Random0.z));\n\t#endif\n\treturn size;\n}\n#endif\n\nfloat computeParticleRotationFloat(in float rotation,in float age,in float normalizedAge)\n{ \n\t#ifdef ROTATIONOVERLIFETIME\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\n\t\t\tfloat ageRot=u_ROLAngularVelocityConst*age;\n\t rotation+=ageRot;\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\n\t rotation+=ageRot;\n\t #endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\n\t\t#endif\n\t#endif\n\t#ifdef ROTATIONOVERLIFETIMESEPERATE\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\n\t\t\tfloat ageRot=u_ROLAngularVelocityConstSeprarate.z*age;\n\t rotation+=ageRot;\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge);\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConstSeprarate.z,u_ROLAngularVelocityConstMaxSeprarate.z,a_Random0.w)*age;\n\t rotation+=ageRot;\n\t #endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\n\t\t#endif\n\t#endif\n\treturn rotation;\n}\n\n\n#if defined(RENDERMODE_MESH)&&(defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE))\nvec3 computeParticleRotationVec3(in vec3 rotation,in float age,in float normalizedAge)\n{ \n\t#ifdef ROTATIONOVERLIFETIME\n\t#ifdef ROTATIONOVERLIFETIMECONSTANT\n\t\t\tfloat ageRot=u_ROLAngularVelocityConst*age;\n\t rotation+=ageRot;\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\n\t rotation+=ageRot;\n\t #endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\n\t\t#endif\n\t#endif\n\t#ifdef ROTATIONOVERLIFETIMESEPERATE\n\t#ifdef ROTATIONOVERLIFETIMECONSTANT\n\t\t\tvec3 ageRot=u_ROLAngularVelocityConstSeprarate*age;\n\t rotation+=ageRot;\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\n\t\t\trotation+=vec3(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge));\n\t\t#endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n\t\t\tvec3 ageRot=mix(u_ROLAngularVelocityConstSeprarate,u_ROLAngularVelocityConstMaxSeprarate,a_Random0.w)*age;\n\t rotation+=ageRot;\n\t #endif\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n\t\t\trotation+=vec3(mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxX,normalizedAge),a_Random0.w)\n\t ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxY,normalizedAge),a_Random0.w)\n\t ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\n\t\t#endif\n\t#endif\n\treturn rotation;\n}\n#endif\n\nvec2 computeParticleUV(in vec2 uv,in float normalizedAge)\n{ \n\t#ifdef TEXTURESHEETANIMATIONCURVE\n\t\tfloat cycleNormalizedAge=normalizedAge*u_TSACycles;\n\t\tfloat frame=getFrameFromGradient(u_TSAGradientUVs,cycleNormalizedAge-floor(cycleNormalizedAge));\n\t\tfloat totalULength=frame*u_TSASubUVLength.x;\n\t\tfloat floorTotalULength=floor(totalULength);\n\t uv.x+=totalULength-floorTotalULength;\n\t\tuv.y+=floorTotalULength*u_TSASubUVLength.y;\n #endif\n\t#ifdef TEXTURESHEETANIMATIONRANDOMCURVE\n\t\tfloat cycleNormalizedAge=normalizedAge*u_TSACycles;\n\t\tfloat uvNormalizedAge=cycleNormalizedAge-floor(cycleNormalizedAge);\n\t float frame=floor(mix(getFrameFromGradient(u_TSAGradientUVs,uvNormalizedAge),getFrameFromGradient(u_TSAMaxGradientUVs,uvNormalizedAge),a_Random1.x));\n\t\tfloat totalULength=frame*u_TSASubUVLength.x;\n\t\tfloat floorTotalULength=floor(totalULength);\n\t uv.x+=totalULength-floorTotalULength;\n\t\tuv.y+=floorTotalULength*u_TSASubUVLength.y;\n #endif\n\treturn uv;\n}\n\nuniform vec4 _QOffset; \nuniform float _Dist; \nvoid main()\n{\n\t\tfloat age = u_CurrentTime - a_DirectionTime.w;\n\t\tfloat normalizedAge = age/a_ShapePositionStartLifeTime.w;\n\t\tvec3 lifeVelocity;\n\t\tif(normalizedAge<1.0){ \n\t\t\tvec3 startVelocity=a_DirectionTime.xyz*a_StartSpeed;\n\t\t\t#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n\t\t\t\t\tlifeVelocity= computeParticleLifeVelocity(normalizedAge);//计算粒子生命周期速度\n\t\t\t#endif \n\t\t\tvec3 gravityVelocity=u_Gravity*age;\n\t\n\t\t\tvec4 worldRotation;\n\t\t\tif(u_SimulationSpace==0)\n\t\t\t\t\tworldRotation=a_SimulationWorldRotation;\n\t\t\telse\n\t\t\t\t\tworldRotation=u_WorldRotation;\n\t\n\t\t\tvec3 center=computeParticlePosition(startVelocity, lifeVelocity, age, normalizedAge,gravityVelocity,worldRotation);//计算粒子位置\n \n \n \t\t#ifdef SPHERHBILLBOARD\n\t\t\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n \t\t\tvec3 cameraUpVector =normalize(u_CameraUp);//TODO:是否外面归一化\n \t\t\tvec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\n \t\t\tvec3 upVector = normalize(cross(sideVector,u_CameraDirection));\n\t \t\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n\t\t\t\t\t#if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\n\t\t\t\t\t\t\tif(u_ThreeDStartRotation){\n\t\t\t\t\t\t\t\t\tvec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z,age,normalizedAge));\n\t\t\t\t\t\t\t\t\tcenter += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,rotation);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n\t\t\t\t\t\t\t\t\tfloat c = cos(rot);\n\t\t\t\t\t\t\t\t\tfloat s = sin(rot);\n\t\t\t\t\t\t\t\t\tmat2 rotation= mat2(c, -s, s, c);\n\t\t\t\t\t\t\t\t\tcorner=rotation*corner;\n\t\t\t\t\t\t\t\t\tcenter += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t#else\n\t\t\t\t\t\t\tif(u_ThreeDStartRotation){\n\t\t\t\t\t\t\t\tcenter += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,a_StartRotation0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\t\tfloat c = cos(a_StartRotation0.x);\n\t\t\t\t\t\t\t\t\tfloat s = sin(a_StartRotation0.x);\n\t\t\t\t\t\t\t\t\tmat2 rotation= mat2(c, -s, s, c);\n\t\t\t\t\t\t\t\t\tcorner=rotation*corner;\n\t\t\t\t\t\t\t\t\tcenter += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t#endif\n \t\t#endif\n \n \t\t#ifdef STRETCHEDBILLBOARD\n\t\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n\t\t\t\tvec3 velocity;\n\t\t\t\t#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n\t \t\t\t\t if(u_VOLSpaceType==0)\n\t\t \t\t\t\t\tvelocity=rotationByQuaternions(u_SizeScale*(startVelocity+lifeVelocity),worldRotation)+gravityVelocity;\n\t \t\t\t\telse\n\t\t \t\t\t\t\tvelocity=rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+lifeVelocity+gravityVelocity;\n \t\t\t#else\n\t \t\t\t\tvelocity= rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+gravityVelocity;\n \t\t\t#endif\t\n\t\t\t\t\tvec3 cameraUpVector = normalize(velocity);\n\t\t\t\t\tvec3 direction = normalize(center-u_CameraPosition);\n \t\t\tvec3 sideVector = normalize(cross(direction,normalize(velocity)));\n\t\t\n\t\t\t\t\tsideVector=u_SizeScale.xzy*sideVector;\n\t\t\t\t\tcameraUpVector=length(vec3(u_SizeScale.x,0.0,0.0))*cameraUpVector;\n\t\t\n\t \t\t\tvec2 size=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n\t\t\n\t \t\t\tconst mat2 rotaionZHalfPI=mat2(0.0, -1.0, 1.0, 0.0);\n\t \t\t\tcorner=rotaionZHalfPI*corner;\n\t \t\t\tcorner.y=corner.y-abs(corner.y);\n\t\t\n\t \t\t\tfloat speed=length(velocity);//TODO:\n\t \tcenter+=sign(u_SizeScale.x)*(sign(u_StretchedBillboardLengthScale)*size.x*corner.x*sideVector+(speed*u_StretchedBillboardSpeedScale+size.y*u_StretchedBillboardLengthScale)*corner.y*cameraUpVector);\n \t\t#endif\n \n \t\t#ifdef HORIZONTALBILLBOARD\n\t\t\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n \t\t\tconst vec3 cameraUpVector=vec3(0.0,0.0,1.0);\n\t \t\t\tconst vec3 sideVector = vec3(-1.0,0.0,0.0);\n\t\t\n\t\t\t\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n \t\t\tfloat c = cos(rot);\n \t\t\tfloat s = sin(rot);\n \t\t\tmat2 rotation= mat2(c, -s, s, c);\n\t \t\t\tcorner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\n\t\t\t\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n \t\t\tcenter +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\n \t\t#endif\n \n \t\t#ifdef VERTICALBILLBOARD\n\t\t\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n \t\t\tconst vec3 cameraUpVector =vec3(0.0,1.0,0.0);\n \t\t\tvec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\n\t\t\n\t\t\t\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n \t\t\tfloat c = cos(rot);\n \t\t\tfloat s = sin(rot);\n \t\t\tmat2 rotation= mat2(c, -s, s, c);\n\t \t\t\tcorner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\n\t\t\t\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n \t\t\tcenter +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\n \t\t#endif\n \n \t\t#ifdef RENDERMODE_MESH\n\t \t\t\tvec3 size=computeParticleSizeMesh(a_StartSize,normalizedAge);\n\t\t\t\t\t#if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\n\t\t\t\t\t\tif(u_ThreeDStartRotation){\n\t\t\t\t\t\t\t\tvec3 rotation=vec3(a_StartRotation0.xy,-computeParticleRotationFloat(a_StartRotation0.z, age,normalizedAge));\n\t\t\t\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,rotation),worldRotation);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\t#ifdef ROTATIONOVERLIFETIME\n\t\t\t\t\t\t\t\t\t\tfloat angle=computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n\t\t\t\tif(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\n\t\t\t\t\t\t\t\tcenter+=(rotationByQuaternions(rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),angle),worldRotation));//已验证\n}\n\t\t\t\t\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\t\t\t\t#ifdef SHAPE\n\t\t\t\t\t\t\t\t\t\t\t\t\tcenter+= u_SizeScale.xzy*(rotationByQuaternions(rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),angle),worldRotation));\n\t\t\t\t\t\t\t\t\t\t\t#else\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(u_SimulationSpace==0)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcenter+=rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle);//已验证\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\n\t\t\t\t\t\t\t\tcenter+=rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle),worldRotation);//已验证\n\t\t\t\t\t\t\t\t\t\t\t#endif\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t#endif\n\t\t\t\t\t\t\t\t#ifdef ROTATIONOVERLIFETIMESEPERATE\n\t\t\t\t\t\t\t\t\t//TODO:是否应合并if(u_ThreeDStartRotation)分支代码,待测试\n\t\t\t\t\t\t\t\t\t\tvec3 angle=computeParticleRotationVec3(vec3(0.0,0.0,a_StartRotation0.z), age,normalizedAge);\n\t\t\t\t\t\t\t\t\t\tcenter+= (rotationByQuaternions(rotationByEuler(u_SizeScale*a_MeshPosition*size,vec3(angle.x,angle.y,angle.z)),worldRotation));//已验证\n\t\t\t\t\t\t\t\t#endif\t\n\t\t\t\t\t\t}\n\t\t\t\t\t#else\n\t\t\t\t\t\t\tif(u_ThreeDStartRotation){\n\t\t\t\t\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,a_StartRotation0),worldRotation);//已验证\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\t\tif(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\n\t\t\t\t\t\t\t\t\t\t\tif(u_SimulationSpace==0)\n\t\t\t\t\t\tcenter+=rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x);\n\t\t\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\n\t\t\t\t\t\t\t\t\t\tcenter+=(rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x),worldRotation));//已验证\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\t\t\t\t#ifdef SHAPE\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(u_SimulationSpace==0)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcenter+= u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x);\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x),worldRotation);\t\n\t\t\t\t\t\t\t\t\t\t\t#else\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(u_SimulationSpace==0)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcenter+= rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x);\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcenter+=rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x),worldRotation);//已验证\n\t\t\t\t\t\t\t#endif\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t#endif\n\t\t\t\t\tv_MeshColor=a_MeshColor;\n \t\t#endif\n \n highp vec4 vPos = u_Projection*u_View*vec4(center,1.0);\n float zOff = vPos.z/_Dist;\n vPos += _QOffset*zOff*zOff;\n gl_Position = vPos;\n\t\tv_Color = computeParticleColor(a_StartColor, normalizedAge);\n\t\t\t#ifdef DIFFUSEMAP\n\t\t\t\t\t#if defined(SPHERHBILLBOARD)||defined(STRETCHEDBILLBOARD)||defined(HORIZONTALBILLBOARD)||defined(VERTICALBILLBOARD)\n\t\t\t\t\t\t\tv_TextureCoordinate =computeParticleUV(a_CornerTextureCoordinate.zw, normalizedAge);\n\t\t\t\t\t#endif\n\t\t\t\t\t#ifdef RENDERMODE_MESH\n\t\t\t\t\t\t\tv_TextureCoordinate =computeParticleUV(a_MeshTextureCoordinate, normalizedAge);\n\t\t\t\t\t#endif\n\t\t\n\t\t\t\t\t#ifdef TILINGOFFSET\n\t\t\t\tv_TextureCoordinate=vec2(v_TextureCoordinate.x,1.0-v_TextureCoordinate.y)*u_TilingOffset.xy+vec2(u_TilingOffset.z,-u_TilingOffset.w);//需要特殊处理\n\t\t\t\t\tv_TextureCoordinate=vec2(v_TextureCoordinate.x,1.0-v_TextureCoordinate.y);//需要特殊处理\n\t\t\t\t\t#endif\n\t\t\t#endif\n \t\tv_Discard=0.0;\n\t \n\t\t\t#ifdef FOG\n\t\t\t\t\tv_PositionWorld=center;\n\t\t\t#endif\n \t\t}\n \telse\n\t\t{\n\t\t\t\tv_Discard=1.0;\n\t\t}\n}\n\n","#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nvarying float v_Discard;\nvarying vec4 v_Color;\nvarying vec2 v_TextureCoordinate;\nuniform sampler2D u_texture;\nuniform vec4 u_Tintcolor;\n\n#ifdef RENDERMODE_MESH\n\tvarying vec4 v_MeshColor;\n#endif\n\n#ifdef FOG\n\tvarying vec3 v_PositionWorld;\n\tuniform vec3 u_CameraPosition;\n\tuniform float u_FogStart;\n\tuniform float u_FogRange;\n\t#ifdef ADDTIVEFOG\n\t#else\n\t\tuniform vec3 u_FogColor;\n\t#endif\n#endif\n\n\nvoid main()\n{\t\n\t#ifdef RENDERMODE_MESH\n\t\tgl_FragColor=v_MeshColor;\n\t#else\n\t\tgl_FragColor=vec4(1.0);\t\n\t#endif\n\t\t\n\t#ifdef DIFFUSEMAP\n\t\tif(v_Discard!=0.0)\n\t\t\tdiscard;\n\t\t#ifdef TINTCOLOR\n\t\t\tgl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*u_Tintcolor*2.0*v_Color;\n\t\t#else\n\t\t\tgl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*v_Color;\n\t\t#endif\n\t#else\n\t\t#ifdef TINTCOLOR\n\t\t\tgl_FragColor*=u_Tintcolor*2.0*v_Color;\n\t\t#else\n\t\t\tgl_FragColor*=v_Color;\n\t\t#endif\n\t#endif\n\t\n\t#ifdef FOG\n\t\tvec3 toEye=u_CameraPosition-v_PositionWorld;\n\t\tfloat toEyeLength=length(toEye);\n\t\ttoEye/=toEyeLength;\n\t\t\n\t\tfloat lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\n\t\t#ifdef ADDTIVEFOG\n\t\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,vec3(0.0,0.0,0.0),lerpFact);\n\t\t#else\n\t\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\n\t\t#endif\n\t#endif\n}",n,i),qn.SHADERDEFINE_DIFFUSEMAP=a.registerMaterialDefine("DIFFUSEMAP"),qn.SHADERDEFINE_TINTCOLOR=a.registerMaterialDefine("TINTCOLOR"),qn.SHADERDEFINE_ADDTIVEFOG=a.registerMaterialDefine("ADDTIVEFOG"),qn.SHADERDEFINE_TILINGOFFSET=a.registerMaterialDefine("TILINGOFFSET"),gi.SHADERDEFINE_RENDERMODE_BILLBOARD=a.registerSpriteDefine("SPHERHBILLBOARD"),gi.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD=a.registerSpriteDefine("STRETCHEDBILLBOARD"),gi.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD=a.registerSpriteDefine("HORIZONTALBILLBOARD"),gi.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD=a.registerSpriteDefine("VERTICALBILLBOARD"),gi.SHADERDEFINE_COLOROVERLIFETIME=a.registerSpriteDefine("COLOROVERLIFETIME"),gi.SHADERDEFINE_RANDOMCOLOROVERLIFETIME=a.registerSpriteDefine("RANDOMCOLOROVERLIFETIME"),gi.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT=a.registerSpriteDefine("VELOCITYOVERLIFETIMECONSTANT"),gi.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE=a.registerSpriteDefine("VELOCITYOVERLIFETIMECURVE"),gi.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT=a.registerSpriteDefine("VELOCITYOVERLIFETIMERANDOMCONSTANT"),gi.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE=a.registerSpriteDefine("VELOCITYOVERLIFETIMERANDOMCURVE"),gi.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE=a.registerSpriteDefine("TEXTURESHEETANIMATIONCURVE"),gi.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE=a.registerSpriteDefine("TEXTURESHEETANIMATIONRANDOMCURVE"),gi.SHADERDEFINE_ROTATIONOVERLIFETIME=a.registerSpriteDefine("ROTATIONOVERLIFETIME"),gi.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE=a.registerSpriteDefine("ROTATIONOVERLIFETIMESEPERATE"),gi.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT=a.registerSpriteDefine("ROTATIONOVERLIFETIMECONSTANT"),gi.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE=a.registerSpriteDefine("ROTATIONOVERLIFETIMECURVE"),gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS=a.registerSpriteDefine("ROTATIONOVERLIFETIMERANDOMCONSTANTS"),gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES=a.registerSpriteDefine("ROTATIONOVERLIFETIMERANDOMCURVES"),gi.SHADERDEFINE_SIZEOVERLIFETIMECURVE=a.registerSpriteDefine("SIZEOVERLIFETIMECURVE"),gi.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE=a.registerSpriteDefine("SIZEOVERLIFETIMECURVESEPERATE"),gi.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES=a.registerSpriteDefine("SIZEOVERLIFETIMERANDOMCURVES"),gi.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE=a.registerSpriteDefine("SIZEOVERLIFETIMERANDOMCURVESSEPERATE"),gi.SHADERDEFINE_RENDERMODE_MESH=a.registerSpriteDefine("RENDERMODE_MESH"),gi.SHADERDEFINE_SHAPE=a.registerSpriteDefine("SHAPE"),n={a_Position:0,a_Texcoord0:2,a_Time:33},i={_QOffset:[4,1],_Dist:[5,1],u_Texture:[1,1],u_Albedo:[2,1],u_Color:[3,1],u_CurrentTime:[2,2],u_Duration:[3,2],u_MvpMatrix:[1,2]};var d=Bn.nameKey.add("GLITTER");e="attribute vec4 a_Position;\nattribute vec2 a_Texcoord0;\nattribute float a_Time;\n\nuniform mat4 u_MvpMatrix;\nuniform mat4 u_ViewMatrix;\nuniform mat4 u_WorldMat;\nuniform vec4 _QOffset; \nuniform float _Dist; \nuniform float u_CurrentTime;\nuniform vec4 u_Color;\nuniform float u_Duration;\n\nvarying vec2 v_Texcoord;\nvarying vec4 v_Color;\n\n\nvoid main()\n{\nmat4 mvMatrix = u_ViewMatrix*u_WorldMat;\nhighp vec4 vPos = u_MvpMatrix *a_Position;\nfloat zOff = vPos.z/_Dist;\nvPos += _QOffset*zOff*zOff;\ngl_Position = vPos;\n \n float age = u_CurrentTime-a_Time;\n float normalizedAge = clamp(age / u_Duration,0.0,1.0);\n \n v_Texcoord=a_Texcoord0;\n \n v_Color=u_Color;\n v_Color.a*=1.0-normalizedAge;\n}\n\n",t="#ifdef HIGHPRECISION\n\tprecision highp float;\n#else\n\tprecision mediump float;\n#endif\n\nuniform vec4 u_Albedo;\nuniform sampler2D u_Texture;\n\nvarying vec2 v_Texcoord;\nvarying vec4 v_Color;\n\n\nvoid main()\n{\t\n gl_FragColor=texture2D(u_Texture, v_Texcoord)*v_Color;\n gl_FragColor=gl_FragColor*u_Albedo;\n}\n\n",a=un.add(d,e,t,n,i),n={a_Position:0},i={u_Intensity:[1,1],u_AlphaBlending:[2,1],u_CubeTexture:[3,1],u_MvpMatrix:[4,3]};var f=Bn.nameKey.add("SkyBox");e="attribute vec4 a_Position;\nuniform mat4 u_MvpMatrix;\nvarying vec3 v_Texcoord;\n\n\nvoid main()\n{\n gl_Position = (u_MvpMatrix*a_Position).xyww;\n v_Texcoord=a_Position.xyz;\n}\n",t="#ifdef HIGHPRECISION\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n\nuniform float u_Intensity;\nuniform float u_AlphaBlending;\nuniform samplerCube u_CubeTexture;\n\nvarying vec3 v_Texcoord;\n\n\nvoid main()\n{\t\n gl_FragColor=vec4(textureCube(u_CubeTexture, v_Texcoord).rgb*u_Intensity,u_AlphaBlending);\n}\n\n",un.add(f,e,t,n,i),n={a_Position:0,a_Texcoord0:2},i={u_Intensity:[1,1],u_AlphaBlending:[2,1],u_texture:[3,1],u_MvpMatrix:[4,3]};var m=Bn.nameKey.add("SkyDome");e="attribute vec4 a_Position;\nattribute vec2 a_Texcoord0;\nuniform mat4 u_MvpMatrix;\nvarying vec2 v_Texcoord;\n\n\nvoid main()\n{\n gl_Position = (u_MvpMatrix*a_Position).xyww;\n v_Texcoord = a_Texcoord0;\n}\n",t="#ifdef HIGHPRECISION\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n\nuniform float u_Intensity;\nuniform float u_AlphaBlending;\nuniform sampler2D u_texture;\n\nvarying vec2 v_Texcoord;\n\n\nvoid main()\n{\t\n gl_FragColor=vec4(texture2D(u_texture, v_Texcoord).rgb*u_Intensity,u_AlphaBlending);\n}\n\n",un.add(m,e,t,n,i),n={a_Position:0,a_Normal:3,a_Texcoord0:2,a_Texcoord1:15},i={u_MvpMatrix:[1,2],u_WorldMat:[0,2],u_LightmapScaleOffset:[2,2],u_LightMap:[3,2],u_SplatAlphaTexture:[0,1],u_NormalTexture:[1,1],u_DiffuseTexture1:[2,1],u_DiffuseTexture2:[3,1],u_DiffuseTexture3:[4,1],u_DiffuseTexture4:[5,1],u_DiffuseScale1:[6,1],u_DiffuseScale2:[7,1],u_DiffuseScale3:[8,1],u_DiffuseScale4:[9,1],u_MaterialDiffuse:[11,1],u_MaterialAmbient:[10,1],u_MaterialSpecular:[12,1],u_CameraPos:[0,3],u_FogStart:[1,4],u_FogRange:[2,4],u_FogColor:[0,4],"u_DirectionLight.Direction":[3,4],"u_DirectionLight.Diffuse":[4,4],"u_PointLight.Position":[5,4],"u_PointLight.Range":[6,4],"u_PointLight.Attenuation":[7,4],"u_PointLight.Diffuse":[8,4],"u_SpotLight.Position":[9,4],"u_SpotLight.Direction":[10,4],"u_SpotLight.Range":[12,4],"u_SpotLight.Spot":[11,4],"u_SpotLight.Attenuation":[13,4],"u_SpotLight.Diffuse":[14,4],u_AmbientColor:[21,4],u_shadowMap1:[18,4],u_shadowMap2:[19,4],u_shadowMap3:[20,4],u_shadowPSSMDistance:[15,4],u_lightShadowVP:[16,4],u_shadowPCFoffset:[17,4]};var p=Bn.nameKey.add("Terrain");e="attribute vec4 a_Position;\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(LIGHTMAP)\n\tattribute vec3 a_Normal;\n\tvarying vec3 v_Normal;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\n\tuniform mat4 u_WorldMat;\n\tvarying vec3 v_PositionWorld;\n#endif\n\nvarying float v_posViewZ;\n#ifdef RECEIVESHADOW\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n uniform mat4 u_lightShadowVP[4];\n #endif\n#endif\n\n#ifdef LIGHTMAP\n\tuniform vec4 u_LightmapScaleOffset;\n\tvarying vec2 v_LightMapUV;\n#endif\n\nattribute vec2 a_Texcoord0;\nattribute vec2 a_Texcoord1;\nvarying vec2 v_Texcoord0;\nvarying vec2 v_Texcoord1;\nuniform mat4 u_MvpMatrix;\n\nvoid main()\n{\n\tgl_Position = u_MvpMatrix * a_Position;\n\tv_Texcoord0=a_Texcoord0;\n\tv_Texcoord1=a_Texcoord1;\n\t\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n\tv_Normal=a_Normal;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\n\tv_PositionWorld=(u_WorldMat*a_Position).xyz;\n#endif\n\n#ifdef LIGHTMAP\n\t//这个地方使用a_Normal 并不是真的代表normal,其实凑巧法线图的uv正好是符合 light_Map的UV\n\tv_LightMapUV=vec2(a_Normal.x*u_LightmapScaleOffset.x+u_LightmapScaleOffset.z,(a_Normal.y-1.0)*u_LightmapScaleOffset.y+u_LightmapScaleOffset.w);\n#endif\n\n#ifdef RECEIVESHADOW\n\tv_posViewZ = gl_Position.w;\n\t#ifdef SHADOWMAP_PSSM1\n\t\tv_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\n\t#endif\n#endif\n\n}",t='#ifdef HIGHPRECISION\n\tprecision highp float;\n#else\n\tprecision mediump float;\n#endif\n\n#include "LightHelper.glsl";\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n\tuniform vec3 u_MaterialDiffuse;\n\tuniform vec4 u_MaterialSpecular;\n\tuniform vec3 u_CameraPos;\n\tvarying vec3 v_Normal;\n\tvarying vec3 v_PositionWorld;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(LIGHTMAP)\n\tuniform vec3 u_MaterialAmbient;\n#endif\n\n#ifdef FOG\n\tuniform float u_FogStart;\n\tuniform float u_FogRange;\n\tuniform vec3 u_FogColor;\n#endif\n\n\n#ifdef DIRECTIONLIGHT\n\tuniform DirectionLight u_DirectionLight;\n#endif\n\n#ifdef POINTLIGHT\n\tuniform PointLight u_PointLight;\n#endif\n\n#ifdef SPOTLIGHT\n\tuniform SpotLight u_SpotLight;\n#endif\n\nuniform vec3 u_AmbientColor;\n\n#include "ShadowHelper.glsl"\n#ifdef RECEIVESHADOW\n\t#if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\n\tuniform mat4 u_lightShadowVP[4];\n\t#endif\n\t#ifdef SHADOWMAP_PSSM1 \n\tvarying vec4 v_lightMVPPos;\n\t#endif\n#endif\nvarying float v_posViewZ;\n\n\nuniform sampler2D u_SplatAlphaTexture;\nuniform sampler2D u_NormalTexture;\nuniform sampler2D u_DiffuseTexture1;\nuniform sampler2D u_DiffuseTexture2;\nuniform sampler2D u_DiffuseTexture3;\nuniform sampler2D u_DiffuseTexture4;\nuniform vec2 u_DiffuseScale1;\nuniform vec2 u_DiffuseScale2;\nuniform vec2 u_DiffuseScale3;\nuniform vec2 u_DiffuseScale4;\nvarying vec2 v_Texcoord0;\nvarying vec2 v_Texcoord1;\n\n#ifdef LIGHTMAP\n\tuniform sampler2D u_LightMap;\n\tvarying vec2 v_LightMapUV;\n#endif\n\nvoid main()\n{\n#ifdef DETAIL_NUM1\n\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord1/u_DiffuseScale1);\n\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\tgl_FragColor.xyz = color1.xyz;\n#endif\n#ifdef DETAIL_NUM2\n\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord1/u_DiffuseScale1);\n\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord1/u_DiffuseScale2);\n\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\tgl_FragColor.xyz = color1.xyz * (1.0-splatAlpha.r) + color2.xyz * splatAlpha.r;\n#endif\n#ifdef DETAIL_NUM3\n\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord1/u_DiffuseScale1);\n\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord1/u_DiffuseScale2);\n\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord1/u_DiffuseScale3);\n\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\tgl_FragColor.xyz = color1.xyz * (1.0-(splatAlpha.r+splatAlpha.g)) + color2.xyz * splatAlpha.r + color3.xyz * splatAlpha.g;\n#endif\n#ifdef DETAIL_NUM4\n\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord1/u_DiffuseScale1);\n\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord1/u_DiffuseScale2);\n\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord1/u_DiffuseScale3);\n\tvec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord1/u_DiffuseScale4);\n\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\tgl_FragColor.xyz = color1.xyz * (1.0-(splatAlpha.r+splatAlpha.g+splatAlpha.b))+ color2.xyz * splatAlpha.r + color3.xyz * splatAlpha.g + color4.xyz * splatAlpha.b;\n#endif\n\tgl_FragColor.w = splatAlpha.a;\n\t\t\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n vec3 normal = texture2D(u_NormalTexture,v_Normal.xy).xyz;\n\tnormal = normal*2.0 - vec3(1.0);\n\tvec3 diffuse = vec3(0.0);\n\tvec3 ambient = vec3(0.0);\n\tvec3 specular= vec3(0.0);\n\tvec3 dif, amb, spe;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\n\tvec3 toEye;\n\t#ifdef FOG\n\t\ttoEye=u_CameraPos-v_PositionWorld;\n\t\tfloat toEyeLength=length(toEye);\n\t\ttoEye/=toEyeLength;\n\t#else\n\t\ttoEye=normalize(u_CameraPos-v_PositionWorld);\n\t#endif\n#endif\n\n#ifdef DIRECTIONLIGHT\n\tcomputeDirectionLight(u_MaterialDiffuse,u_MaterialAmbient,u_MaterialSpecular,u_DirectionLight,u_AmbientColor,normal,toEye, dif, amb, spe);\n\tdiffuse+=dif;\n\tambient+=amb;\n\tspecular+=spe;\n#endif\n \n#ifdef POINTLIGHT\n\tcomputePointLight(u_MaterialDiffuse,u_MaterialAmbient,u_MaterialSpecular,u_PointLight,u_AmbientColor,v_PositionWorld,normal,toEye, dif, amb, spe);\n\tdiffuse+=dif;\n\tambient+=amb;\n\tspecular+=spe;\n#endif\n\n#ifdef SPOTLIGHT\n\tComputeSpotLight(u_MaterialDiffuse,u_MaterialAmbient,u_MaterialSpecular,u_SpotLight,u_AmbientColor,v_PositionWorld,normal,toEye, dif, amb, spe);\n\tdiffuse+=dif;\n\tambient+=amb;\n\tspecular+=spe;\n#endif\n\n#ifdef RECEIVESHADOW\n\tfloat shadowValue = 1.0;\n\t#ifdef SHADOWMAP_PSSM3\n\t\tshadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n\t#endif\n\t#ifdef SHADOWMAP_PSSM2\n\t\tshadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n\t#endif \n\t#ifdef SHADOWMAP_PSSM1\n\t\tshadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\n\t#endif\n#endif\n\n#ifdef LIGHTMAP\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n\t\tgl_FragColor.rgb=gl_FragColor.rgb*(u_MaterialAmbient + texture2D(u_LightMap, v_LightMapUV).rgb);\n\t#else\n\t\t#if defined(RECEIVESHADOW)\n\t\t\tgl_FragColor.rgb=gl_FragColor.rgb*(u_MaterialAmbient + texture2D(u_LightMap, v_LightMapUV).rgb * shadowValue);\n\t\t#else\n\t\t\tgl_FragColor.rgb=gl_FragColor.rgb*(u_MaterialAmbient + texture2D(u_LightMap, v_LightMapUV).rgb);\n\t\t#endif\n\t#endif\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n\t#ifdef RECEIVESHADOW\n\t\tgl_FragColor =vec4( gl_FragColor.rgb*(ambient + diffuse*shadowValue) + specular * shadowValue,gl_FragColor.a);\n\t#else\n\t\tgl_FragColor =vec4( gl_FragColor.rgb*(ambient + diffuse) + specular, gl_FragColor.a);\n\t#endif\n#endif\n\n#ifdef FOG\n\tfloat lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\n\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\n#endif\n}\n\n';var v=un.add(p,e,t,n,i);Zn.SHADERDEFINE_DETAIL_NUM1=v.registerMaterialDefine("DETAIL_NUM1"),Zn.SHADERDEFINE_DETAIL_NUM2=v.registerMaterialDefine("DETAIL_NUM2"),Zn.SHADERDEFINE_DETAIL_NUM4=v.registerMaterialDefine("DETAIL_NUM4"),Zn.SHADERDEFINE_DETAIL_NUM3=v.registerMaterialDefine("DETAIL_NUM3"),n={a_Position:0,a_Normal:3,a_Texcoord0:2},i={u_MvpMatrix:[1,2],u_WorldMat:[0,2],u_CameraPos:[0,3],u_LightmapScaleOffset:[2,2],u_LightMap:[3,2],u_SplatAlphaTexture:[0,1],u_DiffuseTexture1:[1,1],u_DiffuseTexture2:[2,1],u_DiffuseTexture3:[3,1],u_DiffuseTexture4:[4,1],u_DiffuseTexture5:[5,1],u_DiffuseScaleOffset1:[6,1],u_DiffuseScaleOffset2:[7,1],u_DiffuseScaleOffset3:[8,1],u_DiffuseScaleOffset4:[9,1],u_DiffuseScaleOffset5:[10,1],u_MaterialAlbedo:[14,1],u_MaterialDiffuse:[12,1],u_MaterialAmbient:[11,1],u_MaterialSpecular:[13,1],u_FogStart:[1,4],u_FogRange:[2,4],u_FogColor:[0,4],"u_DirectionLight.Direction":[3,4],"u_DirectionLight.Diffuse":[4,4],"u_PointLight.Position":[5,4],"u_PointLight.Range":[6,4],"u_PointLight.Attenuation":[7,4],"u_PointLight.Diffuse":[8,4],"u_SpotLight.Position":[9,4],"u_SpotLight.Direction":[10,4],"u_SpotLight.Range":[12,4],"u_SpotLight.Spot":[11,4],"u_SpotLight.Attenuation":[13,4],"u_SpotLight.Diffuse":[14,4],u_AmbientColor:[21,4],u_shadowMap1:[18,4],u_shadowMap2:[19,4],u_shadowMap3:[20,4],u_shadowPSSMDistance:[15,4],u_lightShadowVP:[16,4],u_shadowPCFoffset:[17,4]};var g=Bn.nameKey.add("ExtendTerrain");e="attribute vec4 a_Position;\nattribute vec2 a_Texcoord0;\n\nuniform mat4 u_MvpMatrix;\n\nvarying vec2 v_Texcoord0;\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(LIGHTMAP)\n\tattribute vec3 a_Normal;\n\tvarying vec3 v_Normal;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\n\tuniform mat4 u_WorldMat;\n\tvarying vec3 v_PositionWorld;\n#endif\n\n#ifdef LIGHTMAP\n\tvarying vec2 v_LightMapUV;\n\tuniform vec4 u_LightmapScaleOffset;\n#endif\n\n#ifdef RECEIVESHADOW\n\tvarying float v_posViewZ;\n\t#ifdef SHADOWMAP_PSSM1 \n\t\tvarying vec4 v_lightMVPPos;\n\t\tuniform mat4 u_lightShadowVP[4];\n\t#endif\n#endif\n\nvoid main()\n{\n\tgl_Position = u_MvpMatrix * a_Position;\n \n\tv_Texcoord0 = a_Texcoord0;\n \n\t#ifdef LIGHTMAP\n\t\tv_LightMapUV = vec2(a_Texcoord0.x*u_LightmapScaleOffset.x+u_LightmapScaleOffset.z,(a_Texcoord0.y-1.0)*u_LightmapScaleOffset.y+u_LightmapScaleOffset.w);\n\t#endif\n \n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n\t\tv_Normal = a_Normal;\n\t#endif\n\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\n\t\tv_PositionWorld=(u_WorldMat*a_Position).xyz;\n\t#endif\n\n\t#ifdef RECEIVESHADOW\n\t\tv_posViewZ = gl_Position.w;\n\t\t#ifdef SHADOWMAP_PSSM1\n\t\t\tv_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\n\t\t#endif\n\t#endif\n}",t='#ifdef HIGHPRECISION\n\tprecision highp float;\n#else\n\tprecision mediump float;\n#endif\n\n#include "LightHelper.glsl";\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\n\tuniform vec3 u_MaterialDiffuse;\n\tuniform vec4 u_MaterialSpecular;\n\tuniform vec3 u_CameraPos;\n\tvarying vec3 v_Normal;\n\tvarying vec3 v_PositionWorld;\n#endif\n\n#ifdef FOG\n\tuniform float u_FogStart;\n\tuniform float u_FogRange;\n\tuniform vec3 u_FogColor;\n#endif\n\n\n#ifdef DIRECTIONLIGHT\n\tuniform DirectionLight u_DirectionLight;\n#endif\n\n#ifdef POINTLIGHT\n\tuniform PointLight u_PointLight;\n#endif\n\n#ifdef SPOTLIGHT\n\tuniform SpotLight u_SpotLight;\n#endif\n\nuniform vec3 u_AmbientColor;\n\n#include "ShadowHelper.glsl"\n#ifdef RECEIVESHADOW\n\t#if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\n\tuniform mat4 u_lightShadowVP[4];\n\t#endif\n\t#ifdef SHADOWMAP_PSSM1 \n\tvarying vec4 v_lightMVPPos;\n\t#endif\n#endif\nvarying float v_posViewZ;\n\n\nuniform sampler2D u_SplatAlphaTexture;\n\nuniform sampler2D u_DiffuseTexture1;\nuniform sampler2D u_DiffuseTexture2;\nuniform sampler2D u_DiffuseTexture3;\nuniform sampler2D u_DiffuseTexture4;\nuniform sampler2D u_DiffuseTexture5;\n\nuniform vec4 u_DiffuseScaleOffset1;\nuniform vec4 u_DiffuseScaleOffset2;\nuniform vec4 u_DiffuseScaleOffset3;\nuniform vec4 u_DiffuseScaleOffset4;\nuniform vec4 u_DiffuseScaleOffset5;\n\nvarying vec2 v_Texcoord0;\n\nuniform vec3 u_MaterialAmbient;\nuniform vec4 u_MaterialAlbedo;\n\n#ifdef LIGHTMAP\n\tuniform sampler2D u_LightMap;\n\tvarying vec2 v_LightMapUV;\n#endif\n\nvoid main()\n{\n\t#ifdef ExtendTerrain_DETAIL_NUM1\n\t\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r;\n\t#endif\n\t#ifdef ExtendTerrain_DETAIL_NUM2\n\t\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * (1.0 - splatAlpha.r);\n\t#endif\n\t#ifdef ExtendTerrain_DETAIL_NUM3\n\t\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * (1.0 - splatAlpha.r - splatAlpha.g);\n\t#endif\n\t#ifdef ExtendTerrain_DETAIL_NUM4\n\t\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\n\t\tvec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * splatAlpha.b + color4.xyz * (1.0 - splatAlpha.r - splatAlpha.g - splatAlpha.b);\n\t#endif\n\t#ifdef ExtendTerrain_DETAIL_NUM5\n\t\tvec4 splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\n\t\tvec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\n\t\tvec4 color5 = texture2D(u_DiffuseTexture5, v_Texcoord0 * u_DiffuseScaleOffset5.xy);\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * splatAlpha.b + color4.xyz * splatAlpha.a + color5.xyz * (1.0 - splatAlpha.r - splatAlpha.g - splatAlpha.b - splatAlpha.a);\n\t#endif\n\t\tgl_FragColor.w = splatAlpha.a;\n\t\t\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n vec3 normal = v_Normal;\n\tvec3 diffuse = vec3(0.0);\n\tvec3 ambient = vec3(0.0);\n\tvec3 specular= vec3(0.0);\n\tvec3 dif, amb, spe;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\n\tvec3 toEye;\n\t#ifdef FOG\n\t\ttoEye=u_CameraPos-v_PositionWorld;\n\t\tfloat toEyeLength=length(toEye);\n\t\ttoEye/=toEyeLength;\n\t#else\n\t\ttoEye=normalize(u_CameraPos-v_PositionWorld);\n\t#endif\n#endif\n\n#ifdef DIRECTIONLIGHT\n\tcomputeDirectionLight(u_MaterialDiffuse,u_MaterialAmbient,u_MaterialSpecular,u_DirectionLight,u_AmbientColor,normal,toEye, dif, amb, spe);\n\tdiffuse+=dif;\n\tambient+=amb;\n\tspecular+=spe;\n#endif\n \n#ifdef POINTLIGHT\n\tcomputePointLight(u_MaterialDiffuse,u_MaterialAmbient,u_MaterialSpecular,u_PointLight,u_AmbientColor,v_PositionWorld,normal,toEye, dif, amb, spe);\n\tdiffuse+=dif;\n\tambient+=amb;\n\tspecular+=spe;\n#endif\n\n#ifdef SPOTLIGHT\n\tComputeSpotLight(u_MaterialDiffuse,u_MaterialAmbient,u_MaterialSpecular,u_SpotLight,u_AmbientColor,v_PositionWorld,normal,toEye, dif, amb, spe);\n\tdiffuse+=dif;\n\tambient+=amb;\n\tspecular+=spe;\n#endif\n\n#ifdef RECEIVESHADOW\n\tfloat shadowValue = 1.0;\n\t#ifdef SHADOWMAP_PSSM3\n\t\tshadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n\t#endif\n\t#ifdef SHADOWMAP_PSSM2\n\t\tshadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n\t#endif \n\t#ifdef SHADOWMAP_PSSM1\n\t\tshadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\n\t#endif\n#endif\n\n#ifdef LIGHTMAP\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n\t\tgl_FragColor.rgb=gl_FragColor.rgb*(u_MaterialAmbient + texture2D(u_LightMap, v_LightMapUV).rgb);\n\t#else\n\t\t#if defined(RECEIVESHADOW)\t\t\n\t\t\tgl_FragColor.rgb=gl_FragColor.rgb*(u_MaterialAmbient+texture2D(u_LightMap, v_LightMapUV).rgb * shadowValue);\n\t\t\t//vec3 tColor= u_MaterialAmbient + texture2D(u_LightMap, v_LightMapUV).rgb * shadowValue + mix(vec3(0.15,0.15,0.15),vec3(0.0),shadowValue);\n\t\t\t//gl_FragColor.rgb*=tColor;\n\t\t#else\n\t\t\tgl_FragColor.rgb=gl_FragColor.rgb*(u_MaterialAmbient + texture2D(u_LightMap, v_LightMapUV).rgb);\n\t\t#endif\n\t#endif\n#endif\n\ngl_FragColor=gl_FragColor*u_MaterialAlbedo;\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n\t#ifdef RECEIVESHADOW\n\t\tgl_FragColor = vec4( gl_FragColor.rgb*(ambient + diffuse*shadowValue) + specular * shadowValue,gl_FragColor.a);\n\t#else\n\t\tgl_FragColor =vec4( gl_FragColor.rgb*(ambient + diffuse) + specular, gl_FragColor.a);\n\t#endif\n#endif\n\n#ifdef FOG\n\tfloat lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\n\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\n#endif\n}\n\n\n\n\n\n';var E=un.add(g,e,t,n,i);E.addSpriteDefines(ci.shaderDefines),E.addMaterialDefines(Hn.shaderDefines),n={a_Position:0,a_OffsetVector:41,a_Texcoord0X:38,a_Texcoord0Y:40,a_BirthTime:33},i={u_MvpMatrix:[1,2],u_VMatrix:[1,3],u_PMatrix:[2,3],u_TilingOffset:[3,1],u_MainTexture:[1,1],u_MainColor:[2,1],u_CurTime:[3,2],u_LifeTime:[4,2],u_WidthCurve:[5,2],u_WidthCurveKeyLength:[6,2],u_GradientColorkey:[7,2],u_GradientAlphakey:[8,2]};var S=Bn.nameKey.add("Trail");e="attribute vec3 a_Position;\nattribute vec3 a_OffsetVector;\nattribute vec4 a_Color;\nattribute float a_Texcoord0X;\nattribute float a_Texcoord0Y;\nattribute float a_BirthTime;\n\nuniform mat4 u_VMatrix;\nuniform mat4 u_PMatrix;\n\nuniform vec4 u_TilingOffset;\n\nuniform float u_CurTime;\nuniform float u_LifeTime;\nuniform vec4 u_WidthCurve[10];\nuniform int u_WidthCurveKeyLength;\n\nuniform vec4 u_GradientColorkey[10];\nuniform vec2 u_GradientAlphakey[10];\n\nvarying vec2 v_Texcoord0;\nvarying vec4 v_Color;\n\nfloat hermiteInterpolate(float t, float outTangent, float inTangent, float duration, float value1, float value2)\n{\n\tfloat t2 = t * t;\n\tfloat t3 = t2 * t;\n\tfloat a = 2.0 * t3 - 3.0 * t2 + 1.0;\n\tfloat b = t3 - 2.0 * t2 + t;\n\tfloat c = t3 - t2;\n\tfloat d = -2.0 * t3 + 3.0 * t2;\n\treturn a * value1 + b * outTangent * duration + c * inTangent * duration + d * value2;\n}\n\nfloat getCurWidth(in float normalizeTime)\n{\n\tif(normalizeTime == 0.0){\n\t\treturn u_WidthCurve[0].w;\n\t}\n\telse if(normalizeTime >= 1.0){\n\t\treturn u_WidthCurve[u_WidthCurveKeyLength - 1].w;\n\t}\n\telse{\n\t\tfor(int i = 0; i < 10; i ++ )\n\t\t{\n\t\t\tif(normalizeTime == u_WidthCurve[i].x)\n\t\t\t{\n\t\t\t\treturn u_WidthCurve[i].w;\n\t\t\t}\n\t\t\t\n\t\t\tvec4 lastFrame = u_WidthCurve[i];\n\t\t\tvec4 nextFrame = u_WidthCurve[i + 1];\n\t\t\tif(normalizeTime > lastFrame.x && normalizeTime < nextFrame.x)\n\t\t\t{\n\t\t\t\tfloat duration = nextFrame.x - lastFrame.x;\n\t\t\t\tfloat t = (normalizeTime - lastFrame.x) / duration;\n\t\t\t\tfloat outTangent = lastFrame.z;\n\t\t\t\tfloat inTangent = nextFrame.y;\n\t\t\t\tfloat value1 = lastFrame.w;\n\t\t\t\tfloat value2 = nextFrame.w;\n\t\t\t\treturn hermiteInterpolate(t, outTangent, inTangent, duration, value1, value2);\n\t\t\t}\n\t\t}\t\n\t}\n}\t\n\nvec4 getColorFromGradientByBlend(in vec4 gradientColors[10], in vec2 gradientAlphas[10], in float normalizeTime)\n{\n\tvec4 color;\n\tfor(int i = 1; i < 10; i++)\n\t{\n\t\tvec4 gradientColor = gradientColors[i];\n\t\tfloat colorKey = gradientColor.w;\n\t\tif(colorKey >= normalizeTime)\n\t\t{\n\t\t\tvec4 lastGradientColor = gradientColors[i-1];\n\t\t\tfloat lastColorKey = lastGradientColor.w;\n\t\t\tfloat age = (normalizeTime - lastColorKey) / (colorKey - lastColorKey);\n\t\t\tcolor.rgb = mix(gradientColors[i-1].xyz, gradientColor.xyz, age);\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor(int i = 1; i < 10; i++)\n\t{\n\t\tvec2 gradientAlpha = gradientAlphas[i];\n\t\tfloat alphaKey = gradientAlpha.y;\n\t\tif(alphaKey >= normalizeTime)\n\t\t{\n\t\t\tvec2 lastGradientAlpha = gradientAlphas[i-1];\n\t\t\tfloat lastAlphaKey = lastGradientAlpha.y;\n\t\t\tfloat age = (normalizeTime - lastAlphaKey) / (alphaKey - lastAlphaKey);\n\t\t\tcolor.a = mix(lastGradientAlpha.x, gradientAlpha.x, age);\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn color;\n}\n\nvec4 getColorFromGradientByFixed(in vec4 gradientColors[10], in vec2 gradientAlphas[10], in float normalizeTime)\n{\n\tvec4 color;\n\tfor(int i = 1; i < 10; i++)\n\t{\n\t\tvec4 gradientColor = gradientColors[i];\n\t\tif(gradientColor.w >= normalizeTime)\n\t\t{\n\t\t\tcolor.rgb = gradientColor.xyz;\n\t\t\tbreak;\n\t\t}\n\t}\n\tfor(int i = 1; i < 10; i++)\n\t{\n\t\tvec2 gradientAlpha = gradientAlphas[i];\n\t\tif(gradientAlpha.y >= normalizeTime)\n\t\t{\n\t\t\tcolor.a = gradientAlpha.x;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn color;\n}\n\nvoid main()\n{\n\tfloat normalizeTime = (u_CurTime - a_BirthTime) / u_LifeTime;\n\t\n\tgl_Position = u_PMatrix * u_VMatrix * vec4(a_Position + a_OffsetVector * getCurWidth(normalizeTime),1.0);\n\t\n\t#ifdef TILINGOFFSET\n\t\tv_Texcoord0 = (vec2(a_Texcoord0X, a_Texcoord0Y) * u_TilingOffset.xy) + u_TilingOffset.zw;\n\t#else\n\t\tv_Texcoord0 = vec2(a_Texcoord0X, a_Texcoord0Y);\n\t#endif\n\t\n\t#ifdef GRADIENTMODE_BLEND\n\t\tv_Color = getColorFromGradientByBlend(u_GradientColorkey, u_GradientAlphakey, normalizeTime);\n\t#else\n\t\tv_Color = getColorFromGradientByFixed(u_GradientColorkey, u_GradientAlphakey, normalizeTime);\n\t#endif\n}\n\n\n\n",t="#ifdef HIGHPRECISION\n\tprecision highp float;\n#else\n\tprecision mediump float;\n#endif\n\nuniform sampler2D u_MainTexture;\nuniform vec4 u_MainColor;\n\nvarying vec2 v_Texcoord0;\nvarying vec4 v_Color;\n\nvoid main()\n{\t\n\tvec4 color = 2.0 * u_MainColor * v_Color;\n\t#ifdef DIFFUSETEXTURE\n\t\tvec4 mainTextureColor = texture2D(u_MainTexture, v_Texcoord0);\n\t\tcolor *= mainTextureColor;\n\t#endif\n\tgl_FragColor = color;\n}\n\n";var D=un.add(S,e,t,n,i);Qn.SHADERDEFINE_DIFFUSETEXTURE=D.registerMaterialDefine("DIFFUSETEXTURE"),Qn.SHADERDEFINE_TILINGOFFSET=D.registerSpriteDefine("TILINGOFFSET"),Si.SHADERDEFINE_GRADIENTMODE_BLEND=D.registerSpriteDefine("GRADIENTMODE_BLEND")},e}(),Ht=function(){function e(){this._data=null,this._data=[]}r(e,"laya.d3.shader.ValusArray");var t=e.prototype;return t.setValue=function(e,t){this._data[e]=t},a(0,t,"data",function(){return this._data}),e}(),Gt=function(){function e(){this._currentPSSM=-1,this._numberOfPSSM=3,this._maxDistance=200,this._ratioOfDistance=1/this._numberOfPSSM,this._statesDirty=!0,this._lightCulling=null,this._renderTarget=null,this._lightVPMatrix=null,this._lightCameras=null,this._shadowQuenes=null,this._shadowMapTextureSize=1024,this._scene=null,this._PCFType=0,this._shaderValueLightVP=null,this._shaderValueVPs=null,this._spiltDistance=new Array(4),this._globalParallelLightDir=new Vt(0,-1,0),this._boundingSphere=new Array(4),this._boundingBox=new Array(4),this._frustumPos=new Array(16),this._uniformDistance=new Array(4),this._logDistance=new Array(4),this._dimension=new Array(4),this._tempLookAt3=new Vt,this._tempLookAt4=new Pt,this._tempValue=new Pt,this._tempPos=new Vt,this._tempLightUp=new Vt,this._tempMin=new Pt,this._tempMax=new Pt,this._tempMatrix44=new At,this._splitFrustumCulling=new Dt(At.DEFAULT),this._tempScaleMatrix44=new At,this._shadowPCFOffset=new Ot(1/1024,1/1024),this._shaderValueDistance=new Pt;var e=0;for(e=0;e3&&(this._numberOfPSSM=3),this._scene=e,this._maxDistance=t,this.PSSMNum=r,this._globalParallelLightDir=n,this._ratioOfDistance=1/this._numberOfPSSM;for(var o=0;othis._numberOfPSSM)throw new Error("ParallelSplitShadowMap: beginSample invalid index");this._currentPSSM=e,this._update(t)},t.endSampler=function(e){this._currentPSSM=-1},t._calcAllLightCameraInfo=function(e){if(1===this._numberOfPSSM)this._beginSampler(0,e),this.endSampler(e);else for(var t=0,n=this._numberOfPSSM+1;t0?At.createPerspective(3.1416*e.fieldOfView/180,e.aspectRatio,this._spiltDistance[this._currentPSSM-1],this._spiltDistance[this._currentPSSM],this._tempMatrix44):At.createPerspective(3.1416*e.fieldOfView/180,e.aspectRatio,this._spiltDistance[0],this._spiltDistance[this._numberOfPSSM],this._tempMatrix44),At.multiply(this._tempMatrix44,e.viewMatrix,this._tempMatrix44),this._splitFrustumCulling.matrix=this._tempMatrix44},t._rebuildRenderInfo=function(){var e=this._numberOfPSSM+1,t=0;if(null==this._renderTarget)for(this._renderTarget=o(e),this._renderTarget[0]=null,t=1;th[0]?u[0]:h[0],h[1]=u[1]>h[1]?u[1]:h[1],h[2]=u[2]>h[2]?u[2]:h[2]}Pt.add(this._tempMax,this._tempMin,this._tempValue),u[0]*=.5,u[1]*=.5,u[2]*=.5,u[3]=1,Pt.transformByM4x4(this._tempValue,l.transform.worldMatrix,this._tempValue);var m=Math.abs(-this._tempMax.z),p=m>this._maxDistance?m:this._maxDistance;Vt.scale(this._globalParallelLightDir,p,this._tempPos);var v=this._tempPos.elements;v[0]=u[0]-v[0],v[1]=u[1]-v[1],v[2]=u[2]-v[2],l.transform.position=this._tempPos,l.transform.lookAt(this._tempLookAt3,this._tempLightUp,!1),At.createOrthoOffCenterRH(_[0],h[0],_[1],h[1],1,p+.5*(h[2]-_[2]),l.projectionMatrix),l.projectionViewMatrix.cloneTo(this._lightVPMatrix[this._currentPSSM]),this._lightCulling[this._currentPSSM].matrix=this._lightVPMatrix[this._currentPSSM],e.multiplyMatrixOutFloat32Array(this._tempScaleMatrix44,this._lightVPMatrix[this._currentPSSM],this._shaderValueVPs[this._currentPSSM])},t.getLightFrustumCulling=function(e){return this._lightCulling[e]},t.getSplitFrustumCulling=function(){return this._splitFrustumCulling},t.getSplitDistance=function(e){return this._spiltDistance[e]},t.setShadowMapTextureSize=function(e){e!==this._shadowMapTextureSize&&(this._shadowMapTextureSize=e,this._shadowPCFOffset.x=1/this._shadowMapTextureSize,this._shadowPCFOffset.y=1/this._shadowMapTextureSize,this._statesDirty=!0)},t.getShadowMapTextureSize=function(){return this._shadowMapTextureSize},t.beginRenderTarget=function(e){this._renderTarget[e].start()},t.endRenderTarget=function(e){this._renderTarget[e].end()},t.getRenderTarget=function(e){return this._renderTarget[e]},t.disposeAllRenderTarget=function(){for(var e=0,t=this._numberOfPSSM+1;e0?e:1)<=3?e:3,this._numberOfPSSM!=e&&(this._numberOfPSSM=e,this._ratioOfDistance=1/this._numberOfPSSM,this._statesDirty=!0)}),e.multiplyMatrixOutFloat32Array=function(e,t,n){var i,r,a,o,s,l,h;for(r=e.elements,a=t.elements,i=0;i<4;i++)o=r[i],s=r[i+4],l=r[i+8],h=r[i+12],n[i]=o*a[0]+s*a[1]+l*a[2]+h*a[3],n[i+4]=o*a[4]+s*a[5]+l*a[6]+h*a[7],n[i+8]=o*a[8]+s*a[9]+l*a[10]+h*a[11],n[i+12]=o*a[12]+s*a[13]+l*a[14]+h*a[15]},e.SHADERDEFINE_RECEIVE_SHADOW=1,e.SHADERDEFINE_CAST_SHADOW=512,e.SHADERDEFINE_SHADOW_PSSM1=1024,e.SHADERDEFINE_SHADOW_PSSM2=2048,e.SHADERDEFINE_SHADOW_PSSM3=4096,e.SHADERDEFINE_SHADOW_PCF_NO=8192,e.SHADERDEFINE_SHADOW_PCF1=16384,e.SHADERDEFINE_SHADOW_PCF2=32768,e.SHADERDEFINE_SHADOW_PCF3=65536,e.MAX_PSSM_COUNT=3,e}(),zt=function(){function e(){this._boundingSphere=null,this._boundingBox=null,this._sizeOfY=null,this._currentLODLevel=0,this._lastDistanceToEye=NaN,this._originalBoundingSphere=null,this._originalBoundingBox=null,this._originalBoundingBoxCorners=null,this._bUseStrip=!1,this._gridSize=NaN,this._beginGridX=0,this._beginGridZ=0,this._LODError=null,e.__init__(),this._currentLODLevel=0}r(e,"laya.d3.terrain.TerrainLeaf");var t=e.prototype;return t.calcVertextNorml=function(t,n,i,r,a,o){var s=0,l=0;l=-1*e.getHeightFromTerrainHeightData(t-1,n-1,i,r,a),l+=-1*e.getHeightFromTerrainHeightData(t-1,n,i,r,a),l+=-1*e.getHeightFromTerrainHeightData(t-1,n+1,i,r,a),l+=1*e.getHeightFromTerrainHeightData(t+1,n-1,i,r,a),l+=1*e.getHeightFromTerrainHeightData(t+1,n,i,r,a),l+=1*e.getHeightFromTerrainHeightData(t+1,n+1,i,r,a),s=-1*e.getHeightFromTerrainHeightData(t-1,n-1,i,r,a),s+=-1*e.getHeightFromTerrainHeightData(t,n-1,i,r,a),s+=-1*e.getHeightFromTerrainHeightData(t+1,n-1,i,r,a),s+=1*e.getHeightFromTerrainHeightData(t-1,n+1,i,r,a),s+=1*e.getHeightFromTerrainHeightData(t,n+1,i,r,a),s+=1*e.getHeightFromTerrainHeightData(t+1,n+1,i,r,a),o.x=-l,o.y=6,o.z=-s,Vt.normalize(o,o)},t.calcVertextNormlUV=function(e,t,n,i,r){r.x=e/n,r.y=t/i,r.z=t/i},t.calcVertextBuffer=function(t,n,i,r,a,o,s,l,h,_,u,c){if(1==c&&!e.__ADAPT_MATRIX__){e.__ADAPT_MATRIX__=new At;var d=new At;At.createRotationY(Math.PI,e.__ADAPT_MATRIX__),At.createTranslate(new Vt(0,0,(u-1)*a),d),At.multiply(d,e.__ADAPT_MATRIX__,e.__ADAPT_MATRIX__),e.__ADAPT_MATRIX_INV__=new At,e.__ADAPT_MATRIX__.invert(e.__ADAPT_MATRIX_INV__)}this._gridSize=a,this._beginGridX=t*e.CHUNK_GRID_NUM+i,this._beginGridZ=n*e.CHUNK_GRID_NUM+r;for(var f=s*l,m=2147483647,p=-2147483648,v=new Vt,g=0,E=e.LEAF_GRID_NUM+1;gp?e.__VECTOR3__.y:p,e.__ADAPT_MATRIX__&&Vt.transformV3ToV3(e.__VECTOR3__,e.__ADAPT_MATRIX__,e.__VECTOR3__),o[f]=e.__VECTOR3__.x,o[++f]=e.__VECTOR3__.y,o[++f]=e.__VECTOR3__.z,f++,this.calcVertextNormlUV(this._beginGridX+S,this._beginGridZ+g,_,u,v),o[f]=v.x,o[++f]=v.y,o[++f]=v.z,o[++f]=(i+S)/e.CHUNK_GRID_NUM,o[++f]=(r+g)/e.CHUNK_GRID_NUM,o[++f]=this._beginGridX+S,o[++f]=this._beginGridZ+g,f++;this._sizeOfY=new Ot(m-1,p+1),this.calcLODErrors(h,_,u),this.calcOriginalBoudingBoxAndSphere()},t.calcSkirtVertextBuffer=function(t,n,i,r,a,o,s,l,h,_,u){this._gridSize=a,this._beginGridX=t*e.CHUNK_GRID_NUM+i,this._beginGridZ=n*e.CHUNK_GRID_NUM+r;var c=s*l,d=0,f=0,m=e.LEAF_GRID_NUM+1,p=new Vt,v=0,g=0;for(d=0;d<2;d++)for(f=0;fa&&(o=this._currentLODLevel)}for(var s=o;s>=1;s--)if(fi.LOD_DISTANCE_FACTOR*this._LODError[s]/a*ne._maxLODLevel&&(t=e._maxLODLevel);var n=e.LEAF_GRID_NUM+1,i=0,r=null,a=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM/Math.pow(2,t);r=new Uint16Array(a*a*6);for(var o=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM/a,s=0;se._maxLODLevel&&(t=e._maxLODLevel);var n=e.CHUNK_GRID_NUM/e.LEAF_GRID_NUM*(e.CHUNK_GRID_NUM/e.LEAF_GRID_NUM)*e.LEAF_PLANE_VERTEXT_COUNT,i=e.LEAF_GRID_NUM+1,r=0,a=null,o=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM/Math.pow(2,t);a=new Uint16Array(4*o*6);for(var s=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM/o,l=0;l<4;l++){for(var h=0;h=i?i-1:e,t=t<0?0:t,t=t>=r?r-1:t,n[t*i+e]},e.CHUNK_GRID_NUM=64,e.LEAF_GRID_NUM=32,e.__ADAPT_MATRIX__=null,e.__ADAPT_MATRIX_INV__=null,e._planeLODIndex=null,e._skirtLODIndex=null,e._bInit=!1,i(e,["LEAF_PLANE_VERTEXT_COUNT",function(){return this.LEAF_PLANE_VERTEXT_COUNT=(e.LEAF_GRID_NUM+1)*(e.LEAF_GRID_NUM+1)},"LEAF_SKIRT_VERTEXT_COUNT",function(){return this.LEAF_SKIRT_VERTEXT_COUNT=2*(e.LEAF_GRID_NUM+1)*4},"LEAF_VERTEXT_COUNT",function(){return this.LEAF_VERTEXT_COUNT=e.LEAF_PLANE_VERTEXT_COUNT+e.LEAF_SKIRT_VERTEXT_COUNT},"LEAF_PLANE_MAX_INDEX_COUNT",function(){return this.LEAF_PLANE_MAX_INDEX_COUNT=e.LEAF_GRID_NUM*e.LEAF_GRID_NUM*6},"LEAF_SKIRT_MAX_INDEX_COUNT",function(){return this.LEAF_SKIRT_MAX_INDEX_COUNT=4*e.LEAF_GRID_NUM*6},"LEAF_MAX_INDEX_COUNT",function(){return this.LEAF_MAX_INDEX_COUNT=e.LEAF_PLANE_MAX_INDEX_COUNT+e.LEAF_SKIRT_MAX_INDEX_COUNT},"__VECTOR3__",function(){return this.__VECTOR3__=new Vt},"_maxLODLevel",function(){return this._maxLODLevel=Math.log2(e.LEAF_GRID_NUM)}]),e}(),kt=function(){function e(){this.alphaMap=null,this.detailID=null,this.normalMap=null}return r(e,"laya.d3.terrain.unit.ChunkInfo"),e}(),Wt=function(){function e(){this.diffuseTexture=null,this.normalTexture=null,this.scale=null,this.offset=null}return r(e,"laya.d3.terrain.unit.DetailTextureInfo"),e}(),Xt=function(){function e(){this.ambientColor=null,this.diffuseColor=null,this.specularColor=null}return r(e,"laya.d3.terrain.unit.MaterialInfo"),e}(),Zt=function(){function e(){}return r(e,"laya.d3.utils.Physics"),e.__init__=function(){e._layerCollsionMatrix.length=31;for(var t=0;t<31;t++){var n=[],i=31-t;n.length=i;for(var r=0;r-Number.MIN_VALUE&&l1)return Number.NaN;var c=e._tempVector34;Vt.cross(_,a,c);var d;if(d=Vt.dot(t.direction,c),(d*=h)<0||u+d>1)return Number.NaN;var f;return f=Vt.dot(o,c),(f*=h)<0?Number.NaN:f},i(e,["_tempVector30",function(){return this._tempVector30=new Vt},"_tempVector31",function(){return this._tempVector31=new Vt},"_tempVector32",function(){return this._tempVector32=new Vt},"_tempVector33",function(){return this._tempVector33=new Vt},"_tempVector34",function(){return this._tempVector34=new Vt},"_tempVector35",function(){return this._tempVector35=new Vt},"_tempVector36",function(){return this._tempVector36=new Vt},"_tempVector37",function(){return this._tempVector37=new Vt}]),e}(),jt=function(){function e(){this.distance=NaN,this.trianglePositions=null,this.triangleNormals=null,this.position=null,this.sprite3D=null,this.distance=-1,this.trianglePositions=[new Vt,new Vt,new Vt],this.trianglePositions.length=3,this.triangleNormals=[new Vt,new Vt,new Vt],this.triangleNormals.length=3,this.position=new Vt}r(e,"laya.d3.utils.RaycastHit");return e.prototype.cloneTo=function(e){e.distance=this.distance,this.trianglePositions[0].cloneTo(e.trianglePositions[0]),this.trianglePositions[1].cloneTo(e.trianglePositions[1]),this.trianglePositions[2].cloneTo(e.trianglePositions[2]),this.triangleNormals[0].cloneTo(e.triangleNormals[0]),this.triangleNormals[1].cloneTo(e.triangleNormals[1]),this.triangleNormals[2].cloneTo(e.triangleNormals[2]),this.position.cloneTo(e.position),e.sprite3D=this.sprite3D},e}(),Kt=function(){function e(e,t){this._width=0,this._height=0,this._width=e,this._height=t}r(e,"laya.d3.utils.Size");var t=e.prototype;return a(0,t,"width",function(){return-1===this._width?ce.clientWidth:this._width}),a(0,t,"height",function(){return-1===this._height?ce.clientHeight:this._height}),a(1,e,"fullScreen",function(){return new e(-1,-1)}),e}(),qt=function(){function e(){}return r(e,"laya.d3.utils.Utils3D"),e._rotationTransformScaleSkinAnimation=function(t,n,i,r,a,o,s,l,h,_,u,c){var d=e._tempArray16_0,f=e._tempArray16_1,m=e._tempArray16_2,p=r+r,v=a+a,g=o+o,E=r*p,S=a*p,D=a*v,T=o*p,x=o*v,M=o*g,R=s*p,A=s*v,I=s*g;d[15]=1,d[0]=1-D-M,d[1]=S+I,d[2]=T-A,d[4]=S-I,d[5]=1-E-M,d[6]=x+R,d[8]=T+A,d[9]=x-R,d[10]=1-E-D,f[15]=1,f[0]=l,f[5]=h,f[10]=_;var y,C,N,w,O;for(y=0;y<4;y++)C=d[y],N=d[y+4],w=d[y+8],O=d[y+12],m[y]=C,m[y+4]=N,m[y+8]=w,m[y+12]=C*t+N*n+w*i+O;for(y=0;y<4;y++)C=m[y],N=m[y+4],w=m[y+8],O=m[y+12],u[y+c]=C*f[0]+N*f[1]+w*f[2]+O*f[3],u[y+c+4]=C*f[4]+N*f[5]+w*f[6]+O*f[7],u[y+c+8]=C*f[8]+N*f[9]+w*f[10]+O*f[11],u[y+c+12]=C*f[12]+N*f[13]+w*f[14]+O*f[15]},e._createNodeByJson=function(t,n,i,r){if(!i)switch(n.type){case"Sprite3D":i=new Fn;break;case"MeshSprite3D":i=new vi;break;case"SkinnedMeshSprite3D":i=new Ei;break;case"ShuriKenParticle3D":i=new gi;break;case"TrailSprite3D":i=new Si;break;case"Terrain":i=new fi;break;case"Camera":i=new mi;break;case"DirectionLight":i=new pi;break;default:throw new Error("Utils3D:unidentified class type in (.lh) file.")}var a=n.props;if(a)for(var o in a)i[o]=a[o];var s=n.customProps;s&&(i instanceof laya.d3.core.Sprite3D?(i._parseBaseCustomProps(s),i._parseCustomProps(t,r,s,n),i._parseCustomComponent(t,r,n.components)):i._parseCustomProps(t,r,s,n));var l=n.child;if(l)for(var h=0,_=l.length;h<_;h++){var u=e._createNodeByJson(t,l[h],null,r);i.addChild(u)}return i},e._computeBoneAndAnimationDatasByBindPoseMatrxix=function(e,t,n,i,r,a){var o,s,l=0,h=0,_=e.length;for(o=0;o<_;l+=e[o].keyframeWidth,h+=16,o++)laya.d3.utils.Utils3D._rotationTransformScaleSkinAnimation(t[l+0],t[l+1],t[l+2],t[l+3],t[l+4],t[l+5],t[l+6],t[l+7],t[l+8],t[l+9],i,h),0!=o&&(s=16*e[o].parentIndex,laya.d3.utils.Utils3D.mulMatrixByArray(i,s,i,h,i,h));var u=n.length;for(o=0;o=0?e.substr(t):null},e._quaternionCreateFromYawPitchRollArray=function(e,t,n,i){var r=.5*n,a=.5*t,o=.5*e,s=Math.sin(r),l=Math.cos(r),h=Math.sin(a),_=Math.cos(a),u=Math.sin(o),c=Math.cos(o);i[0]=c*h*l+u*_*s,i[1]=u*_*l-c*h*s,i[2]=c*_*s-u*h*l,i[3]=c*_*l+u*h*s},e._createAffineTransformationArray=function(e,t,n,i){var r=t[0],a=t[1],o=t[2],s=t[3],l=r+r,h=a+a,_=o+o,u=r*l,c=r*h,d=r*_,f=a*h,m=a*_,p=o*_,v=s*l,g=s*h,E=s*_,S=n[0],D=n[1],T=n[2];i[0]=(1-(f+p))*S,i[1]=(c+E)*S,i[2]=(d-g)*S,i[3]=0,i[4]=(c-E)*D,i[5]=(1-(u+p))*D,i[6]=(m+v)*D,i[7]=0,i[8]=(d+g)*T,i[9]=(m-v)*T,i[10]=(1-(u+f))*T,i[11]=0,i[12]=e[0],i[13]=e[1],i[14]=e[2],i[15]=1},e._mulMatrixArray=function(e,t,n,i){var r,a,o,s,l,h=t.elements,_=h[0],u=h[1],c=h[2],d=h[3],f=h[4],m=h[5],p=h[6],v=h[7],g=h[8],E=h[9],S=h[10],D=h[11],T=h[12],x=h[13],M=h[14],R=h[15],A=i,I=i+4,y=i+8,C=i+12;for(r=0;r<4;r++)a=e[r],o=e[r+4],s=e[r+8],l=e[r+12],n[A+r]=a*_+o*u+s*c+l*d,n[I+r]=a*f+o*m+s*p+l*v,n[y+r]=a*g+o*E+s*S+l*D,n[C+r]=a*T+o*x+s*M+l*R},e.getYawPitchRoll=function(t,n){e.transformQuat(Vt.ForwardRH,t,Ct.TEMPVector31),e.transformQuat(Vt.Up,t,Ct.TEMPVector32);var i=Ct.TEMPVector32.elements;e.angleTo(Vt.ZERO,Ct.TEMPVector31,Ct.TEMPVector33);var r=Ct.TEMPVector33.elements;r[0]==Math.PI/2?(r[1]=e.arcTanAngle(i[2],i[0]),r[2]=0):r[0]==-Math.PI/2?(r[1]=e.arcTanAngle(-i[2],-i[0]),r[2]=0):(At.createRotationY(-r[1],Ct.TEMPMatrix0),At.createRotationX(-r[0],Ct.TEMPMatrix1),Vt.transformCoordinate(Ct.TEMPVector32,Ct.TEMPMatrix0,Ct.TEMPVector32),Vt.transformCoordinate(Ct.TEMPVector32,Ct.TEMPMatrix1,Ct.TEMPVector32),r[2]=e.arcTanAngle(i[1],-i[0])),r[1]<=-Math.PI&&(r[1]=Math.PI),r[2]<=-Math.PI&&(r[2]=Math.PI),r[1]>=Math.PI&&r[2]>=Math.PI&&(r[1]=0,r[2]=0,r[0]=Math.PI-r[0]),n[0]=r[1],n[1]=r[0],n[2]=r[2]},e.arcTanAngle=function(e,t){return 0==e?1==t?Math.PI/2:-Math.PI/2:e>0?Math.atan(t/e):e<0?t>0?Math.atan(t/e)+Math.PI:Math.atan(t/e)-Math.PI:0},e.angleTo=function(t,n,i){Vt.subtract(n,t,Ct.TEMPVector30),Vt.normalize(Ct.TEMPVector30,Ct.TEMPVector30),i.elements[0]=Math.asin(Ct.TEMPVector30.y),i.elements[1]=e.arcTanAngle(-Ct.TEMPVector30.z,-Ct.TEMPVector30.x)},e.transformQuat=function(e,t,n){var i=n.elements,r=e.elements,a=t,o=r[0],s=r[1],l=r[2],h=a[0],_=a[1],u=a[2],c=a[3],d=c*o+_*l-u*s,f=c*s+u*o-h*l,m=c*l+h*s-_*o,p=-h*o-_*s-u*l;i[0]=d*c+p*-h+f*-u-m*-_,i[1]=f*c+p*-_+m*-h-d*-u,i[2]=m*c+p*-u+d*-_-f*-h},e.quaterionNormalize=function(e,t){var n=e[0],i=e[1],r=e[2],a=e[3],o=n*n+i*i+r*r+a*a;o>0&&(o=1/Math.sqrt(o),t[0]=n*o,t[1]=i*o,t[2]=r*o,t[3]=a*o)},e.matrix4x4MultiplyFFF=function(e,t,n){var i,r,a,o,s;if(n===t)for(t=new Float32Array(16),i=0;i<16;++i)t[i]=n[i];for(i=0;i<4;i++)r=e[i],a=e[i+4],o=e[i+8],s=e[i+12],n[i]=r*t[0]+a*t[1]+o*t[2]+s*t[3],n[i+4]=r*t[4]+a*t[5]+o*t[6]+s*t[7],n[i+8]=r*t[8]+a*t[9]+o*t[10]+s*t[11],n[i+12]=r*t[12]+a*t[13]+o*t[14]+s*t[15]},e.matrix4x4MultiplyMFM=function(t,n,i){e.matrix4x4MultiplyFFF(t.elements,n,i.elements)},e._tempVector3_0=new Vt,e._tempVector3_1=new Vt,e._tempVector3_2=new Vt,e._tempVector3_3=new Vt,e._tempVector3_4=new Vt,e._tempVector3_5=new Vt,e._tempVector3_6=new Vt,e._tempArray4_0=new Float32Array(4),e._tempArray16_0=new Float32Array(16),e._tempArray16_1=new Float32Array(16),e._tempArray16_2=new Float32Array(16),e._tempArray16_3=new Float32Array(16),i(e,["_typeToFunO",function(){return this._typeToFunO={INT16:"writeInt16",SHORT:"writeInt16",UINT16:"writeUint16",UINT32:"writeUint32",FLOAT32:"writeFloat32",INT:"writeInt32",UINT:"writeUint32",BYTE:"writeByte",STRING:"writeUTFString"}}]),e}(),Qt=function(){function e(){}return r(e,"Laya3D"),e._cancelLoadByUrl=function(t){n.loader.cancelLoadByUrl(t),e._innerFirstLevelLoaderManager.cancelLoadByUrl(t),e._innerSecondLevelLoaderManager.cancelLoadByUrl(t),e._innerThirdLevelLoaderManager.cancelLoadByUrl(t),e._innerFourthLevelLoaderManager.cancelLoadByUrl(t)},e._changeWebGLSize=function(e,t){V.onStageResize(e,t),ce.clientWidth=e,ce.clientHeight=t},e.__init__=function(){var t=S.createMap;t.lh=[Fn,"SPRITE3DHIERARCHY"],t.ls=[bn,"SPRITE3DHIERARCHY"],t.lm=[ri,"MESH"],t.lmat=[Xn,"MATERIAL"],t.lpbr=[zn,"MATERIAL"],t.ltc=[hi,"TEXTURECUBE"],t.jpg=[li,"nativeimage"],t.jpeg=[li,"nativeimage"],t.png=[li,"nativeimage"],t.pkm=[li,"arraybuffer"],t.lsani=[l,"arraybuffer"],t.lrani=[l,"arraybuffer"],t.raw=[ni,"arraybuffer"],t.mipmaps=[ni,"arraybuffer"],t.thdata=[Sn,"arraybuffer"],t.lt=[Dn,"TERRAIN"],t.lani=[mn,"arraybuffer"],t.lav=[pn,"json"],t.ani=[l,"arraybuffer"],E.parserMap.SPRITE3DHIERARCHY=e._loadHierarchy,E.parserMap.MESH=e._loadMesh,E.parserMap.MATERIAL=e._loadMaterial,E.parserMap.TEXTURECUBE=e._loadTextureCube,E.parserMap.TERRAIN=e._loadTerrain,e._innerFirstLevelLoaderManager.on("error",null,e._eventLoadManagerError),e._innerSecondLevelLoaderManager.on("error",null,e._eventLoadManagerError),e._innerThirdLevelLoaderManager.on("error",null,e._eventLoadManagerError),e._innerFourthLevelLoaderManager.on("error",null,e._eventLoadManagerError)},e.READ_BLOCK=function(){return e._readData.pos+=4,!0},e.READ_DATA=function(){return e._DATA.offset=e._readData.getUint32(),e._DATA.size=e._readData.getUint32(),!0},e.READ_STRINGS=function(){var t=[],n={offset:0,size:0};n.offset=e._readData.getUint16(),n.size=e._readData.getUint16();e._readData.pos;e._readData.pos=n.offset+e._DATA.offset;for(var i=0;i0&&".."!==i[o]&&(i.splice(o,2),r-=2)}n=i.join("/")}else n=e+t;return null!=w.customFormat&&(n=w.customFormat(n,null)),n},e._eventLoadManagerError=function(e){n.loader.event("error",e)},e._addHierarchyInnerUrls=function(t,n,i,r,a,o){var s=e.formatRelativePath(r,a);i&&(s+=i),t.push({url:s,clas:o}),n[a]=s},e._getSprite3DHierarchyInnerUrls=function(t,n,i,r,a,o,s){var l,h=0,_=0;switch(t.type){case"Scene":var u=t.customProps.lightmaps;for(h=0,_=u.length;h<_;h++){var d=u[h].replace(".exr",".png");e._addHierarchyInnerUrls(r,a,o,s,d,li)}break;case"MeshSprite3D":case"TrailSprite3D":case"LineSprite3D":case"SkinnedMeshSprite3D":var f;if(t.instanceParams)(f=t.instanceParams.loadPath)&&e._addHierarchyInnerUrls(n,a,o,s,f,ri);else{(f=(l=t.customProps).meshPath)&&e._addHierarchyInnerUrls(n,a,o,s,f,ri);var m=l.materials;if(m)for(h=0,_=m.length;h<_;h++){var p=m[h],v=p.type.split("."),g=c.window;if(v.forEach(function(e){g=g[e]}),"function"!=typeof g)throw"_getSprite3DHierarchyInnerUrls 错误: "+p.type+" 不是类";e._addHierarchyInnerUrls(i,a,o,s,p.path,g)}}break;case"ShuriKenParticle3D":var E=(l=t.customProps).meshPath;E&&e._addHierarchyInnerUrls(n,a,o,s,E,ri);var S=l.material;if(S)v=S.type.split("."),g=c.window,v.forEach(function(e){g=g[e]}),e._addHierarchyInnerUrls(i,a,o,s,S.path,g);else{var D=l.materialPath;if(D)e._addHierarchyInnerUrls(i,a,o,s,D,qn);else{var T=l.texturePath;T&&e._addHierarchyInnerUrls(r,a,o,s,T,li)}}break;case"Terrain":e._addHierarchyInnerUrls(r,a,o,s,t.customProps.dataPath,Dn)}var x=t.components;for(var M in x){var R=x[M];switch(M){case"Animator":var A=R.avatarPath;if(A)e._addHierarchyInnerUrls(r,a,o,s,A,pn);else{var I=R.avatar;I&&e._addHierarchyInnerUrls(r,a,o,s,I.path,pn)}var y=R.clipPaths;for(h=0,_=y.length;h<_;h++)e._addHierarchyInnerUrls(r,a,o,s,y[h],mn)}}var C=t.child;for(h=0,_=C.length;h<_;h++)e._getSprite3DHierarchyInnerUrls(C[h],n,i,r,a,o,s)},e._loadHierarchy=function(t){t.on("loaded",null,e._onHierarchylhLoaded,[t,t._class._getGroup()]),t.load(t.url,"json",!1,null,!0)},e._onHierarchylhLoaded=function(t,n,i){if(t._class.destroyed)t.endLoad();else{var r=t.url,a=qt.getURLVerion(r),o=w.getPath(r),s=[],l=[],h=[],_={};e._getSprite3DHierarchyInnerUrls(i,s,l,h,_,a,o);var u=s.length+l.length+h.length,c=u+1,d=1/c;if(e._onProcessChange(t,0,d,1),h.length>0){var f=u/c,m=g.create(null,e._onProcessChange,[t,d,f],!1);e._innerFourthLevelLoaderManager.create(h,g.create(null,e._onHierarchyInnerForthLevResouLoaded,[t,n,m,i,_,s,l,d+f*h.length,f]),m,null,null,1,!0,n)}else e._onHierarchyInnerForthLevResouLoaded(t,n,null,i,_,s,l,d,f)}},e._onHierarchyInnerForthLevResouLoaded=function(t,n,i,r,a,o,s,l,h){if(t._class.destroyed)t.endLoad();else if(i&&i.recover(),s.length>0){var _=g.create(null,e._onProcessChange,[t,l,h],!1);e._innerSecondLevelLoaderManager.create(s,g.create(null,e._onHierarchyInnerSecondLevResouLoaded,[t,n,_,r,a,o,l+h*s.length,h]),i,null,null,1,!0,n)}else e._onHierarchyInnerSecondLevResouLoaded(t,n,null,r,a,o,l,h)},e._onHierarchyInnerSecondLevResouLoaded=function(t,n,i,r,a,o,s,l){if(t._class.destroyed)t.endLoad();else if(i&&i.recover(),o.length>0){var h=g.create(null,e._onProcessChange,[t,s,l],!1);e._innerFirstLevelLoaderManager.create(o,g.create(null,e._onHierarchyInnerFirstLevResouLoaded,[t,h,r,a]),i,null,null,1,!0,n)}else e._onHierarchyInnerFirstLevResouLoaded(t,null,r,a)},e._onHierarchyInnerFirstLevResouLoaded=function(e,t,n,i){t&&t.recover(),e.endLoad([n,i])},e._loadTerrain=function(t){t.on("loaded",null,e._onTerrainLtLoaded,[t,t._class._getGroup()]),t.load(t.url,"json",!1,null,!0)},e._onTerrainLtLoaded=function(t,n,i){if(t._class.destroyed)t.endLoad();else{var r,a,o=t.url,s=qt.getURLVerion(o),l=w.getPath(o),h=[],_={},u=0,c=0,d=i.heightData;r=d.url,a=e.formatRelativePath(l,r),s&&(a+=s),_[r]=a,r=a;var f=i.detailTexture;for(u=0,c=f.length;u0){e._onProcessChange(t,0,.5,1);var T=g.create(null,e._onProcessChange,[t,.5,.5],!1);e._innerSecondLevelLoaderManager.create(r,g.create(null,e._onMeshMateialLoaded,[t,T,i,h]),T,null,null,1,!0,n)}else t.endLoad([i,h])}},e._onMeshMateialLoaded=function(e,t,n,i){e.endLoad([n,i]),t.recover()},e._getMaterialTexturePath=function(t,n,i){var r=t.length-4;return t.indexOf(".dds")!=r&&t.indexOf(".tga")!=r&&t.indexOf(".exr")!=r&&t.indexOf(".DDS")!=r&&t.indexOf(".TGA")!=r&&t.indexOf(".EXR")!=r||(t=t.substr(0,r)+".png"),t=e.formatRelativePath(i,t),n&&(t+=n),t},e._loadMaterial=function(t){t.on("loaded",null,e._onMaterilLmatLoaded,[t,t._class._getGroup()]),t.load(t.url,"json",!1,null,!0)},e._onMaterilLmatLoaded=function(t,n,i){if(t._class.destroyed)t.endLoad();else{var r,a=t.url,o=qt.getURLVerion(a),s=w.getPath(a),l=[],h={},_=i.customProps,u=i.version;if(u)switch(u){case"LAYAMATERIAL:01":case"LAYAMATERIAL:02":for(var c=i.props.textures,d=0,f=c.length;d0){var y=g.create(null,e._onProcessChange,[t,I,R/A],!1);e._innerFourthLevelLoaderManager.create(l,g.create(null,e._onMateialTexturesLoaded,[t,y,i,h]),y,li,null,1,!0,n)}else e._onMateialTexturesLoaded(t,null,i,null)}},e._onMateialTexturesLoaded=function(e,t,n,i){e.endLoad([n,i]),t&&t.recover()},e._loadTextureCube=function(t){t.on("loaded",null,e._onTextureCubeLtcLoaded,[t]),t.load(t.url,"json",!1,null,!0)},e._onTextureCubeLtcLoaded=function(t,n){if(t._class.destroyed)t.endLoad();else{var i=w.getPath(t.url),r=[e.formatRelativePath(i,n.px),e.formatRelativePath(i,n.nx),e.formatRelativePath(i,n.py),e.formatRelativePath(i,n.ny),e.formatRelativePath(i,n.pz),e.formatRelativePath(i,n.nz)];e._onProcessChange(t,0,1/7,1);var a=g.create(null,e._onProcessChange,[t,1/7,6/7],!1);e._innerFourthLevelLoaderManager.load(r,g.create(null,e._onTextureCubeImagesLoaded,[t,r,a]),a,"nativeimage")}},e._onTextureCubeImagesLoaded=function(e,t,n){var i=[];i.length=6;for(var r=0;r<6;r++){var a=t[r];i[r]=E.getRes(a),E.clearRes(a)}e.endLoad(i),n.recover()},e._onProcessChange=function(e,t,n,i){(i=t+i*n)<1&&e.event("progress",i)},e.init=function(t,i,r,a,o,s){void 0===r&&(r=!1),void 0===a&&(a=!1),void 0===o&&(o=!0),void 0===s&&(s=!0),A.update3DLoop=function(){rn._triggerCollision()},A.cancelLoadByUrl=function(t){e._cancelLoadByUrl(t)},p.isAntialias=r,p.isAlpha=a,p.premultipliedAlpha=o,p.isStencil=s,V.enable()?(A.changeWebGLSize=e._changeWebGLSize,x.is3DMode=!0,n.init(t,i),k.__init__(),Zt.__init__(),Hn.__init__(),Ut.__init__(),vi.__init__(),B.__init__(),e.__init__(),_.maxTextureCount=2,(e.debugMode||de.debugMode)&&(e._debugPhasorSprite=new he)):alert("Laya3D init error,must support webGL!")},e.HIERARCHY="SPRITE3DHIERARCHY",e.MESH="MESH",e.MATERIAL="MATERIAL",e.PBRMATERIAL="PBRMTL",e.TEXTURECUBE="TEXTURECUBE",e.TERRAIN="TERRAIN",e._readData=null,e._debugPhasorSprite=null,e.debugMode=!1,i(e,["_DATA",function(){return this._DATA={offset:0,size:0}},"_strings",function(){return this._strings=["BLOCK","DATA","STRINGS"]},"_innerFirstLevelLoaderManager",function(){return this._innerFirstLevelLoaderManager=new S},"_innerSecondLevelLoaderManager",function(){return this._innerSecondLevelLoaderManager=new S},"_innerThirdLevelLoaderManager",function(){return this._innerThirdLevelLoaderManager=new S},"_innerFourthLevelLoaderManager",function(){return this._innerFourthLevelLoaderManager=new S}]),e}(),$t=function(e){function t(e){t.__super.call(this),this._owner=e,this._childs=[],this._localMatrix=new Float32Array(16),this._localQuaternionUpdate=!1,this._locaEulerlUpdate=!1,this._localUpdate=!1,this._worldUpdate=!0}r(t,"laya.d3.animation.AnimationTransform3D",v);var n=t.prototype;return n._getlocalMatrix=function(){return this._localUpdate&&(qt._createAffineTransformationArray(this._localPosition,this._localRotation,this._localScale,this._localMatrix),this._localUpdate=!1),this._localMatrix},n._onWorldTransform=function(){if(!this._worldUpdate){this._worldUpdate=!0;for(var e=0,t=this._childs.length;e=0){var e=this._owner.scene;if(e){var t=e.getlightmaps()[this._lightmapIndex];t?(this._addShaderDefine(ci.SAHDERDEFINE_LIGHTMAP),t.loaded?this._setShaderValuelightMap(t):t.once("loaded",this,this._setShaderValuelightMap)):this._removeShaderDefine(ci.SAHDERDEFINE_LIGHTMAP)}else this._removeShaderDefine(ci.SAHDERDEFINE_LIGHTMAP)}else this._removeShaderDefine(ci.SAHDERDEFINE_LIGHTMAP)},o._updateOctreeNode=function(){var e=this._treeNode;e&&this._octreeNodeNeedChange&&(e.updateObject(this),this._octreeNodeNeedChange=!1)},o._destroy=function(){this.offAll();var e=0,t=0;for(e=0,t=this._renderElements.length;e=r;h--){var _=e[h];if(i[a][30-_]){var u,c,d,f=0,m=0,p=0,v=0,g=k.getLayerByNumber(_),E=g._colliders,S=g._nonRigidbodyOffset;if(o!==g){for(f=0;fe);r++)if(e&i){var a=t[i];a&&(n[a]="")}return n},n.withCompile=function(e,n,i){var r,a,o;if(a=this.sharders[e])if(o=a[n]){if(r=o[i])return r}else o=a[n]=[];else o=(a=this.sharders[e]=[])[n]=[];var s,l=this._definesToNameDic(e,t._globalInt2name),h=this._definesToNameDic(n,this._spriteInt2name),_=this._definesToNameDic(i,this._materialInt2name);if(laya.d3.shader.ShaderCompile3D.debugMode){var u="";for(s in l)u+=s+" ";var c="";for(s in h)c+=s+" ";var d="";for(s in _)d+=s+" ";console.log("ShaderCompile3DDebugMode---(Name:"+Bn.nameKey.getName(this._name)+" PublicDefine:"+e+" SpriteDefine:"+n+" MaterialDefine:"+i+" PublicDefineGroup:"+u+" SpriteDefineGroup:"+c+"MaterialDefineGroup: "+d+")---ShaderCompile3DDebugMode")}var f={},m="";if(l)for(s in l)m+="#define "+s+"\n",f[s]=!0;if(h)for(s in h)m+="#define "+s+"\n",f[s]=!0;if(_)for(s in _)m+="#define "+s+"\n",f[s]=!0;var p=this._VS.toscript(f,[]),v=this._PS.toscript(f,[]);return r=Bn.create(m+p.join("\n"),m+v.join("\n"),this._attributeMap,this._sceneUniformMap,this._cameraUniformMap,this._spriteUniformMap,this._materialUniformMap,this._renderElementUniformMap),o[i]=r,r},n.precompileShaderWithShaderDefine=function(e,t,n){this.withCompile(e,t,n)},n.addMaterialDefines=function(e){var t=e.defines;for(var n in t){var i=t[n],r=parseInt(n);this._materialInt2name[r]=i,this._materialName2Int[i]=r}},n.addSpriteDefines=function(e){var t=e.defines;for(var n in t){var i=t[n],r=parseInt(n);this._spriteInt2name[r]=i,this._spriteName2Int[i]=r}},n.getMaterialDefineByName=function(e){return this._materialName2Int[e]},n.registerMaterialDefine=function(e){var t=Math.pow(2,this._materialDefineCounter++);return this._materialInt2name[t]=e,this._materialName2Int[e]=t,t},n.registerSpriteDefine=function(e){var t=Math.pow(2,this._spriteDefineCounter++);return this._spriteInt2name[t]=e,this._spriteName2Int[e]=t,t},t._globalRegDefine=function(e,n){t._globalInt2name[n]=e},t.add=function(e,n,i,r,a){return laya.d3.shader.ShaderCompile3D._preCompileShader[e]=new t(e,n,i,r,a,I.includes)},t.get=function(e){return laya.d3.shader.ShaderCompile3D._preCompileShader[Bn.nameKey.getID(e)]},t._preCompileShader={},t._globalInt2name=[],t.debugMode=!1,t.SHADERDEFINE_HIGHPRECISION=1,t.SHADERDEFINE_FOG=4,t.SHADERDEFINE_DIRECTIONLIGHT=8,t.SHADERDEFINE_POINTLIGHT=16,t.SHADERDEFINE_SPOTLIGHT=32,t.SHADERDEFINE_UV0=64,t.SHADERDEFINE_COLOR=128,t.SHADERDEFINE_UV1=256,t.SAHDERDEFINE_DEPTHFOG=131072,t}(),cn=function(e){function t(){t.__super.call(this)}r(t,"laya.d3.graphics.MeshSprite3DStaticBatchManager",Me);var n=t.prototype;return n._getStaticBatch=function(e,t,n,i){var r,a;return a=e?e.id.toString()+n.id.toString()+t.id.toString()+i.toString():n.id.toString()+t.id.toString()+i.toString(),this._staticBatches[a]?r=this._staticBatches[a]:this._staticBatches[a]=r=new dn(a,this,e,t,n),r},n._initStaticBatchs=function(e){this._initBatchRenderElements.sort(t._sortPrepareStaticBatch);for(var n,i,r,a=!1,o=0,s=0,l=this._initBatchRenderElements.length;s65535?a=!1:(r=this._getStaticBatch(e,i,n,o),(u=c._staticBatch)!==r&&(u&&u._deleteCombineBatchRenderObj(c),r._addCombineBatchRenderObj(c)),(u=h._staticBatch)!==r&&(u&&u._deleteCombineBatchRenderObj(h),r._addCombineBatchRenderObj(h)),a=!0)}}else a=!1,o=0;n=h._material,i=_.vertexDeclaration}},t._sortPrepareStaticBatch=function(e,t){var n=e._render,i=t._render,r=n.lightmapIndex-i.lightmapIndex;if(0===r){var a=n.receiveShadow-i.receiveShadow;if(0===a){var o=e._mainSortID-t._mainSortID;return 0===o?e.renderObj.triangleCount-t.renderObj.triangleCount:o}return a}return r},t}(),dn=function(e){function t(e,n,i,r,a){this._batchOwnerIndices=null,this._batchOwners=null,this._needFinishCombine=!1,this._currentCombineVertexCount=0,this._currentCombineIndexCount=0,this._vertexDeclaration=null,this._vertexBuffer=null,this._indexBuffer=null,t.__super.call(this,e,n,i),this._batchOwnerIndices=[],this._batchOwners=[],this._needFinishCombine=!1,this._currentCombineVertexCount=0,this._currentCombineIndexCount=0,this._vertexDeclaration=r,this._material=a}r(t,"laya.d3.graphics.SubMeshStaticBatch",Re);var n=t.prototype;return n._compareBatchRenderElement=function(e,t){return e._batchIndexStart>t._batchIndexStart},n._addCombineBatchRenderObjTest=function(e){var t=e.renderObj._vertexCount;return!((t>0?this._currentCombineVertexCount+t:this._currentCombineVertexCount+e.renderObj._getVertexBuffer().vertexCount)>65535)},n._addCombineBatchRenderObj=function(e){var t=e.renderObj,n=t._vertexCount;this._initBatchRenderElements.push(e),e._staticBatch=this,n>0?(this._currentCombineIndexCount+=t._indexCount,this._currentCombineVertexCount+=n):(this._currentCombineIndexCount=this._currentCombineIndexCount+t._getIndexBuffer().indexCount,this._currentCombineVertexCount=this._currentCombineVertexCount+t._getVertexBuffer().vertexCount),this._needFinishCombine=!0},n._deleteCombineBatchRenderObj=function(e){var t=e.renderObj,n=this._initBatchRenderElements.indexOf(e);if(-1!==n){this._initBatchRenderElements.splice(n,1),e._staticBatch=null;var i=t._vertexCount;i>0?(this._currentCombineIndexCount=this._currentCombineIndexCount-t._indexCount,this._currentCombineVertexCount=this._currentCombineVertexCount-i):(this._currentCombineIndexCount=this._currentCombineIndexCount-t._getIndexBuffer().indexCount,this._currentCombineVertexCount=this._currentCombineVertexCount-t._getVertexBuffer().vertexCount),this._needFinishCombine=!0}},n._finishInit=function(){if(this._needFinishCombine){var e=0,t=0;this._initBatchRenderElements[0]._sprite3D._render.lightmapIndex>=0?this._vertexDeclaration=this._getVertexDecLightMap(this._vertexDeclaration):this._material instanceof laya.d3.core.material.StandardMaterial&&this._material.ambientTexture&&(this._vertexDeclaration=this._getVertexDecLightMap(this._vertexDeclaration));var n=new Float32Array(this._vertexDeclaration.vertexStride/4*this._currentCombineVertexCount),i=new Uint16Array(this._currentCombineIndexCount);this._vertexBuffer&&(this._vertexBuffer.destroy(),this._indexBuffer.destroy()),this._vertexBuffer=Kn.create(this._vertexDeclaration,this._currentCombineVertexCount,35044),this._indexBuffer=jn.create("ushort",this._currentCombineIndexCount,35044);for(var r=0,a=this._initBatchRenderElements.length;r0&&(t=e.substr(0,i+1));var r=n.loader.getRes(e);void 0!=r.ev&&this.__ownerCamera?this.__ownerCamera._shaderValues.setValue(13,Math.pow(2,r.ev)):this.__ownerCamera._shaderValues.setValue(13,Math.pow(2,0)),this.texture=li.load(t+r.skytex),this.environmentSpecular=ni.load(t+r.prefiltedEnv);var a=new Float32Array(r.IrradianceMat);this.envDiffuseSHRed=a.slice(0,16),this.envDiffuseSHGreen=a.slice(16,32),this.envDiffuseSHBlue=a.slice(32,48)},o.loadEnvInfo=function(e){n.loader.load(e,g.create(this,this.onEnvDescLoaded,[e]))},o.destroy=function(){e.prototype.destroy.call(this),this._texture&&(this._texture._removeReference(),this._texture=null)},a(0,o,"texture",function(){return this._texture},function(e){this._texture!==e&&(this._texture&&this._texture._removeReference(),this._texture=e,e&&e._addReference())}),t._nameNumber=1,i(t,["_tempMatrix4x40",function(){return this._tempMatrix4x40=new At},"_tempMatrix4x41",function(){return this._tempMatrix4x41=new At},"_vertexDeclaration",function(){return this._vertexDeclaration=new Ae(20,[new Ie(0,"vector3",0),new Ie(12,"vector2",2)])}])}(bt),function(e){function t(){this._componentsMap=null,this._typeComponentsIndices=null,this._components=null,this._scripts=null,t.__super.call(this),this._componentsMap=[],this._typeComponentsIndices=[],this._components=[],this._scripts=[]}r(t,"laya.d3.core.ComponentNode",T);var n=t.prototype;return n.addComponent=function(e){var t,n=this._componentsMap.indexOf(e);if(-1===n)t=[],this._componentsMap.push(e),this._typeComponentsIndices.push(t);else if(t=this._typeComponentsIndices[n],this._components[t[0]].isSingleton)throw new Error("无法单实例创建"+e+"组件,"+e+"组件已存在!");var i=m.getInstance(e);return t.push(this._components.length),this._components.push(i),i instanceof laya.d3.component.Script&&this._scripts.push(i),i._initialize(this),i},n._removeComponent=function(e,t){var n=this._typeComponentsIndices[e],i=n[t],r=this._components[i];this._components.splice(i,1),r instanceof laya.d3.component.Script&&this._scripts.splice(this._scripts.indexOf(r),1),n.splice(t,1),0===n.length&&(this._typeComponentsIndices.splice(e,1),this._componentsMap.splice(e,1));for(var a=0,o=this._componentsMap.length;a=0;s--){var l=n[s];if(!(l>i))break;n[s]=--l}r._destroy()},n.getComponentByType=function(e,t){void 0===t&&(t=0);var n=this._componentsMap.indexOf(e);return-1===n?null:this._components[this._typeComponentsIndices[n][t]]},n.getComponentsByType=function(e,t){var n=this._componentsMap.indexOf(e);if(-1!==n){var i=this._typeComponentsIndices[n],r=i.length;t.length=r;for(var a=0;at){this._realTimeCurrentFrameIndexes[s]=h-1;break}h++}h===u&&(this._realTimeCurrentFrameIndexes[s]=u-1);var c=0,d=0,f=n[s];f||(f=n[s]=new Float32Array(l.keyFrameWidth));var m=_[this._realTimeCurrentFrameIndexes[s]];if(m){if(m.next){var p=m.duration,v=NaN;v=0!==p?(t-m.startTime)/p:0,this._hermiteInterpolate(m,v,p,f)}else{var g=m.data;for(c=0,d=f.length;ce?n=i-1:t=i+1}return t},i.addEvent=function(e){var t=this._binarySearchEventIndex(e.time);this._animationEvents.splice(t,0,e)},i.onAsynLoaded=function(e,t,n){var i=new f(t);switch(this._version=i.readUTFString(),this._version){case"LAYAANIMATION:01":L.parse(this,i);break;case"LAYAANIMATION:02":b.parse(this,i)}this.completeCreate(),this._endLoaded()},i.disposeResource=function(){this._realTimeCurrentFrameIndexes=null,this._realTimeCurrentTimes=null,this._fullKeyframeIndicesCache=null,this._animationDatasCache=null,this._avatarDatasCache=null,this._skinnedDatasCache=null,this._version=null,this._nodes=null,this._nodesMap=null,this._cachePropertyMap=null,this._nodeToCachePropertyMap=null,this._unCachePropertyMap=null,this._publicClipDatas=null},t.load=function(e){return n.loader.create(e,null,null,t)},t}(),pn=function(e){function t(){t.__super.call(this)}r(t,"laya.d3.core.Avatar",R);var i=t.prototype;return n.imps(i,{"laya.d3.core.IClone":!0}),i._initCloneToAnimator=function(e,t){t._avatarNodeMap[e.name]=e,t._avatarNodes.push(e);for(var n=0,i=e.getChildCount();n0&&(n&&n._removeReference(),t&&t._addReference())},o._getTexture=function(e){return this._values[e]},o._upload=function(){this._shader.uploadMaterialUniforms(this._shaderValues.data)},o._getShader=function(e,t,n){var i=(e|t)&~this._disablePublicShaderDefine;return this._shader=this._shaderCompile.withCompile(i,n,this._shaderDefineValue),this._shader},o._setRenderStateBlendDepth=function(){var e=V.mainContext;switch(P.setDepthMask(e,this.depthWrite),0===this.depthTest?P.setDepthTest(e,!1):(P.setDepthTest(e,!0),P.setDepthFunc(e,this.depthTest)),this.blend){case 0:P.setBlend(e,!1);break;case 1:P.setBlend(e,!0),P.setBlendFunc(e,this.srcBlend,this.dstBlend);break;case 2:P.setBlend(e,!0)}},o._setRenderStateFrontFace=function(e,t){var n=V.mainContext,i=0;switch(this.cull){case 0:P.setCullFace(n,!1);break;case 1:P.setCullFace(n,!0),i=e?t&&t._isFrontFaceInvert?2305:2304:t&&t._isFrontFaceInvert?2304:2305,P.setFrontFace(n,i);break;case 2:P.setCullFace(n,!0),i=e?t&&t._isFrontFaceInvert?2304:2305:t&&t._isFrontFaceInvert?2305:2304,P.setFrontFace(n,i)}},o.onAsynLoaded=function(e,t,n){var i=t[0],r=t[1];switch(i.version){case"LAYAMATERIAL:01":var a=0,o=0,s=i.props;for(var l in s)switch(l){case"vectors":var h=s[l];for(a=0,o=h.length;a=a)return this._onAnimationStop(),this._setPlayParamsWhenStop(a,t),void this.event("stopped");if(n+=this._currentTime,a>0)if(n>=a)do{(n-=a)=a);else this._setPlayParams(n,t);else this._currentTime=this._currentFrameTime=this._currentFrameIndex=this._playEventIndex=0,this.event("complete")}},o._update=function(e){var t=this._currentPlayClip;if(2===this.playState&&t&&t.loaded){var i=this.playbackRate*n.timer.scale,r=this._cachePlayRate;this._canCache=this.isCache&&i>=r;var a,o=-1;if(this._canCache){if(o=this._currentFrameIndex,this._lastFrameIndex===o)return;if(a=t._getAnimationDataWithCache(r,o),this._avatar){var s=this._cacheNodesAvatarOwners[this._currentPlayClipIndex],l=t._cachePropertyMap,h=l.length;h>0&&(a||((a=[]).length=h,t._cacheAnimationData(r,o,a),t._evaluateAnimationlDatasCacheMode(s,this._cacheFullFrames[this._currentPlayClipIndex],this,a,l)),this._setAnimationClipPropertyToAnimationNode(s,l,a)),this._curAvatarNodeDatas=t._getAvatarDataWithCache(this._avatar,this._cachePlayRate,o),this._curAvatarNodeDatas||(this._curAvatarNodeDatas=[],this._curAvatarNodeDatas.length=this._avatarNodes.length,t._cacheAvatarData(this._avatar,this._cachePlayRate,o,this._curAvatarNodeDatas),this._evaluateAvatarNodesCacheMode(s,t,t._publicClipDatas,this._curAvatarNodeDatas,t._unCachePropertyMap)),this._updateAvatarNodesToSpriteCacheMode(t,this._curAvatarNodeDatas)}else{var _=this._cacheNodesSpriteOwners[this._currentPlayClipIndex];a||((a=[]).length=this._currentPlayClip._nodes.length,t._evaluateAnimationlDatasCacheMode(_,this._cacheFullFrames[this._currentPlayClipIndex],this,a,null),t._cacheAnimationData(r,o,a)),this._setAnimationClipPropertyToSprite3D(_,a)}}else if(a=t._publicClipDatas,this._avatar){if(t._evaluateAnimationlDatasRealTime(this._cacheNodesAvatarOwners[this._currentPlayClipIndex],this.currentPlayTime,a,t._cachePropertyMap),!this._publicAvatarNodeDatas){this._publicAvatarNodeDatas=[];var u=this._avatarNodes.length;this._publicAvatarNodeDatas.length=u;for(var c=1;ci)throw new Error("Animator:startFrame must less than endFrame.");this._clipNames.push(t),this._clips.push(e),this._playStartFrames.push(n),this._playEndFrames.push(i),this._cacheNodesSpriteOwners.push([]),this._cacheNodesAvatarOwners.push([]),this._cacheNodesDefaultlValues.push([]),this._publicClipsDatas.push([]),e._addReference(),a=this._clips.length-1,this._avatar?this._avatar.loaded?this._getAvatarOwnersByClipAsync(a,e):this._avatar.once("loaded",this,this._getAvatarOwnersByClipAsync,[a,e]):this._getSpriteOwnersByClipAsync(a,e),e.loaded?this._computeCacheFullKeyframeIndices(a):e.once("loaded",this,this._computeCacheFullKeyframeIndices,[a])}},o.removeClip=function(e){var t=this._clips.indexOf(e);-1!==t&&(this._avatar?this._offClipAndAvatarRelateEvent(this._avatar,e):this._offGetSpriteOwnersByClipAsyncEvent(e),this._offGetClipCacheFullKeyframeIndicesEvent(e),this._clipNames.splice(t,1),this._clips.splice(t,1),this._playStartFrames.splice(t,1),this._playEndFrames.splice(t,1),this._cacheNodesSpriteOwners.splice(t,1),this._cacheNodesAvatarOwners.splice(t,1),this._cacheNodesDefaultlValues.splice(t,1),this._publicClipsDatas.splice(t,1),e._removeReference())},o.removeClipByName=function(e){var t=this._clipNames.indexOf(e);if(-1!==t){var n=this._clips[t];this._avatar?this._offClipAndAvatarRelateEvent(this._avatar,n):this._offGetSpriteOwnersByClipAsyncEvent(n),this._offGetClipCacheFullKeyframeIndicesEvent(n),this._clipNames.splice(t,1),this._clips.splice(t,1),this._playStartFrames.splice(t,1),this._playEndFrames.splice(t,1),this._cacheNodesSpriteOwners.splice(t,1),this._cacheNodesAvatarOwners.splice(t,1),this._cacheNodesDefaultlValues.splice(t,1),this._publicClipsDatas.splice(t,1)}},o.getClip=function(e){var t=this._clipNames.indexOf(e);return-1!==t?this._clips[t]:null},o.getClipCount=function(){return this._clips.length},o.play=function(e,t){if(void 0===t&&(t=1),!e&&-1==this._defaultClipIndex)throw new Error("Animator:must have default clip value,please set clip property.");e?(this._currentPlayClipIndex=this._clipNames.indexOf(e),this._currentPlayClip=this._clips[this._currentPlayClipIndex]):(this._currentPlayClipIndex=this._defaultClipIndex,this._currentPlayClip=this._clips[this._defaultClipIndex]),this._currentTime=0,this._currentFrameTime=0,this._elapsedPlaybackTime=0,this._playEventIndex=0,this.playbackRate=t,this._stoped=!1,this._currentFrameIndex=0,this._startUpdateLoopCount=C.loopCount,this._lastPlayAnimationClip&&this._lastPlayAnimationClip!==this._currentPlayClip&&this._revertKeyframeNodes(this._lastPlayAnimationClip,this._lastPlayAnimationClipIndex),this._updatePlayer(0),this._lastPlayAnimationClip=this._currentPlayClip,this._lastPlayAnimationClipIndex=this._currentPlayClipIndex},o.stop=function(){0!==this.playState&&(this._stoped=!0,this.event("stopped"))},o._getLinkSpritePath=function(e,t){t.unshift(e.name);var n=e._parent;n._hierarchyAnimator===this?this._getLinkSpritePath(n,t):t.shift()},o.linkSprite3DToAvatarNode=function(e,t){if(t._hierarchyAnimator===this){if(this._avatar){var n=this._avatarNodeMap[e];if(n){this._linkSpritesData=this._linkSpritesData||{};var i=[];return this._getLinkSpritePath(t,i),this._linkSpritesData[e]=i,t._isLinkSpriteToAnimationNode(this,n,!0),!0}return!1}return!1}throw"Animator:sprite3D must belong to this Animator"},o.unLinkSprite3DToAvatarNode=function(e){if(this._avatar){var t=e.transform.dummy;if(t){var n=this._avatarNodeMap[t._owner.name];return e._isLinkSpriteToAnimationNode(this,n,!1),!0}return!1}return!1},a(0,o,"playState",function(){return null==this._currentPlayClip?0:this._stoped?0:2}),a(0,o,"avatar",function(){return this._avatar},function(e){if(this._avatar!==e){var t=this._avatar;this._avatar=e;for(var n=this._clips.length,i=0;i=a&&r>=o?r:a>=o?a:o,Vt.transformCoordinate(e.center,n.worldMatrix,this._boundingSphere.center),this._boundingSphere.radius=e.radius*t},n._calculateBoundBoxByInitCorners=function(e){for(var t=this._owner.transform.worldMatrix,n=0;n<8;n++)Vt.transformCoordinate(e[n],t,tn._tempBoundBoxCorners[n]);St.createfromPoints(tn._tempBoundBoxCorners,this._boundingBox)},n._calculateBoundingSphere=function(){var e=this._owner.meshFilter.sharedMesh;null==e||null==e.boundingSphere?this._boundingSphere.toDefault():this._calculateBoundingSphereByInitSphere(e.boundingSphere)},n._calculateBoundingBox=function(){var e=this._owner.meshFilter.sharedMesh;null==e||null==e.boundingBox?this._boundingBox.toDefault():this._calculateBoundBoxByInitCorners(e.boundingBoxCorners)},n._renderUpdate=function(e){var t=this._owner.transform;if(t){this._setShaderValueMatrix4x4(0,t.worldMatrix);var n=this._owner.getProjectionViewWorldMatrix(e);this._setShaderValueMatrix4x4(1,n)}else this._setShaderValueMatrix4x4(0,At.DEFAULT),this._setShaderValueMatrix4x4(1,e);return Qt.debugMode&&this._renderRenderableBoundBox(),!0},t}(),Cn=function(e){function t(e){t.__super.call(this),this._tempRotationMatrix=new At,this._uvLength=new Ot,this._firstActiveElement=0,this._firstNewElement=0,this._firstFreeElement=0,this._firstRetiredElement=0,this._owner=e,this._ownerRender=e.particleRender,this._boundingBoxCorners=o(8,null),this._boundingSphere=new Tt(new Vt,Number.MAX_VALUE),this._boundingBox=new St(new Vt(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),new Vt(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)),this._currentTime=0,this._isEmitting=!1,this._isPlaying=!1,this._isPaused=!1,this._burstsIndex=0,this._frameRateTime=0,this._emissionTime=0,this._totalDelayTime=0,this._simulateUpdate=!1,this._bufferMaxParticles=1,this.duration=5,this.looping=!0,this.prewarm=!1,this.startDelayType=0,this.startDelay=0,this.startDelayMin=0,this.startDelayMax=0,this._startLifetimeType=0,this._startLifetimeConstant=5,this._startLifeTimeGradient=new $,this._startLifetimeConstantMin=0,this._startLifetimeConstantMax=5,this._startLifeTimeGradientMin=new $,this._startLifeTimeGradientMax=new $,this._maxStartLifetime=5,this.startSpeedType=0,this.startSpeedConstant=5,this.startSpeedConstantMin=0,this.startSpeedConstantMax=5,this.threeDStartSize=!1,this.startSizeType=0,this.startSizeConstant=1,this.startSizeConstantSeparate=new Vt(1,1,1),this.startSizeConstantMin=0,this.startSizeConstantMax=1,this.startSizeConstantMinSeparate=new Vt(0,0,0),this.startSizeConstantMaxSeparate=new Vt(1,1,1),this.threeDStartRotation=!1,this.startRotationType=0,this.startRotationConstant=0,this.startRotationConstantSeparate=new Vt(0,0,0),this.startRotationConstantMin=0,this.startRotationConstantMax=0,this.startRotationConstantMinSeparate=new Vt(0,0,0),this.startRotationConstantMaxSeparate=new Vt(0,0,0),this.randomizeRotationDirection=0,this.startColorType=0,this.startColorConstant=new Pt(1,1,1,1),this.startColorConstantMin=new Pt(1,1,1,1),this.startColorConstantMax=new Pt(1,1,1,1),this.gravityModifier=0,this.simulationSpace=1,this.scaleMode=0,this.playOnAwake=!0,this._rand=new Nt(0),this.autoRandomSeed=!0,this.randomSeed=new Uint32Array(1),this._randomSeeds=new Uint32Array(t._RANDOMOFFSET.length),this.isPerformanceMode=!0,this._emission=new Z,this._emission.enbale=!0,this._owner.on("activeinhierarchychanged",this,this._onOwnerActiveHierarchyChanged)}r(t,"laya.d3.core.particleShuriKen.ShurikenParticleSystem",e);var s=t.prototype;return n.imps(s,{"laya.d3.core.render.IRenderable":!0,"laya.d3.core.IClone":!0}),s._getVertexBuffer=function(e){return void 0===e&&(e=0),0===e?this._vertexBuffer:null},s._getIndexBuffer=function(){return this._indexBuffer},s._generateBoundingSphere=function(){var e=this._boundingSphere.center.elements;e[0]=0,e[1]=0,e[2]=0,this._boundingSphere.radius=Number.MAX_VALUE},s._generateBoundingBox=function(){var e=this._owner.particleRender,n=this._boundingBox.min,i=this._boundingBox.max,r=0,a=0,o=NaN;switch(this.startLifetimeType){case 0:o=this.startLifetimeConstant;break;case 1:o=-Number.MAX_VALUE;var s=s;for(r=0,a=s.gradientCount;r=this._bufferMaxParticles&&(this._firstActiveElement=0)}},s._freeRetiredParticles=function(){for(;this._firstRetiredElement!=this._firstActiveElement;){var e=this._drawCounter-this._vertices[this._firstRetiredElement*this._floatCountPerVertex*this._vertexStride+this._timeIndex];if(this.isPerformanceMode&&e<3)break;this._firstRetiredElement++,this._firstRetiredElement>=this._bufferMaxParticles&&(this._firstRetiredElement=0)}},s._burst=function(e,t){for(var n=0,i=this._emission._bursts,r=i.length;this._burstsIndexthis.duration){if(!this.looping){for(r=Math.min(this.maxParticles-this.aliveParticleCount,r),n=0;n0){var o=1/a;for(this._frameRateTime+=o,this._frameRateTime=this._currentTime-(this._currentTime-this._frameRateTime)%this._maxStartLifetime;this._frameRateTime<=t&&this.emit(this._frameRateTime);)this._frameRateTime+=o;this._frameRateTime=Math.floor(t/o)*o}},s._initBufferDatas=function(){this._vertexBuffer&&(this._vertexBuffer.destroy(),this._indexBuffer.destroy());var e=this._ownerRender,t=e.renderMode;if(-1!==t&&this.maxParticles>0){var n,i,r=0,a=0,o=0,s=0,l=0,h=e.mesh;if(4===t){if(h){if(h._vertexBuffers.length>1)throw new Error("ShurikenParticleSystem: submesh Count mesh be One or all subMeshes have the same vertexDeclaration.");i=mt.vertexDeclaration,this._floatCountPerVertex=i.vertexStride/4,this._startLifeTimeIndex=12,this._timeIndex=16,this._vertexStride=h._vertexBuffers[0].vertexCount;var _=this._bufferMaxParticles*this._vertexStride,u=_%65535;if(Math.floor(_/65535)+1>1)throw new Error("ShurikenParticleSystem:the maxParticleCount multiply mesh vertexCount is large than 65535.");this._vertexBuffer=Kn.create(i,u,35048),this._vertices=new Float32Array(this._floatCountPerVertex*u),this._indexStride=h._indexBuffer.indexCount;var c=h._indexBuffer.getData(),d=this._bufferMaxParticles*this._indexStride;for(this._indexBuffer=jn.create("ushort",d,35044),n=new Uint16Array(d),s=0,r=0;r=this._bufferMaxParticles&&(i=0),i===this._firstRetiredElement)return!1;le.create(this,this._ownerRender,this._owner.transform);if(this._currentTime-n>=le.startLifeTime)return!0;var r=NaN,a=NaN,o=NaN,s=NaN,l=NaN,h=NaN,_=NaN,u=this._velocityOverLifetime&&this._velocityOverLifetime.enbale;if(u){var c=this._velocityOverLifetime.velocity.type;2===c||3===c?this.autoRandomSeed?(r=Math.random(),a=Math.random(),o=Math.random()):(this._rand.seed=this._randomSeeds[9],r=this._rand.getFloat(),a=this._rand.getFloat(),o=this._rand.getFloat(),this._randomSeeds[9]=this._rand.seed):u=!1}else u=!1;var d=this._colorOverLifetime&&this._colorOverLifetime.enbale;if(d){3===this._colorOverLifetime.color.type?this.autoRandomSeed?s=Math.random():(this._rand.seed=this._randomSeeds[10],s=this._rand.getFloat(),this._randomSeeds[10]=this._rand.seed):d=!1}else d=!1;var f=this._sizeOverLifetime&&this._sizeOverLifetime.enbale;if(f){3===this._sizeOverLifetime.size.type?this.autoRandomSeed?l=Math.random():(this._rand.seed=this._randomSeeds[11],l=this._rand.getFloat(),this._randomSeeds[11]=this._rand.seed):f=!1}else f=!1;var m=this._rotationOverLifetime&&this._rotationOverLifetime.enbale;if(m){var p=this._rotationOverLifetime.angularVelocity.type;2===p||3===p?this.autoRandomSeed?h=Math.random():(this._rand.seed=this._randomSeeds[12],h=this._rand.getFloat(),this._randomSeeds[12]=this._rand.seed):m=!1}else m=!1;var v=this._textureSheetAnimation&&this._textureSheetAnimation.enable;if(v){3===this._textureSheetAnimation.frame.type?this.autoRandomSeed?_=Math.random():(this._rand.seed=this._randomSeeds[15],_=this._rand.getFloat(),this._randomSeeds[15]=this._rand.seed):v=!1}else v=!1;var g,E=this._firstFreeElement*this._floatCountPerVertex*this._vertexStride,S=le.startUVInfo[0],D=le.startUVInfo[1],T=le.startUVInfo[2],x=le.startUVInfo[3],M=e.elements,R=t.elements,A=0,I=0,y=0,C=0,N=0,w=this._ownerRender;if(4===w.renderMode){var O=w.mesh._vertexBuffers[0];g=O.getData();var V=O.vertexDeclaration;I=V.getVertexElementByUsage(0).offset/4;var P=V.getVertexElementByUsage(1);y=P?P.offset/4:-1;var L=V.getVertexElementByUsage(2);C=L?L.offset/4:-1,A=V.vertexStride/4,N=0}else{this._vertices[E+2]=T,this._vertices[E+3]=x+D;var b=E+this._floatCountPerVertex;this._vertices[b+2]=T+S,this._vertices[b+3]=x+D;var F=b+this._floatCountPerVertex;this._vertices[F+2]=T+S,this._vertices[F+3]=x;var B=F+this._floatCountPerVertex;this._vertices[B+2]=T,this._vertices[B+3]=x}for(var U=E,H=E+this._floatCountPerVertex*this._vertexStride;U0&&this._vertexBuffer.setData(this._vertices,0,0,this._firstFreeElement*this._vertexStride*this._floatCountPerVertex)),this._firstNewElement=this._firstFreeElement},s._beforeRender=function(e){return this._firstNewElement!=this._firstFreeElement&&this.addNewParticlesToVertexBuffer(),this._drawCounter++,this._firstActiveElement!=this._firstFreeElement&&(this._vertexBuffer._bind(),this._indexBuffer._bind(),!0)},s._render=function(e){var t=0,n=V.mainContext;this._firstActiveElement0&&(t=this._firstFreeElement*this._indexStride,n.drawElements(4,t,5123,0),C.trianglesFaces+=t/3,C.drawCall++))},s.play=function(){if(this._burstsIndex=0,this._isEmitting=!0,this._isPlaying=!0,this._isPaused=!1,this._emissionTime=0,this._totalDelayTime=0,!this.autoRandomSeed)for(var e=0,n=this._randomSeeds.length;e0)}),a(0,s,"shape",function(){return this._shape},function(e){this._shape!==e&&(e&&e.enable?this._ownerRender._addShaderDefine(gi.SHADERDEFINE_SHAPE):this._ownerRender._removeShaderDefine(gi.SHADERDEFINE_SHAPE),this._shape=e)}),a(0,s,"rotationOverLifetime",function(){return this._rotationOverLifetime},function(e){var t=this._ownerRender;if(e){var n=e.angularVelocity;if(!n)return;var i=n.separateAxes,r=n.type;if(e.enbale)switch(i?t._addShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE):t._addShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIME),r){case 0:t._addShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);break;case 1:t._addShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);break;case 2:t._addShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);break;case 3:t._addShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES)}else t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIME),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);switch(r){case 0:i?t._setShaderValueColor(35,n.constantSeparate):t._setShaderValueNumber(34,n.constant);break;case 1:i?(t._setShaderValueBuffer(37,n.gradientX._elements),t._setShaderValueBuffer(38,n.gradientY._elements),t._setShaderValueBuffer(39,n.gradientZ._elements),t._setShaderValueBuffer(40,n.gradientW._elements)):t._setShaderValueBuffer(36,n.gradient._elements);break;case 2:i?(t._setShaderValueColor(35,n.constantMinSeparate),t._setShaderValueColor(42,n.constantMaxSeparate)):(t._setShaderValueNumber(34,n.constantMin),t._setShaderValueNumber(41,n.constantMax));break;case 3:i?(t._setShaderValueBuffer(37,n.gradientXMin._elements),t._setShaderValueBuffer(44,n.gradientXMax._elements),t._setShaderValueBuffer(38,n.gradientYMin._elements),t._setShaderValueBuffer(45,n.gradientYMax._elements),t._setShaderValueBuffer(39,n.gradientZMin._elements),t._setShaderValueBuffer(46,n.gradientZMax._elements),t._setShaderValueBuffer(40,n.gradientWMin._elements),t._setShaderValueBuffer(47,n.gradientWMax._elements)):(t._setShaderValueBuffer(36,n.gradientMin._elements),t._setShaderValueBuffer(43,n.gradientMax._elements))}}else t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIME),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS),t._removeShaderDefine(gi.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES),t._setShaderValueColor(35,null),t._setShaderValueColor(42,null),t._setShaderValueNumber(34,void 0),t._setShaderValueNumber(41,void 0),t._setShaderValueBuffer(37,null),t._setShaderValueBuffer(44,null),t._setShaderValueBuffer(38,null),t._setShaderValueBuffer(45,null),t._setShaderValueBuffer(39,null),t._setShaderValueBuffer(46,null),t._setShaderValueBuffer(40,null),t._setShaderValueBuffer(47,null),t._setShaderValueBuffer(36,null),t._setShaderValueBuffer(43,null);this._rotationOverLifetime=e}),a(0,s,"emission",function(){return this._emission}),a(0,s,"emissionTime",function(){return this._emissionTime>this.duration?this.duration:this._emissionTime}),a(0,s,"aliveParticleCount",function(){return this._firstNewElement>=this._firstRetiredElement?this._firstNewElement-this._firstRetiredElement:this._bufferMaxParticles-this._firstRetiredElement+this._firstNewElement}),a(0,s,"isPlaying",function(){return this._isPlaying}),a(0,s,"isPaused",function(){return this._isPaused}),a(0,s,"startLifetimeType",function(){return this._startLifetimeType},function(e){var t=0,n=0;switch(this.startLifetimeType){case 0:this._maxStartLifetime=this.startLifetimeConstant;break;case 1:this._maxStartLifetime=-Number.MAX_VALUE;var i=i;for(t=0,n=i.gradientCount;t=a&&r>=o?r:a>=o?a:o,Vt.transformCoordinate(e.center,n.worldMatrix,this._boundingSphere.center),this._boundingSphere.radius=e.radius*t},i._renderUpdate=function(e){var t=this._owner.particleSystem;if(!n.stage.isVisibility||!t.isAlive)return!1;var i=this._owner.transform;switch(t.simulationSpace){case 0:break;case 1:this._setShaderValueColor(0,i.position),this._setShaderValueColor(1,i.rotation);break;default:throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.")}switch(t.scaleMode){case 0:var r=i.scale;this._setShaderValueColor(4,r),this._setShaderValueColor(5,r);break;case 1:var a=i.localScale;this._setShaderValueColor(4,a),this._setShaderValueColor(5,a);break;case 2:this._setShaderValueColor(4,i.scale),this._setShaderValueColor(5,Vt.ONE)}var o=this._finalGravity.elements,s=Zt.gravity.elements,l=t.gravityModifier;return o[0]=s[0]*l,o[1]=s[1]*l,o[2]=s[2]*l,this._setShaderValueBuffer(7,o),this._setShaderValueInt(11,t.simulationSpace),this._setShaderValueBool(8,t.threeDStartRotation),this._setShaderValueInt(6,t.scaleMode),this._setShaderValueInt(9,this.stretchedBillboardLengthScale),this._setShaderValueInt(10,this.stretchedBillboardSpeedScale),this._setShaderValueNumber(12,t._currentTime),Qt.debugMode&&this._renderRenderableBoundBox(),!0},i._destroy=function(){e.prototype._destroy.call(this),this._mesh&&(this._mesh._removeReference(),this._mesh=null)},a(0,i,"boundingBox",function(){return this._owner.particleSystem.isAlive?(this._boundingBoxNeedChange&&(this._calculateBoundingBox(),this._boundingBoxNeedChange=!1),this._boundingBox):this._defaultBoundBox}),a(0,i,"renderMode",function(){return this._renderMode},function(e){if(this._renderMode!==e){switch(this._renderMode){case 0:this._removeShaderDefine(gi.SHADERDEFINE_RENDERMODE_BILLBOARD);break;case 1:this._removeShaderDefine(gi.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);break;case 2:this._removeShaderDefine(gi.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);break;case 3:this._removeShaderDefine(gi.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);break;case 4:this._removeShaderDefine(gi.SHADERDEFINE_RENDERMODE_MESH)}switch(this._renderMode=e,e){case 0:this._addShaderDefine(gi.SHADERDEFINE_RENDERMODE_BILLBOARD);break;case 1:this._addShaderDefine(gi.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);break;case 2:this._addShaderDefine(gi.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);break;case 3:this._addShaderDefine(gi.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);break;case 4:this._addShaderDefine(gi.SHADERDEFINE_RENDERMODE_MESH);break;default:throw new Error("ShurikenParticleRender: unknown renderMode Value.")}this._owner.particleSystem._initBufferDatas()}}),a(0,i,"mesh",function(){return this._mesh},function(e){this._mesh!==e&&(this._mesh&&this._mesh._removeReference(),this._mesh=e,e&&e._addReference(),this._owner.particleSystem._initBufferDatas())}),t}(tn),wn=function(e){function t(e){this._owner=null,this._trailRenderElements=null,this._minVertexDistance=NaN,this._widthMultiplier=NaN,this._time=NaN,this._widthCurve=null,this._colorGradient=null,this._textureMode=0,this._curtime=0,this._curSubTrailFinishCurTime=0,this._curSubTrailFinished=!1,this._hasLifeSubTrail=!1,this._trailTotalLength=0,this._trailSupplementLength=0,this._trailDeadLength=0,this._isStart=!1,this._trailRenderElementIndex=0,t.__super.call(this),this._curSubTrailFinishPosition=new Vt,this._curSubTrailFinishDirection=new Vt,this._owner=e,this._trailRenderElements=[],this.addRenderElement()}r(t,"laya.d3.core.trail.TrailFilter",e);var n=t.prototype;return n.getRenderElementsCount=function(){return this._trailRenderElements.length},n.addRenderElement=function(){for(var e=0;e0&&this._updateSubTextureCoordinates(0,2*this._firstFreeElement))},i._updateSubTextureCoordinates=function(e,t){for(var n=2*e,i=0;i=this.maxSegments&&(this._firstActiveElement=0)}},i._freeRetiredGlitter=function(){for(var e=2*this._floatCountPerVertex;this._firstRetiredElement!=this._firstActiveElement;){if(this._drawCounter-this._vertices[this._firstRetiredElement*e+5]<3)break;this._firstRetiredElement++,this._firstRetiredElement>=this.maxSegments&&(this._firstRetiredElement=0)}},i._calcVelocity=function(e,t,n){Vt.subtract(e,t,n),Vt.scale(n,.5,n)},i._addNewGlitterSegementToVertexBuffer=function(){var e=0;this._firstActiveElement0&&this._vertexBuffer.setData(this._vertices,0,0,2*this._firstFreeElement*this._floatCountPerVertex)),this._firstNewElement=this._firstFreeElement},i._addGlitter=function(e,t,n){this._needPatch&&(this._needPatch=!1,this._addGlitter(this._lastPatchAddPos0,this._lastPatchAddPos1,this._lastPatchAddTime));var i=this._firstFreeElement+1;i>=this.maxSegments&&(i=0,e.cloneTo(this._lastPatchAddPos0),t.cloneTo(this._lastPatchAddPos1),this._lastPatchAddTime=n,this._needPatch=!0),i===this._firstRetiredElement&&console.log("GlitterTemplet:current segement count have large than maxSegments,please adjust the value of maxSegments or add Glitter Vertex Frequency.");var r=e.elements,a=t.elements,o=0,s=this._firstFreeElement*this._floatCountPerVertex*2;for(o=0;o<3;o++)this._vertices[s+o]=r[o];this._vertices[s+3]=0,this._vertices[s+4]=0,this._vertices[s+5]=n;var l=s+this._floatCountPerVertex;for(o=0;o<3;o++)this._vertices[l+o]=a[o];this._vertices[l+3]=0,this._vertices[l+4]=1,this._vertices[l+5]=n,this._firstFreeElement=i},i._update=function(e){this._currentTime+=e/1e3,this._retireActiveGlitter(),this._freeRetiredGlitter(),this._firstActiveElement==this._firstFreeElement&&(this._currentTime=0),this._firstRetiredElement==this._firstActiveElement&&(this._drawCounter=0),this._updateTextureCoordinates()},i._beforeRender=function(e){return this._firstNewElement!=this._firstFreeElement&&this._addNewGlitterSegementToVertexBuffer(),this._drawCounter++,this._firstActiveElement!=this._firstFreeElement&&(this._vertexBuffer.bindWithIndexBuffer(null),!0)},i._render=function(e){var t=0,n=V.mainContext;this._firstActiveElement0&&(t=2*this._firstFreeElement,n.drawArrays(5,0,t),C.trianglesFaces+=t-2,C.drawCall++))},i.addVertexPosition=function(e,t){if(this._owner.activeInHierarchy)if(this._numPositionMode<2)0===this._numPositionMode?(e.cloneTo(this._posModeLastPosition0),t.cloneTo(this._posModeLastPosition1)):(e.cloneTo(this._posModePosition0),t.cloneTo(this._posModePosition1)),this._numPositionMode++;else{var n=this._tempVector2;this._calcVelocity(e,this._posModeLastPosition0,n);var i=this._tempVector3;this._calcVelocity(t,this._posModeLastPosition1,i),this.addVertexPositionVelocity(this._posModePosition0,n,this._posModePosition1,i),this._posModePosition0.cloneTo(this._posModeLastPosition0),this._posModePosition1.cloneTo(this._posModeLastPosition1),e.cloneTo(this._posModePosition0),t.cloneTo(this._posModePosition1)}},i.addVertexPositionVelocity=function(e,t,n,i){if(this._owner.activeInHierarchy){if(0===this._numPositionVelocityMode)this._numPositionVelocityMode++;else{var r=this._tempVector0;Vt.subtract(e,this._posVelModePosition0,r);var a=Vt.scalarLength(r);Vt.subtract(n,this._posVelModePosition1,r);var o=Vt.scalarLength(r),s=0,l=l;if(a0){for(var r=0;re.y?this._leafs[t]._sizeOfY.y:e.y;var n=new Vt(this._chunkOffsetX*zt.CHUNK_GRID_NUM*this._gridSize,e.x,this._chunkOffsetZ*zt.CHUNK_GRID_NUM*this._gridSize),i=new Vt((this._chunkOffsetX+1)*zt.CHUNK_GRID_NUM*this._gridSize,e.y,(this._chunkOffsetZ+1)*zt.CHUNK_GRID_NUM*this._gridSize);zt.__ADAPT_MATRIX__&&(Vt.transformV3ToV3(n,zt.__ADAPT_MATRIX__,n),Vt.transformV3ToV3(i,zt.__ADAPT_MATRIX__,i)),this._boundingBox=new St(n,i);var r=new Vt;Vt.subtract(i,n,r),Vt.scale(r,.5,r);var a=new Vt;Vt.add(n,r,a),this._boundingSphere=new Tt(a,Vt.scalarLength(r)),this._boundingBoxCorners=o(8,null),this._boundingBox.getCorners(this._boundingBoxCorners)},s.calcLeafBoudingBox=function(e){for(var t=0;t=r.y&&r.x>=r.z?r.x:r.y>=r.z?r.y:r.z,Vt.transformCoordinate(t.center,i.worldMatrix,this._boundingSphere.center),this._boundingSphere.radius=t.radius*n,e.calcLeafBoudingSphere(i.worldMatrix,n)}},n._calculateBoundingBox=function(){var e=this._terrainSprite3DOwner.terrainFilter;if(null==e)this._boundingBox.toDefault();else{for(var t=this._terrainSprite3DOwner.transform.worldMatrix,n=e._boundingBoxCorners,i=0;i<8;i++)Vt.transformCoordinate(n[i],t,tn._tempBoundBoxCorners[i]);St.createfromPoints(tn._tempBoundBoxCorners,this._boundingBox),e.calcLeafBoudingBox(t)}},n._renderUpdate=function(e){this._setShaderValueMatrix4x4(0,this._owner.transform.worldMatrix);var t=this._owner.getProjectionViewWorldMatrix(e);return this._setShaderValueMatrix4x4(1,t),!0},n._destroy=function(){e.prototype._destroy.call(this),this._terrainSprite3DOwner=null},t}(tn),bn=function(e){function t(){this._time=0,this._enableLightCount=3,this._customRenderQueneIndex=11,this.enableLight=!0,t.__super.call(this),this._renderState=new ce,this._lights=[],this._quenes=[],this._cameraPool=[],this._renderableSprite3Ds=[],this.__loaded=!0,this._lightmaps=[],this._shaderValues=new Ht,this.parallelSplitShadowMaps=[],this._dynamicBatchManager=new Te,this._cullingRenders=[],this._cullingRendersLength=0,this.enableFog=!1,this.fogStart=300,this.fogRange=1e3,this.fogColor=new Vt(.7,.7,.7),this.ambientColor=new Vt(.212,.227,.259),V.shaderHighPrecision&&this.addShaderDefine(un.SHADERDEFINE_HIGHPRECISION),this.on("display",this,this._display),this.on("undisplay",this,this._unDisplay),this._componentsMap=[],this._typeComponentsIndices=[],this._components=[]}r(t,"laya.d3.core.scene.Scene",e);var i=t.prototype;return n.imps(i,{"laya.webgl.submit.ISubmit":!0,"laya.resource.ICreateResource":!0}),i._setUrl=function(e){this._url=e},i._getGroup=function(){return this._group},i._setGroup=function(e){this._group=e},i._display=function(){n.stage._scenes.push(this),n.stage._scenes.sort(t._sortScenes);for(var e=0,i=this._childs.length;e0)for(var n=0,i=0;i=this._enableLightCount);i++);},i._updateChilds=function(e){for(var t=0,n=this._childs.length;t=0&&this._lights.splice(t,1)},i._updateScene=function(){var e=this._renderState;this._prepareUpdateToRenderState(V.mainContext,e),this._updateComponents(e),this._updateChilds(e),this._lateUpdateComponents(e),this._time+=e.elapsedTime/1e3,this._shaderValues.setValue(22,this._time)},i._updateSceneConch=function(){var e=this._renderState;this._prepareUpdateToRenderState(V.mainContext,e),this._updateComponents(e),this._lateUpdateComponents(e),this._prepareSceneToRender(e);for(var t=0,n=this._cameraPool.length;t1)for(var l=0;l=0&&t<=this._childs.length){if(e._parent===this){var n=this.getChildIndex(e);this._childs.splice(n,1),this._childs.splice(t,0,e),this.conchModel&&(this.conchModel.removeChild(e.conchModel),this.conchModel.addChildAt(e.conchModel,t)),this._childChanged()}else e.parent&&e.parent.removeChild(e),this._childs===T.ARRAY_EMPTY&&(this._childs=[]),this._childs.splice(t,0,e),this.conchModel&&this.conchModel.addChildAt(e.conchModel,t),e.parent=this,this._addChild3D(e);return e}throw new Error("appendChildAt:The index is out of bounds")},i.addChild=function(e){if(!(e instanceof laya.d3.core.Sprite3D))throw new Error("Sprite3D:Node type must Sprite3D.");if(!e||this.destroyed||e===this)return e;if(e.zOrder&&this._set$P("hasZorder",!0),e._parent===this){var t=this.getChildIndex(e);t!==this._childs.length-1&&(this._childs.splice(t,1),this._childs.push(e),this.conchModel&&(this.conchModel.removeChild(e.conchModel),this.conchModel.addChildAt(e.conchModel,this._childs.length-1)),this._childChanged())}else e.parent&&e.parent.removeChild(e),this._childs===T.ARRAY_EMPTY&&(this._childs=[]),this._childs.push(e),this.conchModel&&this.conchModel.addChildAt(e.conchModel,this._childs.length-1),e.parent=this,this._childChanged(),this._addChild3D(e);return e},i.removeChildAt=function(e){var t=this.getChildAt(e);return t&&(this._removeChild3D(t),this._childs.splice(e,1),this.conchModel&&this.conchModel.removeChild(t.conchModel),t.parent=null),t},i.removeChildren=function(e,t){if(void 0===e&&(e=0),void 0===t&&(t=2147483647),this._childs&&this._childs.length>0){var n=this._childs;if(0===e&&t>=a){var i=n;this._childs=T.ARRAY_EMPTY}else i=n.splice(e,t-e);for(var r=0,a=i.length;r0&&e.addRenderObject(this)},i.renderSubmit=function(){var e=V.mainContext,t=this._renderState;this._set3DRenderConfig(e),this._prepareSceneToRender(this._renderState);var n,i=0,r=0;if(Qt.debugMode||de.debugMode)for(i=0,r=this._cameraPool.length;i=0;s--){var l=n[s];if(!(l>i))break;n[s]=--l}r._destroy()},i._getComponentByType=function(e,t){void 0===t&&(t=0);var n=this._componentsMap.indexOf(e);return-1===n?null:this._components[this._typeComponentsIndices[n][t]]},i._getComponentsByType=function(e,t){var n=this._componentsMap.indexOf(e);if(-1!==n){var i=this._typeComponentsIndices[n],r=i.length;t.length=r;for(var a=0;a=0;d--){var f=r[d];if(!(f>a))break;r[d]=--f}o._destroy()},i._clearSelfRenderObjects=function(){},i._addSelfRenderObjects=function(){},i._parseCustomProps=function(e,t,n,i){},i._updateChilds=function(e){var t=this._childs.length;if(0!==t)for(var n=0;n=0&&t<=this._childs.length){if(e._parent===this){var n=this.getChildIndex(e);this._childs.splice(n,1),this._childs.splice(t,0,e),this.conchModel&&(this.conchModel.removeChild(e.conchModel),this.conchModel.addChildAt(e.conchModel,t)),this._childChanged()}else e.parent&&e.parent.removeChild(e),this._childs===T.ARRAY_EMPTY&&(this._childs=[]),this._childs.splice(t,0,e),this.conchModel&&this.conchModel.addChildAt(e.conchModel,t),e.parent=this,this._addChild3D(e);return e}throw new Error("appendChildAt:The index is out of bounds")},i.addChild=function(e){if(!(e instanceof laya.d3.core.Sprite3D))throw new Error("Sprite3D:Node type must Sprite3D.");if(!e||this.destroyed||e===this)return e;if(e.zOrder&&this._set$P("hasZorder",!0),e._parent===this){var t=this.getChildIndex(e);t!==this._childs.length-1&&(this._childs.splice(t,1),this._childs.push(e),this.conchModel&&(this.conchModel.removeChild(e.conchModel),this.conchModel.addChildAt(e.conchModel,this._childs.length-1)),this._childChanged())}else e.parent&&e.parent.removeChild(e),this._childs===T.ARRAY_EMPTY&&(this._childs=[]),this._childs.push(e),this.conchModel&&this.conchModel.addChildAt(e.conchModel,this._childs.length-1),e.parent=this,this._childChanged(),this._addChild3D(e);return e},i.removeChildAt=function(e){var t=this.getChildAt(e);return t&&(this._removeChild3D(t),this._childs.splice(e,1),this.conchModel&&this.conchModel.removeChild(t.conchModel),t.parent=null),t},i.removeChildren=function(e,t){if(void 0===e&&(e=0),void 0===t&&(t=2147483647),this._childs&&this._childs.length>0){var n=this._childs;if(0===e&&t>=a){var i=n;this._childs=T.ARRAY_EMPTY}else i=n.splice(e,t-e);for(var r=0,a=i.length;r0&&(i.name=i.name.substr(0,i.name.length-3),i.isArray=!0,i.location=n.getUniformLocation(this._program,i.name)),this._uniformParams.push(i)}for(r=0,a=this._attributeParams.length;r7)throw new Error("Shader3D: shader support textures max count is 8,can't large than it.");return a[0]=this._curActTexIndex,r.uniform1i(e.location,this._curActTexIndex),r.activeTexture(t._TEXTURES[this._curActTexIndex]),i&&P.bindTexture(r,3553,i),this._curActTexIndex++,1}return r.activeTexture(t._TEXTURES[a[0]]),i&&P.bindTexture(r,3553,i),0},n._uniform_samplerCube=function(e,n){var i=n.source||n.defaulteTexture.source,r=V.mainContext,a=e.uploadedValue;if(null==a[0]){if(this._curActTexIndex>7)throw new Error("Shader3D: shader support textures max count is 8,can't large than it.");return a[0]=this._curActTexIndex,r.uniform1i(e.location,this._curActTexIndex),r.activeTexture(t._TEXTURES[this._curActTexIndex]),i?P.bindTexture(r,34067,i):P.bindTexture(r,34067,si.grayTexture.source),this._curActTexIndex++,1}return r.activeTexture(t._TEXTURES[a[0]]),i?P.bindTexture(r,34067,i):P.bindTexture(r,34067,si.grayTexture.source),0},n._noSetValue=function(e){console.log("no....:"+e.name)},n.bind=function(){return u.activeShader=this,u.bindShader=this,this.activeResource(),P.UseProgram(this._program)},n.uploadAttributes=function(e,t){for(var n,i,r=0,a=0,o=this._attributeParamsMap.length;a>>16,e=(1431655765&e)<<1|(2863311530&e)>>>1,e=(858993459&e)<<2|(3435973836&e)>>>2,e=(252645135&e)<<4|(4042322160&e)>>>4,e=(16711935&e)<<8|(4278255360&e)>>>8,t[0]=e,2.3283064365386963e-10*t[0]}(e)},o.createHammersleyTex=function(e,t){var n=new Uint8Array(e*t*4),i=0,r=0;for(r=0;ra&&(i=a);for(var o=0;or&&(i=r);for(var a=0;a=i,a=r?this.currentFrameIndex:-1;if(-1===a||this._lastFrameIndex!==a){var o=this.currentAnimationClipIndex,s=this._templet.getNodes(o),l=this._templet._animationDatasCache;if(r){var h=this._templet.getAnimationDataWithCache(i,l,o,a);if(h)return this._curAnimationDatas=h,this._lastFrameIndex=a,void this._effectAnimation(s)}var _=16*s.length;r?this._curAnimationDatas=new Float32Array(_):(this._tempCurAnimationData||(this._tempCurAnimationData=new Float32Array(_)),this._curAnimationDatas=this._tempCurAnimationData),this._curOriginalData||(this._curOriginalData=new Float32Array(this._templet.getTotalkeyframesLength(o))),r?this._templet.getOriginalData(o,this._curOriginalData,this._player._fullFrames[o],a,this._player.currentFrameTime):this._templet.getOriginalDataUnfixedRate(o,this._curOriginalData,this._player.currentPlayTime),qt._computeRootAnimationData(s,this._curOriginalData,this._curAnimationDatas),r&&this._templet.setAnimationDataWithCache(i,l,o,a,this._curAnimationDatas),this._lastFrameIndex=a,this._effectAnimation(s)}}},i._unload=function(t){e.prototype._unload.call(this,t),this._animationSprites=null,this._animationSpritesInitLocalMatrix=null,this._tempCurAnimationData=null,this._curOriginalData=null,this._curAnimationDatas=null},a(0,i,"url",null,function(e){console.log("Warning: discard property,please use templet property instead.");var t=n.loader.create(e,null,null,l);this._templet!==t&&(0!==this._player.state&&this._player.stop(!0),this._templet=t,this._player.templet=t,this._curOriginalData=null,this._curAnimationDatas=null,this._tempCurAnimationData=null,this._templet._animationDatasCache||(this._templet._animationDatasCache=[]),this.event("animationchanged",this))}),a(0,i,"templet",e.prototype._$get_templet,function(e){this._templet!==e&&(0!==this._player.state&&this._player.stop(!0),this._templet=e,this._player.templet=e,this._curOriginalData=null,this._curAnimationDatas=null,this._tempCurAnimationData=null,this._templet._animationDatasCache||(this._templet._animationDatasCache=[]),this.event("animationchanged",this))})}(Tn),function(e){function t(){this._tempCurAnimationData=null,this._tempCurBonesData=null,this._curOriginalData=null,this._lastFrameIndex=-1,this._curMeshAnimationData=null,this._curBonesDatas=null,this._curAnimationDatas=null,this._ownerMesh=null,this._boneIndexToMeshList=null,this._oldVersion=!1,t.__super.call(this),this._boneIndexToMeshList=[]}r(t,"laya.d3.component.animation.SkinAnimations",e);var i=t.prototype;return i._computeBoneIndexToMeshOnTemplet=function(){this._templet.loaded?this._computeBoneIndexToMeshOnMesh():this._templet.once("loaded",this,this._computeBoneIndexToMeshOnMesh)},i._computeBoneIndexToMeshOnMesh=function(){"LAYAANIMATION:02"===this._templet._aniVersion?this._oldVersion=!1:this._oldVersion=!0;var e=this._owner.meshFilter.sharedMesh;e.loaded?this._computeBoneIndexToMesh(e):e.on("loaded",this,this._computeBoneIndexToMesh)},i._computeBoneIndexToMesh=function(e){var t=e._boneNames;if(t)for(var n=t.length,i=this._templet._anis,r=0,a=i.length;r=a,s=o?this.currentFrameIndex:-1;if(-1===s||this._lastFrameIndex!==s){var l=this.currentAnimationClipIndex,h=this._templet._animationDatasCache[0],_=this._templet._animationDatasCache[1];if(o){var u=this._getAnimationDatasWithCache(a,i,_,l,s);if(u)return this._curAnimationDatas=u,this._curBonesDatas=this._templet.getAnimationDataWithCache(a,h,l,s),void(this._lastFrameIndex=s)}var c=!1;o&&(this._curBonesDatas=this._templet.getAnimationDataWithCache(a,h,l,s),c=!!this._curBonesDatas);var d=this._templet.getNodes(l),f=16*d.length,m=i.InverseAbsoluteBindPoses;this._oldVersion?this._curMeshAnimationData||(this._curMeshAnimationData=new Float32Array(f)):this._curMeshAnimationData||(this._curMeshAnimationData=new Float32Array(16*m.length));var p,v,g=0,E=0,S=0,D=i.getSubMeshCount();if(o){for(this._curAnimationDatas=[],this._curAnimationDatas.length=D,g=0;g=n.y&&n.x>=n.z?n.x:n.y>=n.z?n.y:n.z,Vt.transformCoordinate(this._originalBoundSphere.center,t.worldMatrix,this._transformBoundSphere.center),this._transformBoundSphere.radius=this._originalBoundSphere.radius*e,this._needUpdate=!1}},n._onWorldMatrixChanged=function(){this._needUpdate=!0;for(var e in this._runtimeCollisonMap)this._runtimeCollisonTestMap[e]=!0,this._runtimeCollisonMap[e]._runtimeCollisonTestMap[this.id]=!0},n._initialize=function(e){laya.d3.component.Component3D.prototype._initialize.call(this,e),this._originalBoundSphere=new Tt(new Vt(0,0,0),.5),this._transformBoundSphere=new Tt(new Vt(0,0,0),.5),e.transform.on("worldmatrixneedchanged",this,this._onWorldMatrixChanged),this._needUpdate=!0},n._getType=function(){return 0},n._collisonTo=function(e){switch(e._getType()){case 0:return 0!==xt.sphereContainsSphere(this.boundSphere,e.boundSphere);case 1:return 0!==e.boundBox.containsSphere(this.boundSphere);case 2:var t=e;if(0!==xt.sphereContainsBox(this.boundSphere,t._boundBox)){for(var n=t.mesh._positions,i=0,r=n.length;i0&&(this._buffer=null),this.memorySize=m?i*r*4*(1+1/3):i*r*4,this._recreateLock=!1},o.recreateResource=function(){if(this._buffer||null!=this._src&&""!==this._src)if(this._needReleaseAgain=!1,this._buffer||this._mipmaps){if(this._recreateLock)return;this._createWebGlTexture(),this.completeCreate()}else{this._recreateLock=!0}},o.onAsynLoaded=function(e,t,n){var i;n&&(i=n[0].call(this,t)),i&&(this._width=i.width,this._height=i.height,this._buffer=i.data),this._src=e,this._size=new Kt(this._width,this._height),this._conchTexture?alert("怎么给runtime传递datatexture数据"):this.activeResource(),this._endLoaded()},o.getPixels=function(){return new Uint8Array(this._buffer)},o.disposeResource=function(){this._recreateLock&&(this._needReleaseAgain=!0),this._source&&(V.mainContext.deleteTexture(this._source),this._source=null,this._buffer=null,this.memorySize=0)},a(0,o,"src",function(){return this._src}),t.create=function(e,n,i,r,a,o){if(void 0===r&&(r=9729),void 0===a&&(a=9729),void 0===o&&(o=!0),!e||e.byteLengthe.byteLength)throw"load mipmaps data size error ";var s=new Uint8Array(e,a,o);if(this._mipmaps.push(s),a+=o,1==i&&1==r)break;r/=2,(i/=2)<1&&(i=1),r<1&&(r=1)}return null}]);if(laya.d3.resource.DataTexture2D.lodasatlas){s.simLodInfo=new Float32Array(40);for(var l=0;le[t].renderingOrder){var i=e[n];e[n]=e[t],e[t]=i}},o._calculateProjectionMatrix=function(){},o._onScreenSizeChanged=function(){this._calculateProjectionMatrix()},o._prepareCameraToRender=function(){k._currentCameraCullingMask=this.cullingMask;var e=this._shaderValues;e.setValue(0,this.transform.position.elements),e.setValue(5,this.forward.elements),e.setValue(6,this.up.elements)},o._prepareCameraViewProject=function(e,t){var n=this._shaderValues;n.setValue(1,e.elements),n.setValue(2,t.elements)},o._renderCamera=function(e,t,n){},o.addLayer=function(e){29!==e.number&&30!=e.number&&(this.cullingMask=this.cullingMask|e.mask)},o.removeLayer=function(e){29!==e.number&&30!=e.number&&(this.cullingMask=this.cullingMask&~e.mask)},o.addAllLayers=function(){this.cullingMask=2147483647},o.removeAllLayers=function(){this.cullingMask=0|k.getLayerByNumber(29).mask|k.getLayerByNumber(30).mask},o.ResetProjectionMatrix=function(){this._useUserProjectionMatrix=!1,this._calculateProjectionMatrix()},o.moveForward=function(e){this._tempVector3.elements[0]=this._tempVector3.elements[1]=0,this._tempVector3.elements[2]=e,this.transform.translate(this._tempVector3)},o.moveRight=function(e){this._tempVector3.elements[1]=this._tempVector3.elements[2]=0,this._tempVector3.elements[0]=e,this.transform.translate(this._tempVector3)},o.moveVertical=function(e){this._tempVector3.elements[0]=this._tempVector3.elements[2]=0,this._tempVector3.elements[1]=e,this.transform.translate(this._tempVector3,!1)},o._addSelfRenderObjects=function(){var e=this.scene._cameraPool,t=e.length;if(t>0){for(var n=t-1;n>=0;n--)if(this.renderingOrder<=e[n].renderingOrder){e.splice(n+1,0,this);break}}else e.push(this),this.scene.conchModel&&this.scene.conchModel.setCurrentCamera(this.conchModel)},o._clearSelfRenderObjects=function(){var e=this.scene._cameraPool;e.splice(e.indexOf(this),1)},o.destroy=function(t){void 0===t&&(t=!0),this._sky&&this._sky.destroy(),this.renderTarget=null,n.stage.off("resize",this,this._onScreenSizeChanged),e.prototype.destroy.call(this,t)},a(0,o,"sky",function(){return this._sky},function(e){this._sky=e,e._ownerCamera=this}),a(0,o,"forward",function(){var e=this.transform.worldMatrix.elements,t=this._forward.elements;return t[0]=-e[8],t[1]=-e[9],t[2]=-e[10],this._forward}),a(0,o,"position",function(){var e=this.transform.worldMatrix.elements,t=this._position.elements;return t[0]=e[12],t[1]=e[13],t[2]=e[14],this._position}),a(0,o,"renderTarget",function(){return this._renderTarget},function(e){this._renderTarget=e,null!=e&&(this._renderTargetSize=e.size)}),a(0,o,"up",function(){var e=this.transform.worldMatrix.elements,t=this._up.elements;return t[0]=e[4],t[1]=e[5],t[2]=e[6],this._up}),a(0,o,"right",function(){var e=this.transform.worldMatrix.elements,t=this._right.elements;return t[0]=e[0],t[1]=e[1],t[2]=e[2],this._right}),a(0,o,"renderTargetSize",function(){return this._renderTargetSize},function(e){null!=this.renderTarget&&this._renderTargetSize,this._renderTargetSize=e,this._calculateProjectionMatrix()}),a(0,o,"fieldOfView",function(){return this._fieldOfView},function(e){this._fieldOfView=e,this._calculateProjectionMatrix()}),a(0,o,"nearPlane",function(){return this._nearPlane},function(e){this._nearPlane=e,this._calculateProjectionMatrix()}),a(0,o,"farPlane",function(){return this._farPlane},function(e){this._farPlane=e,this._calculateProjectionMatrix()}),a(0,o,"orthographic",function(){return this._orthographic},function(e){this._orthographic=e,this._calculateProjectionMatrix()}),a(0,o,"orthographicVerticalSize",function(){return this._orthographicVerticalSize},function(e){this._orthographicVerticalSize=e,this._calculateProjectionMatrix()}),a(0,o,"renderingOrder",function(){return this._renderingOrder},function(e){this._renderingOrder=e,this._sortCamerasByRenderingOrder()}),t.CAMERAPOS=0,t.VIEWMATRIX=1,t.PROJECTMATRIX=2,t.VPMATRIX=3,t.VPMATRIX_NO_TRANSLATE=4,t.CAMERADIRECTION=5,t.CAMERAUP=6,t.ENVIRONMENTDIFFUSE=7,t.ENVIRONMENTSPECULAR=8,t.SIMLODINFO=9,t.DIFFUSEIRRADMATR=10,t.DIFFUSEIRRADMATG=11,t.DIFFUSEIRRADMATB=12,t.HDREXPOSURE=13,t.RENDERINGTYPE_DEFERREDLIGHTING="DEFERREDLIGHTING",t.RENDERINGTYPE_FORWARDRENDERING="FORWARDRENDERING",t.CLEARFLAG_SOLIDCOLOR=0,t.CLEARFLAG_SKY=1,t.CLEARFLAG_DEPTHONLY=2,t.CLEARFLAG_NONE=3,i(t,["_invertYScaleMatrix",function(){return this._invertYScaleMatrix=new At(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1)},"_invertYProjectionMatrix",function(){return this._invertYProjectionMatrix=new At},"_invertYProjectionViewMatrix",function(){return this._invertYProjectionViewMatrix=new At}]),t}(Fn),ci=function(e){function t(e){this._render=null,this._geometryFilter=null,t.__super.call(this,e)}r(t,"laya.d3.core.RenderableSprite3D",e);var n=t.prototype;return n._addToInitStaticBatchManager=function(){},n._setBelongScene=function(t){e.prototype._setBelongScene.call(this,t),t._renderableSprite3Ds.push(this),this._render._applyLightMapParams()},n._setUnBelongScene=function(){var t=this._scene._renderableSprite3Ds,n=t.indexOf(this);t.splice(n,1),this._render._removeShaderDefine(laya.d3.core.RenderableSprite3D.SAHDERDEFINE_LIGHTMAP),e.prototype._setUnBelongScene.call(this)},n._update=function(e){e.owner=this,this._activeInHierarchy&&(this._updateComponents(e),this._render._updateOctreeNode(),this._lateUpdateComponents(e),C.spriteCount++,this._childs.length&&this._updateChilds(e))},n.destroy=function(t){void 0===t&&(t=!0),e.prototype.destroy.call(this,t),this._render._destroy(),this._render=null},t.__init__=function(){t.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV=t.shaderDefines.registerDefine("SCALEOFFSETLIGHTINGMAPUV"),t.SAHDERDEFINE_LIGHTMAP=t.shaderDefines.registerDefine("LIGHTMAP")},t.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV=2,t.SAHDERDEFINE_LIGHTMAP=4,t.LIGHTMAPSCALEOFFSET=2,t.LIGHTMAP=3,i(t,["shaderDefines",function(){return this.shaderDefines=new Bt}]),t}(Fn),di=function(e){function t(){this._intensityColor=null,this._intensity=NaN,this._shadow=!1,this._shadowFarPlane=0,this._shadowMapSize=0,this._shadowMapCount=0,this._shadowMapPCFType=0,this._parallelSplitShadowMap=null,this._lightmapBakedType=0,this.color=null,t.__super.call(this),this._intensity=1,this._intensityColor=new Vt,this.color=new Vt(1,1,1),this._shadow=!1,this._shadowFarPlane=8,this._shadowMapSize=512,this._shadowMapCount=1,this._shadowMapPCFType=0,this._lightmapBakedType=t.LIGHTMAPBAKEDTYPE_REALTIME}r(t,"laya.d3.core.light.LightSprite",Fn);var n=t.prototype;return n._parseCustomProps=function(e,t,n,i){var r=n.color,a=this.color.elements;a[0]=r[0],a[1]=r[1],a[2]=r[2]},n._addSelfRenderObjects=function(){this.lightmapBakedType!==t.LIGHTMAPBAKEDTYPE_BAKED&&this._scene._addLight(this)},n._clearSelfRenderObjects=function(){this.lightmapBakedType!==t.LIGHTMAPBAKEDTYPE_BAKED&&this._scene._removeLight(this)},n._prepareToScene=function(e){return!1},a(0,n,"lightmapBakedType",function(){return this._lightmapBakedType},function(e){this._lightmapBakedType!==e&&(this._lightmapBakedType=e,this._activeInHierarchy&&(e!==t.LIGHTMAPBAKEDTYPE_BAKED?this._scene._addLight(this):this._scene._removeLight(this)))}),a(0,n,"shadowPCFType",function(){return this._shadowMapPCFType},function(e){this._shadowMapPCFType=e,this._parallelSplitShadowMap&&this._parallelSplitShadowMap.setPCFType(e)}),a(0,n,"intensity",function(){return this._intensity},function(e){this._intensity=e}),a(0,n,"shadow",function(){return this._shadow},function(e){throw new Error("LightSprite: must override it.")}),a(0,n,"shadowDistance",function(){return this._shadowFarPlane},function(e){this._shadowFarPlane=e,this._parallelSplitShadowMap&&this._parallelSplitShadowMap.setFarDistance(e)}),a(0,n,"shadowPSSMCount",function(){return this._shadowMapCount},function(e){this._shadowMapCount=e,this._parallelSplitShadowMap&&(this._parallelSplitShadowMap.PSSMNum=e)}),a(0,n,"shadowResolution",function(){return this._shadowMapSize},function(e){this._shadowMapSize=e,this._parallelSplitShadowMap&&this._parallelSplitShadowMap.setShadowMapTextureSize(e)}),a(0,n,"diffuseColor",function(){return console.log("LightSprite: discard property,please use color property instead."),this.color},function(e){console.log("LightSprite: discard property,please use color property instead."),this.color=e}),t.LIGHTMAPBAKEDTYPE_REALTIME=0,t.LIGHTMAPBAKEDTYPE_MIXED=1,t.LIGHTMAPBAKEDTYPE_BAKED=2,t}(),fi=function(e){function t(e){this._terrainRes=null,this._lightmapScaleOffset=null,t.__super.call(this),this._lightmapScaleOffset=new Pt(1,1,0,0),e&&(this._terrainRes=e,e.loaded?this.buildTerrain(e):e.once("loaded",this,this.buildTerrain))}r(t,"laya.d3.terrain.Terrain",Fn);var i=t.prototype;return i._parseCustomProps=function(e,t,n,i){this.terrainRes=E.getRes(t[n.dataPath]);var r=n.lightmapIndex;null!=r&&this.setLightmapIndex(r);var a=n.lightmapScaleOffset;a&&this.setLightmapScaleOffset(new Pt(a[0],a[1],a[2],a[3]))},i.setLightmapIndex=function(e){for(var t=0;t0?e._detailTextureInfos[l.detailID[h][0]].diffuseTexture:null,c=_>1?e._detailTextureInfos[l.detailID[h][1]].diffuseTexture:null,d=_>2?e._detailTextureInfos[l.detailID[h][2]].diffuseTexture:null,f=_>3?e._detailTextureInfos[l.detailID[h][3]].diffuseTexture:null,m=_>0?e._detailTextureInfos[l.detailID[h][0]].scale:null,p=_>1?e._detailTextureInfos[l.detailID[h][1]].scale:null,v=_>2?e._detailTextureInfos[l.detailID[h][2]].scale:null,g=_>3?e._detailTextureInfos[l.detailID[h][3]].scale:null;s.buildRenderElementAndMaterial(_,l.normalMap,l.alphaMap[h],u,c,d,f,e._materialInfo.ambientColor,e._materialInfo.diffuseColor,e._materialInfo.specularColor,m?m.x:1,m?m.y:1,p?p.x:1,p?p.y:1,v?v.x:1,v?v.y:1,g?g.x:1,g?g.y:1)}s.terrainRender.receiveShadow=!0,s.terrainRender.lightmapScaleOffset=this._lightmapScaleOffset,this.addChild(s)}},i.width=function(){return this._terrainRes._chunkNumX*zt.CHUNK_GRID_NUM*this._terrainRes._gridSize},i.depth=function(){return this._terrainRes._chunkNumZ*zt.CHUNK_GRID_NUM*this._terrainRes._gridSize},i.getHeightXZ=function(e,n){if(!this._terrainRes||!this._terrainRes.loaded)return NaN;if(e-=this.transform.position.x,n-=this.transform.position.z,t.__VECTOR3__||(t.__VECTOR3__=new Vt),t.__VECTOR3__.elements[0]=e,t.__VECTOR3__.elements[1]=0,t.__VECTOR3__.elements[2]=n,Vt.transformV3ToV3(t.__VECTOR3__,zt.__ADAPT_MATRIX_INV__,t.__VECTOR3__),e=t.__VECTOR3__.elements[0],n=t.__VECTOR3__.elements[2],e<0||e>this.width()||n<0||n>this.depth())return NaN;var i=this._terrainRes._gridSize,r=parseInt(""+e/i),a=parseInt(""+n/i),o=e-r*i,s=n-a*i,l=NaN,h=NaN,_=NaN,u=NaN,c=NaN,d=this._terrainRes._heightData;return o+s>i?(l=d._terrainHeightData[(a+1-1)*d._width+r+1],h=d._terrainHeightData[(a+1-1)*d._width+r],_=d._terrainHeightData[(a-1)*d._width+r+1],u=(i-o)/i,c=(i-s)/i,l+(h-l)*u+(_-l)*c):(l=d._terrainHeightData[Math.max(0,a-1)*d._width+r],h=d._terrainHeightData[Math.min(d._width*d._height-1,(a+1-1)*d._width+r)],_=d._terrainHeightData[Math.min(d._width*d._height-1,Math.max(0,a-1)*d._width+r+1)],u=o/i,c=s/i,l+(h-l)*c+(_-l)*u)},a(0,i,"terrainRes",null,function(e){e&&(this._terrainRes=e,e.loaded?this.buildTerrain(e):e.once("loaded",this,this.buildTerrain))}),t.load=function(e){return n.loader.create(e,null,null,t,null,1,!1)},t.RENDER_LINE_MODEL=!1,t.LOD_TOLERANCE_VALUE=4,t.LOD_DISTANCE_FACTOR=2,t.__VECTOR3__=null,t}(),mi=(function(e){function t(e,n,i){this._long=NaN,this._width=NaN,this._height=NaN,void 0===e&&(e=1),void 0===n&&(n=1),void 0===i&&(i=1),t.__super.call(this),this._long=e,this._width=n,this._height=i,this.activeResource(),this._positions=this._getPositions(),this._generateBoundingObject()}r(t,"laya.d3.resource.models.BoxMesh",ii);var n=t.prototype;n.recreateResource=function(){this._numberVertices=24,this._numberIndices=36;var e=Qe.vertexDeclaration,t=(e.vertexStride,this._long/2),n=this._height/2,i=this._width/2,r=new Float32Array([-t,n,-i,0,1,0,0,0,t,n,-i,0,1,0,1,0,t,n,i,0,1,0,1,1,-t,n,i,0,1,0,0,1,-t,-n,-i,0,-1,0,0,1,t,-n,-i,0,-1,0,1,1,t,-n,i,0,-1,0,1,0,-t,-n,i,0,-1,0,0,0,-t,n,-i,-1,0,0,0,0,-t,n,i,-1,0,0,1,0,-t,-n,i,-1,0,0,1,1,-t,-n,-i,-1,0,0,0,1,t,n,-i,1,0,0,1,0,t,n,i,1,0,0,0,0,t,-n,i,1,0,0,0,1,t,-n,-i,1,0,0,1,1,-t,n,i,0,0,1,0,0,t,n,i,0,0,1,1,0,t,-n,i,0,0,1,1,1,-t,-n,i,0,0,1,0,1,-t,n,-i,0,0,-1,1,0,t,n,-i,0,0,-1,0,0,t,-n,-i,0,0,-1,0,1,-t,-n,-i,0,0,-1,1,1]),a=new Uint16Array([0,1,2,2,3,0,4,7,6,6,5,4,8,9,10,10,11,8,12,15,14,14,13,12,16,17,18,18,19,16,20,23,22,22,21,20]);this._vertexBuffer=new Kn(e,this._numberVertices,35044,!0),this._indexBuffer=new jn("ushort",this._numberIndices,35044,!0),this._vertexBuffer.setData(r),this._indexBuffer.setData(a),this.memorySize=2*(this._vertexBuffer._byteLength+this._indexBuffer._byteLength),this.completeCreate()},a(0,n,"long",function(){return this._long},function(e){this._long!==e&&(this._long=e,this.releaseResource(),this.activeResource())}),a(0,n,"width",function(){return this._width},function(e){this._width!==e&&(this._width=e,this.releaseResource(),this.activeResource())}),a(0,n,"height",function(){return this._height},function(e){this._height!==e&&(this._height=e,this.releaseResource(),this.activeResource())})}(),function(e){function t(e,n,i,r){this._radius=NaN,this._height=NaN,this._slices=0,this._stacks=0,void 0===e&&(e=.5),void 0===n&&(n=2),void 0===i&&(i=16),void 0===r&&(r=32),t.__super.call(this),this._radius=e,this._height=n<2*e?2*e:n,this._stacks=i,this._slices=r,this.recreateResource(),this._positions=this._getPositions(),this._generateBoundingObject()}r(t,"laya.d3.resource.models.CapsuleMesh",ii);var n=t.prototype;n.recreateResource=function(){this._numberVertices=(this._stacks+1)*(this.slices+1)*2+2*(this._slices+1),this._numberIndices=3*this._stacks*(this._slices+1)*2*2+2*this._slices*3;var e=Qe.vertexDeclaration,t=e.vertexStride/4,n=new Float32Array(this._numberVertices*t),i=new Uint16Array(this._numberIndices),r=Math.PI/2/this._stacks,a=2*Math.PI/this._slices,o=this._height/2-this._radius,s=0,l=0,h=0,_=0,u=0,c=0,d=0,f=0;for(d=0;d<=this._stacks;d++)for(f=0;f<=this._slices;f++)s=this._radius*Math.cos(d*r)*Math.cos(f*a+Math.PI),l=this._radius*Math.sin(d*r),h=this._radius*Math.cos(d*r)*Math.sin(f*a+Math.PI),n[_++]=s,n[_++]=l+o,n[_++]=h,n[_++]=s,n[_++]=l,n[_++]=h,n[_++]=1-f/this._slices,n[_++]=(1-d/this._stacks)*(Math.PI*this._radius/2/(this._height+Math.PI*this._radius)),d1&&(e.width=1-e.x,console.warn("Camera: viewport.width + viewport.x must less than 1.0.")),e.y+e.height>1&&(e.height=1-e.y,console.warn("Camera: viewport.height + viewport.y must less than 1.0.")),this._viewportExpressedInClipSpace=!0,this._normalizedViewport=e,this._calculateProjectionMatrix()}),a(0,o,"projectionMatrix",function(){return this._projectionMatrix},function(e){this._projectionMatrix=e,this._useUserProjectionMatrix=!0}),a(0,o,"viewMatrix",function(){return this.transform.worldMatrix.invert(this._viewMatrix),this._viewMatrix}),i(t,["_tempVector20",function(){return this._tempVector20=new Ot}]),t}()),pi=(function(e){function t(){t.__super.call(this),this._render=new An(this),this._render.on("materialchanged",this,this._onMaterialChanged);var e=new Gn;this._render.sharedMaterial=e,this._geometryFilter=new Vn(this),e.renderMode=8,this._changeRenderObject(0)}r(t,"laya.d3.core.glitter.Glitter",e);var n=t.prototype;n._changeRenderObject=function(e){var t=this._render._renderElements,n=t[e];n||(n=t[e]=new _e),n._render=this._render;var i=this._render.sharedMaterials[e];i||(i=Gn.defaultMaterial);var r=this._geometryFilter;return n._mainSortID=0,n._sprite3D=this,n.renderObj=r,n._material=i,n},n._onMaterialChanged=function(e,t,n){t1||e.x+e.height>1)throw new Error("VRCamera: viewport size invalid.","value");this._viewportExpressedInClipSpace=!0,this._leftNormalizedViewport=new Lt(0,0,e.width/2,e.height),this._rightNormalizedViewport=new Lt(e.width/2,0,e.width/2,e.height),this._calculateProjectionMatrix()}),a(0,n,"leftViewport",function(){if(this._viewportExpressedInClipSpace){var e=this._leftNormalizedViewport,t=this.renderTargetSize,n=t.width,i=t.height;this._leftViewport.x=e.x*n,this._leftViewport.y=e.y*i,this._leftViewport.width=e.width*n,this._leftViewport.height=e.height*i}return this._leftViewport}),a(0,n,"needLeftViewport",function(){var e=this.leftNormalizedViewport;return 0===e.x&&0===e.y&&1===e.width&&1===e.height}),a(0,n,"needRightViewport",function(){var e=this.rightNormalizedViewport;return 0===e.x&&0===e.y&&1===e.width&&1===e.height}),a(0,n,"leftViewMatrix",function(){var e=this._calculatePupilOffset(),t=this._tempMatrix;this.transform.worldMatrix.cloneTo(t);var n=t.elements;return n[12]-=e[0],n[13]-=e[1],n[14]-=e[2],t.invert(this._leftViewMatrix),this._leftViewMatrix}),a(0,n,"rightViewMatrix",function(){var e=this._calculatePupilOffset(),t=this._tempMatrix;this.transform.worldMatrix.cloneTo(t);var n=t.elements;return n[12]+=e[0],n[13]+=e[1],n[14]+=e[2],t.invert(this._rightViewMatrix),this._rightViewMatrix}),a(0,n,"leftProjectionMatrix",function(){return this._leftProjectionMatrix}),a(0,n,"leftProjectionViewMatrix",function(){return At.multiply(this.leftProjectionMatrix,this.leftViewMatrix,this._leftProjectionViewMatrix),this._leftProjectionViewMatrix}),a(0,n,"rightProjectionMatrix",function(){return this._rightProjectionMatrix}),a(0,n,"rightProjectionViewMatrix",function(){return At.multiply(this.rightProjectionMatrix,this.rightViewMatrix,this._rightProjectionViewMatrix),this._rightProjectionViewMatrix}),a(0,n,"leftBoundFrustum",function(){return this._leftBoundFrustumUpdate&&(this._leftBoundFrustum.matrix=this.leftProjectionViewMatrix),this._leftBoundFrustum})}(),function(e){function t(){t.__super.call(this),this._geometryFilter=new wn(this),this._render=new On(this),this._changeRenderObjectsByMaterial(this._render,0,Qn.defaultMaterial),this._render.on("materialchanged",this,this._changeRenderObjectsByMaterial),this._geometryFilter.on("trailfilterchange",this,this._changeRenderObjectsByRenderElement)}r(t,"laya.d3.core.trail.TrailSprite3D",e);var n=t.prototype;return n._changeRenderObjectsByMaterial=function(e,t,n){var i=this._geometryFilter.getRenderElementsCount();this._render._renderElements.length=i;for(var r=0;r