UNPKG

@awayjs/renderer

Version:
1 lines 144 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@awayjs/core"),require("@awayjs/stage"),require("@awayjs/view")):"function"==typeof define&&define.amd?define(["exports","@awayjs/core","@awayjs/stage","@awayjs/view"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AwayjsRenderer={},e.AwayjsCore,e.AwayjsStage,e.AwayjsView)}(this,(function(e,t,i,n){"use strict";var s=function(){function e(e,n,s,r){this._blendFactor=[i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ZERO],this._blendEquation=[i.ContextGLBlendEquation.ADD,i.ContextGLBlendEquation.ADD],this._invalidProgram=!0,this._animationVertexCode="",this._animationFragmentCode="",this._vertexCode="",this._fragmentCode="",this._postAnimationFragmentCode="",this.usesBlending=!1,this.useImageRect=!1,this.usesCurves=!1,this.depthCompareMode=i.ContextGLCompareMode.LESS_EQUAL,this.writeDepth=!0,this._defaultCulling=i.ContextGLTriangleFace.BACK,this._pInverseSceneMatrix=new Float32Array(16),this.ambientR=255,this.ambientG=255,this.ambientB=255,this.usesGlobalPosFragment=!1,this.usesPositionFragment=!1,this.imageIndices=new Array,this.id=t.UUID.Next(),this._renderElements=e,this._renderMaterial=n,this._pass=s,this._stage=r,this._view=e.renderer.view,this.profile=this._stage.profile}return Object.defineProperty(e.prototype,"view",{get:function(){return this._view},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this._stage},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pass",{get:function(){return this._pass},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"renderMaterial",{get:function(){return this._renderMaterial},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"programData",{get:function(){return this._invalidProgram&&this._updateProgram(),this._programData},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"usesAnimation",{get:function(){return this._usesAnimation},set:function(e){this._usesAnimation!=e&&(this._usesAnimation=e,this.invalidateProgram())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numUsedVertexConstants",{get:function(){return this._invalidProgram&&this._updateProgram(),this._numUsedVertexConstants},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numUsedFragmentConstants",{get:function(){return this._invalidProgram&&this._updateProgram(),this._numUsedFragmentConstants},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numUsedStreams",{get:function(){return this._invalidProgram&&this._updateProgram(),this._numUsedStreams},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"numUsedTextures",{get:function(){return this._invalidProgram&&this._updateProgram(),this._numUsedTextures},enumerable:!1,configurable:!0}),e.prototype.requestAbstraction=function(t){var i=e._store[t.assetType];return i.length?i.pop():new e._abstractionClassPool[t.assetType]},e.prototype.storeAbstraction=function(t){e._store[t.asset.assetType].push(t)},e.registerAbstraction=function(t,i){e._abstractionClassPool[i.assetType]=t,e._store[i.assetType]=[]},e.prototype._includeDependencies=function(){this._renderMaterial.renderElements._includeDependencies(this),this._pass._includeDependencies(this)},e.prototype.reset=function(){this.projectionDependencies=0,this.normalDependencies=0,this.colorDependencies=0,this.viewDirDependencies=0,this.uvDependencies=0,this.secondaryUVDependencies=0,this.globalPosDependencies=0,this.tangentDependencies=0,this.usesCommonData=!1,this.usesGlobalPosFragment=!1,this.usesPositionFragment=!1,this.usesFragmentAnimation=!1,this.usesTangentSpace=!1,this.outputsNormals=!1,this.outputsTangentNormals=!1},e.prototype.setBlendMode=function(e){switch(this.usesBlending=!0,this.usesPremultipliedAlpha=!0,this._blendEquation=[0,0],e){case i.BlendMode.NORMAL:this._blendFactor=[i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ZERO],this.usesBlending=!1,this.usesPremultipliedAlpha=!1;break;case i.BlendMode.LAYER:this._blendFactor=[i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE_MINUS_SOURCE_ALPHA];break;case i.BlendMode.MULTIPLY:this._blendFactor=[i.ContextGLBlendFactor.DESTINATION_COLOR,i.ContextGLBlendFactor.ONE_MINUS_SOURCE_ALPHA,i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE_MINUS_SOURCE_ALPHA];break;case i.BlendMode.ADD:this._blendFactor=[i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE];break;case i.BlendMode.SCREEN:this._blendFactor=[i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE_MINUS_SOURCE_COLOR,i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE_MINUS_SOURCE_ALPHA];break;case i.BlendMode.SUBTRACT:this._blendFactor=[i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE,i.ContextGLBlendFactor.ONE],this._blendEquation=[i.ContextGLBlendEquation.SUBTRACT,i.ContextGLBlendEquation.ADD];break;case i.BlendMode.ALPHA:this._blendFactor=[i.ContextGLBlendFactor.ZERO,i.ContextGLBlendFactor.SOURCE_ALPHA],this.usesPremultipliedAlpha=!1;break;default:throw new t.ArgumentError("Unsupported blend mode: ".concat(e))}},e.prototype._activate=function(){if(!this.programData.program){this.programData.program=this._stage.context.createProgram();var e=(new i.AGALMiniAssembler).assemble("part vertex 1\n"+this.programData.vertexString+"endpart").vertex,t=(new i.AGALMiniAssembler).assemble("part fragment 1\n"+this.programData.fragmentString+"endpart").fragment;this.programData.program.upload(e,t)}if(this._stage.context.setProgram(this.programData.program),this._stage.context.setCulling(this.useBothSides?i.ContextGLTriangleFace.NONE:this._defaultCulling,this._view.projection.coordinateSystem),!this.usesTangentSpace&&this.cameraPositionIndex>=0){var n=this._view.projection.transform.matrix3D.position;this.vertexConstantData[this.cameraPositionIndex]=n.x,this.vertexConstantData[this.cameraPositionIndex+1]=n.y,this.vertexConstantData[this.cameraPositionIndex+2]=n.z}this._stage.context.setDepthTest(this.writeDepth&&!this.usesBlending,this.depthCompareMode),this._stage.context.setBlendEquation(this._blendEquation[0],this._blendEquation[1]),this._stage.context.setBlendFactors(this._blendFactor[0],this._blendFactor[1],this._blendFactor[2],this._blendFactor[3]),this.activeElements=null},e.prototype._deactivate=function(){this._stage.context.setDepthTest(!0,i.ContextGLCompareMode.LESS_EQUAL),this.activeElements=null},e.prototype._setRenderState=function(e){var t,i=e.entity.node;if(i.container.animator&&i.container.animator.setRenderState(this,e),this.usesUVTransform){var n=e.uvMatrix;n?(t=n.rawData,this.vertexConstantData[this.uvMatrixIndex]=t[0],this.vertexConstantData[this.uvMatrixIndex+1]=t[2],this.vertexConstantData[this.uvMatrixIndex+3]=t[4],this.vertexConstantData[this.uvMatrixIndex+4]=t[1],this.vertexConstantData[this.uvMatrixIndex+5]=t[3],this.vertexConstantData[this.uvMatrixIndex+7]=t[5]):(this.vertexConstantData[this.uvMatrixIndex]=1,this.vertexConstantData[this.uvMatrixIndex+1]=0,this.vertexConstantData[this.uvMatrixIndex+3]=0,this.vertexConstantData[this.uvMatrixIndex+4]=0,this.vertexConstantData[this.uvMatrixIndex+5]=1,this.vertexConstantData[this.uvMatrixIndex+7]=0)}if(this.usesColorTransform){var s=i.getColorTransform();s?(t=s._rawData,this.fragmentConstantData[this.colorTransformIndex]=t[0],this.fragmentConstantData[this.colorTransformIndex+1]=t[1],this.fragmentConstantData[this.colorTransformIndex+2]=t[2],this.fragmentConstantData[this.colorTransformIndex+3]=t[3],this.fragmentConstantData[this.colorTransformIndex+4]=t[4]/255,this.fragmentConstantData[this.colorTransformIndex+5]=t[5]/255,this.fragmentConstantData[this.colorTransformIndex+6]=t[6]/255,this.fragmentConstantData[this.colorTransformIndex+7]=t[7]/255):(this.fragmentConstantData[this.colorTransformIndex]=1,this.fragmentConstantData[this.colorTransformIndex+1]=1,this.fragmentConstantData[this.colorTransformIndex+2]=1,this.fragmentConstantData[this.colorTransformIndex+3]=1,this.fragmentConstantData[this.colorTransformIndex+4]=0,this.fragmentConstantData[this.colorTransformIndex+5]=0,this.fragmentConstantData[this.colorTransformIndex+6]=0,this.fragmentConstantData[this.colorTransformIndex+7]=0)}if(this.sceneNormalMatrixIndex>=0&&this.sceneNormalMatrix.copyFrom(i.getInverseMatrix3D()),this.usesTangentSpace&&this.cameraPositionIndex>=0){i.getInverseMatrix3D().copyRawDataTo(this._pInverseSceneMatrix);var r=this._view.projection.transform.matrix3D.position,a=r.x,o=r.y,h=r.z;this.vertexConstantData[this.cameraPositionIndex]=this._pInverseSceneMatrix[0]*a+this._pInverseSceneMatrix[4]*o+this._pInverseSceneMatrix[8]*h+this._pInverseSceneMatrix[12],this.vertexConstantData[this.cameraPositionIndex+1]=this._pInverseSceneMatrix[1]*a+this._pInverseSceneMatrix[5]*o+this._pInverseSceneMatrix[9]*h+this._pInverseSceneMatrix[13],this.vertexConstantData[this.cameraPositionIndex+2]=this._pInverseSceneMatrix[2]*a+this._pInverseSceneMatrix[6]*o+this._pInverseSceneMatrix[10]*h+this._pInverseSceneMatrix[14]}},e.prototype.invalidateProgram=function(){this._invalidProgram=!0},e.prototype.dispose=function(){this._programData.dispose(),this._programData=null,this._registerCache.dispose(),this._registerCache=null,this._sharedRegisters=null},e.prototype._updateProgram=function(){if(this._invalidProgram=!1,this._sharedRegisters=new i.ShaderRegisterData,this._registerCache=new i.ShaderRegisterCache(this.profile),this.reset(),this._includeDependencies(),this._initRegisterIndices(),this._compileDependencies(),this._vertexCode+=this._pass._getVertexCode(this._registerCache,this._sharedRegisters),this._fragmentCode+=this._pass._getFragmentCode(this._registerCache,this._sharedRegisters),this._postAnimationFragmentCode+=this._pass._getPostAnimationFragmentCode(this._registerCache,this._sharedRegisters),this.usesPremultipliedAlpha){var e=this._sharedRegisters.shadedTarget;this._postAnimationFragmentCode+="mul ".concat(e,".xyz, ").concat(e,", ").concat(e,".w\n")}this._postAnimationFragmentCode+="mov ".concat(this._registerCache.fragmentOutputRegister,", ").concat(this._sharedRegisters.shadedTarget,"\n"),this._registerCache.removeFragmentTempUsage(this._sharedRegisters.shadedTarget),this._compileAnimationCode(),this._initConstantData();var t=this._stage.getProgramData(this._animationVertexCode+this._vertexCode,this._fragmentCode+this._animationFragmentCode+this._postAnimationFragmentCode);this._programData!=t&&(this._programData&&this._programData.dispose(),this._programData=t,t.usages++)},e.prototype._initRegisterIndices=function(){this.commonsDataIndex=-1,this.cameraPositionIndex=-1,this.curvesIndex=-1,this.uvIndex=-1,this.uvMatrixIndex=-1,this.colorTransformIndex=-1,this.secondaryUVIndex=-1,this.normalIndex=-1,this.colorBufferIndex=-1,this.tangentIndex=-1,this.sceneMatrixIndex=-1,this.sceneNormalMatrixIndex=-1,this.jointIndexIndex=-1,this.jointWeightIndex=-1,this.imageIndices.length=0,this._sharedRegisters.animatedPosition=this._registerCache.getFreeVertexVectorTemp(),this._registerCache.addVertexTempUsages(this._sharedRegisters.animatedPosition,1),this._sharedRegisters.animatableAttributes.push(this._registerCache.getFreeVertexAttribute()),this._sharedRegisters.animationTargetRegisters.push(this._sharedRegisters.animatedPosition),this._vertexCode="",this._fragmentCode="",this._postAnimationFragmentCode="",(this.usesCommonData||this.normalDependencies>0)&&(this._sharedRegisters.commons=this._registerCache.getFreeFragmentConstant(),this.commonsDataIndex=4*this._sharedRegisters.commons.index),(this.tangentDependencies>0||this.outputsNormals)&&(this._sharedRegisters.tangentInput=this._registerCache.getFreeVertexAttribute(),this.tangentIndex=this._sharedRegisters.tangentInput.index,this._sharedRegisters.animatedTangent=this._registerCache.getFreeVertexVectorTemp(),this._registerCache.addVertexTempUsages(this._sharedRegisters.animatedTangent,1),this.usesTangentSpace&&(this._sharedRegisters.bitangent=this._registerCache.getFreeVertexVectorTemp(),this._registerCache.addVertexTempUsages(this._sharedRegisters.bitangent,1)),this._sharedRegisters.animatableAttributes.push(this._sharedRegisters.tangentInput),this._sharedRegisters.animationTargetRegisters.push(this._sharedRegisters.animatedTangent)),this.normalDependencies>0&&(this._sharedRegisters.normalInput=this._registerCache.getFreeVertexAttribute(),this.normalIndex=this._sharedRegisters.normalInput.index,this._sharedRegisters.animatedNormal=this._registerCache.getFreeVertexVectorTemp(),this._registerCache.addVertexTempUsages(this._sharedRegisters.animatedNormal,1),this._sharedRegisters.animatableAttributes.push(this._sharedRegisters.normalInput),this._sharedRegisters.animationTargetRegisters.push(this._sharedRegisters.animatedNormal)),this.uvDependencies>0&&(this._sharedRegisters.uvInput=this._registerCache.getFreeVertexAttribute(),this.uvIndex=this._sharedRegisters.uvInput.index,this.usesUVTransform||(this._sharedRegisters.animatedUV=this._registerCache.getFreeVertexVectorTemp(),this._registerCache.addVertexTempUsages(this._sharedRegisters.animatedUV,1))),this._sharedRegisters.shadedTarget=this._registerCache.getFreeFragmentVectorTemp(),this._registerCache.addFragmentTempUsages(this._sharedRegisters.shadedTarget,1)},e.prototype._compileDependencies=function(){this.colorDependencies>0&&this._compileColorCode(),this.globalPosDependencies>0&&this._compileGlobalPositionCode(),this.usesPositionFragment&&this._compilePositionCode(),this.usesCurves&&this._compileCurvesCode(),this.usesColorTransform&&this._compileColorTransformCode(),this.uvDependencies>0&&this._compileUVCode(),this.secondaryUVDependencies>0&&this._compileSecondaryUVCode(),this.normalDependencies>0&&this._compileNormalCode(),this.viewDirDependencies>0&&this._compileViewDirCode(),this._vertexCode+=this._renderElements._getVertexCode(this,this._registerCache,this._sharedRegisters),this._fragmentCode+=this._renderElements._getFragmentCode(this,this._registerCache,this._sharedRegisters)},e.prototype._initConstantData=function(){var e=this._registerCache,i=this._numUsedVertexConstants=e.numUsedVertexConstants,n=this._numUsedFragmentConstants=e.numUsedFragmentConstants;if(this._numUsedStreams=e.numUsedStreams,this._numUsedTextures=e.numUsedTextures,this.vertexConstantData&&this.vertexConstantData.length===4*i||(this.vertexConstantData=new Float32Array(4*i)),this.fragmentConstantData&&this.fragmentConstantData.length===4*n||(this.fragmentConstantData=new Float32Array(4*this._registerCache.numUsedFragmentConstants)),this.viewMatrixIndex>=0){var s=new Float32Array(this.vertexConstantData.buffer,4*this.viewMatrixIndex,16);this.viewMatrix?this.viewMatrix._rawData=s:this.viewMatrix=new t.Matrix3D(s)}else this.viewMatrix&&(this.viewMatrix=null);if(this.sceneMatrixIndex>=0){s=new Float32Array(this.vertexConstantData.buffer,4*this.sceneMatrixIndex,16);this.sceneMatrix?this.sceneMatrix._rawData=s:this.sceneMatrix=new t.Matrix3D(s)}else this.sceneMatrix&&(this.sceneMatrix=null);if(this.commonsDataIndex>=0&&(this.fragmentConstantData[this.commonsDataIndex]=.5,this.fragmentConstantData[this.commonsDataIndex+1]=0,this.fragmentConstantData[this.commonsDataIndex+2]=1/255,this.fragmentConstantData[this.commonsDataIndex+3]=1),this.uvMatrixIndex>=0&&(this.vertexConstantData[this.uvMatrixIndex]=1,this.vertexConstantData[this.uvMatrixIndex+1]=0,this.vertexConstantData[this.uvMatrixIndex+2]=0,this.vertexConstantData[this.uvMatrixIndex+3]=0,this.vertexConstantData[this.uvMatrixIndex+4]=0,this.vertexConstantData[this.uvMatrixIndex+5]=1,this.vertexConstantData[this.uvMatrixIndex+6]=0,this.vertexConstantData[this.uvMatrixIndex+7]=0),this.colorTransformIndex>=0&&(this.fragmentConstantData[this.colorTransformIndex]=1,this.fragmentConstantData[this.colorTransformIndex+1]=1,this.fragmentConstantData[this.colorTransformIndex+2]=1,this.fragmentConstantData[this.colorTransformIndex+3]=1,this.fragmentConstantData[this.colorTransformIndex+4]=0,this.fragmentConstantData[this.colorTransformIndex+5]=0,this.fragmentConstantData[this.colorTransformIndex+6]=0,this.fragmentConstantData[this.colorTransformIndex+7]=0),this.sceneNormalMatrixIndex>=0){s=new Float32Array(this.vertexConstantData.buffer,4*this.sceneNormalMatrixIndex,16);this.sceneNormalMatrix?this.sceneNormalMatrix._rawData=s:this.sceneNormalMatrix=new t.Matrix3D(s)}else this.sceneNormalMatrix&&(this.sceneNormalMatrix=null);this.cameraPositionIndex>=0&&(this.vertexConstantData[this.cameraPositionIndex+3]=1),this._pass._initConstantData(),this._usesAnimation&&this._renderMaterial.animationSet.doneAGALCode(this)},e.prototype._compileColorCode=function(){this._sharedRegisters.colorInput=this._registerCache.getFreeVertexAttribute(),this.colorBufferIndex=this._sharedRegisters.colorInput.index,this._sharedRegisters.colorVarying=this._registerCache.getFreeVarying(),this._vertexCode+="mov ".concat(this._sharedRegisters.colorVarying,", ").concat(this._sharedRegisters.colorInput,"\n")},e.prototype._compileGlobalPositionCode=function(){var e=this._sharedRegisters.globalPositionVertex=this._registerCache.getFreeVertexVectorTemp();this._registerCache.addVertexTempUsages(e,this.globalPosDependencies);var t=this._registerCache.getFreeVertexConstant();this._registerCache.getFreeVertexConstant(),this._registerCache.getFreeVertexConstant(),this._registerCache.getFreeVertexConstant(),this.sceneMatrixIndex=4*t.index;var i=this._sharedRegisters;this._vertexCode+="m44 ".concat(i.globalPositionVertex,", ").concat(i.animatedPosition,", ").concat(t,"\n"),this.usesGlobalPosFragment&&(i.globalPositionVarying=this._registerCache.getFreeVarying(),this._vertexCode+="mov ".concat(i.globalPositionVarying,", ").concat(i.globalPositionVertex,"\n"))},e.prototype._compilePositionCode=function(){var e=this._sharedRegisters;e.positionVarying=this._registerCache.getFreeVarying(),this._vertexCode+="mov ".concat(e.positionVarying,", ").concat(e.animatedPosition,"\n")},e.prototype._compileCurvesCode=function(){var e=this._sharedRegisters;e.curvesInput=this._registerCache.getFreeVertexAttribute(),this.curvesIndex=e.curvesInput.index,e.curvesVarying=this._registerCache.getFreeVarying(),this._vertexCode+="mov "+e.curvesVarying+", "+e.curvesInput+"\n";var t=this._registerCache.getFreeFragmentSingleTemp();this._fragmentCode+="mul "+t+", "+e.curvesVarying+".y, "+e.curvesVarying+".y\nsub "+t+", "+t+", "+e.curvesVarying+".z\nmul "+t+", "+t+", "+e.curvesVarying+".x\nkil "+t+"\n"},e.prototype._compileColorTransformCode=function(){var e=this._registerCache.getFreeFragmentConstant(),t=this._registerCache.getFreeFragmentConstant(),i=this._sharedRegisters.shadedTarget;this.colorTransformIndex=4*e.index,this._postAnimationFragmentCode+="mul "+i+", "+i+", "+e+"\n",this._postAnimationFragmentCode+="add "+i+", "+i+", "+t+"\n"},e.prototype._compileUVCode=function(){var e=this._sharedRegisters;if(e.uvVarying=this._registerCache.getFreeVarying(),this.usesUVTransform){var t=this._registerCache.getFreeVertexConstant(),i=this._registerCache.getFreeVertexConstant();this.uvMatrixIndex=4*t.index,this._vertexCode+="dp4 "+e.uvVarying+".x, "+e.uvInput+", "+t+"\ndp4 "+e.uvVarying+".y, "+e.uvInput+", "+i+"\nmov "+e.uvVarying+".zw, "+e.uvInput+".zw \n"}else this._vertexCode+="mov "+e.uvVarying+", "+e.animatedUV+"\n"},e.prototype._compileSecondaryUVCode=function(){var e=this._registerCache.getFreeVertexAttribute(),t=this._sharedRegisters;this.secondaryUVIndex=e.index,t.secondaryUVVarying=this._registerCache.getFreeVarying(),this._vertexCode+="mov "+t.secondaryUVVarying+", "+e+"\n"},e.prototype._compileViewDirCode=function(){var e=this._registerCache.getFreeVertexConstant(),t=this._sharedRegisters;if(t.viewDirVarying=this._registerCache.getFreeVarying(),t.viewDirFragment=this._registerCache.getFreeFragmentVectorTemp(),this._registerCache.addFragmentTempUsages(t.viewDirFragment,this.viewDirDependencies),this.cameraPositionIndex=4*e.index,this.usesTangentSpace){var i=this._registerCache.getFreeVertexVectorTemp();this._vertexCode+="sub "+i+", "+e+", "+t.animatedPosition+"\nm33 "+t.viewDirVarying+".xyz, "+i+", "+t.animatedTangent+"\nmov "+t.viewDirVarying+".w, "+t.animatedPosition+".w\n"}else this._vertexCode+="sub "+t.viewDirVarying+", "+e+", "+t.globalPositionVertex+"\n",this._registerCache.removeVertexTempUsage(this._sharedRegisters.globalPositionVertex);this._fragmentCode+="nrm "+t.viewDirFragment+".xyz, "+t.viewDirVarying+"\nmov "+t.viewDirFragment+".w, "+t.viewDirVarying+".w\n"},e.prototype._compileNormalCode=function(){var e,t=this._sharedRegisters;if(t.normalFragment=this._registerCache.getFreeFragmentVectorTemp(),this._registerCache.addFragmentTempUsages(t.normalFragment,this.normalDependencies),this.outputsNormals&&!this.outputsTangentNormals)return this._vertexCode+=this._pass._getNormalVertexCode(this._registerCache,t),void(this._fragmentCode+=this._pass._getNormalFragmentCode(this._registerCache,t));if(this.outputsNormals&&this.usesTangentSpace||((e=new Array(3))[0]=this._registerCache.getFreeVertexConstant(),e[1]=this._registerCache.getFreeVertexConstant(),e[2]=this._registerCache.getFreeVertexConstant(),this._registerCache.getFreeVertexConstant(),this.sceneNormalMatrixIndex=4*e[0].index,t.normalVarying=this._registerCache.getFreeVarying()),this.outputsNormals)if(this.usesTangentSpace)this._vertexCode+="nrm "+t.animatedNormal+".xyz, "+t.animatedNormal+"\nnrm "+t.animatedTangent+".xyz, "+t.animatedTangent+"\ncrs "+t.bitangent+".xyz, "+t.animatedNormal+", "+t.animatedTangent+"\n",this._fragmentCode+=this._pass._getNormalFragmentCode(this._registerCache,t);else{t.tangentVarying=this._registerCache.getFreeVarying(),t.bitangentVarying=this._registerCache.getFreeVarying();var i=this._registerCache.getFreeVertexVectorTemp();this._vertexCode+="m33 "+i+".xyz, "+t.animatedNormal+", "+e[0]+"\nnrm "+t.animatedNormal+".xyz, "+i+"\nm33 "+i+".xyz, "+t.animatedTangent+", "+e[0]+"\nnrm "+t.animatedTangent+".xyz, "+i+"\nmov "+t.tangentVarying+".x, "+t.animatedTangent+".x \nmov "+t.tangentVarying+".z, "+t.animatedNormal+".x \nmov "+t.tangentVarying+".w, "+t.normalInput+".w \nmov "+t.bitangentVarying+".x, "+t.animatedTangent+".y \nmov "+t.bitangentVarying+".z, "+t.animatedNormal+".y \nmov "+t.bitangentVarying+".w, "+t.normalInput+".w \nmov "+t.normalVarying+".x, "+t.animatedTangent+".z \nmov "+t.normalVarying+".z, "+t.animatedNormal+".z \nmov "+t.normalVarying+".w, "+t.normalInput+".w \ncrs "+i+".xyz, "+t.animatedNormal+", "+t.animatedTangent+"\nmov "+t.tangentVarying+".y, "+i+".x \nmov "+t.bitangentVarying+".y, "+i+".y \nmov "+t.normalVarying+".y, "+i+".z \n",this._registerCache.removeVertexTempUsage(t.animatedTangent);var n=this._registerCache.getFreeFragmentVectorTemp();this._registerCache.addFragmentTempUsages(n,1);var s=this._registerCache.getFreeFragmentVectorTemp();this._registerCache.addFragmentTempUsages(s,1);var r=this._registerCache.getFreeFragmentVectorTemp();this._registerCache.addFragmentTempUsages(r,1),this._fragmentCode+="nrm "+n+".xyz, "+t.tangentVarying+"\nmov "+n+".w, "+t.tangentVarying+".w\t\nnrm "+s+".xyz, "+t.bitangentVarying+"\nnrm "+r+".xyz, "+t.normalVarying+"\n",this._fragmentCode+=this._pass._getNormalFragmentCode(this._registerCache,t)+"m33 "+t.normalFragment+".xyz, "+t.normalFragment+", "+n+"\nmov "+t.normalFragment+".w, "+t.normalVarying+".w\n",this._registerCache.removeFragmentTempUsage(s),this._registerCache.removeFragmentTempUsage(n),this._registerCache.removeFragmentTempUsage(r)}else this._vertexCode+="m33 "+t.normalVarying+".xyz, "+t.animatedNormal+", "+e[0]+"\nmov "+t.normalVarying+".w, "+t.animatedNormal+".w\n",this._fragmentCode+="nrm "+t.normalFragment+".xyz, "+t.normalVarying+"\nmov "+t.normalFragment+".w, "+t.normalVarying+".w\n",this.tangentDependencies>0&&(t.tangentVarying=this._registerCache.getFreeVarying(),this._vertexCode+="m33 "+t.tangentVarying+".xyz, "+t.animatedTangent+", "+e[0]+"\nmov "+t.tangentVarying+".w, "+t.animatedTangent+".w\n");this.usesTangentSpace||this._registerCache.removeVertexTempUsage(t.animatedNormal)},e.prototype._compileAnimationCode=function(){this._animationVertexCode="",this._animationFragmentCode="";var e=this._sharedRegisters;if(this._usesAnimation){var t=this._renderMaterial.animationSet;this._animationVertexCode+=t.getAGALVertexCode(this,this._registerCache,e),this.uvDependencies>0&&!this.usesUVTransform&&(this._animationVertexCode+=t.getAGALUVCode(this,this._registerCache,e)),this.usesFragmentAnimation&&(this._animationFragmentCode+=t.getAGALFragmentCode(this,this._registerCache,e.shadedTarget))}else{for(var i=e.animatableAttributes.length,n=0;n<i;++n)this._animationVertexCode+="mov "+e.animationTargetRegisters[n]+", "+e.animatableAttributes[n]+"\n";this.uvDependencies>0&&!this.usesUVTransform&&(this._animationVertexCode+="mov "+e.animatedUV+","+e.uvInput+"\n")}},e.prototype.setVertexConst=function(e,t,i,n,s){void 0===t&&(t=0),void 0===i&&(i=0),void 0===n&&(n=0),void 0===s&&(s=0),e*=4,this.vertexConstantData[e++]=t,this.vertexConstantData[e++]=i,this.vertexConstantData[e++]=n,this.vertexConstantData[e]=s},e.prototype.setVertexConstFromArray=function(e,t){e*=4;for(var i=0;i<t.length;i++)this.vertexConstantData[e++]=t[i]},e.prototype.setVertexConstFromMatrix=function(e,t){e*=4;var i=t._rawData;this.vertexConstantData[e++]=i[0],this.vertexConstantData[e++]=i[4],this.vertexConstantData[e++]=i[8],this.vertexConstantData[e++]=i[12],this.vertexConstantData[e++]=i[1],this.vertexConstantData[e++]=i[5],this.vertexConstantData[e++]=i[9],this.vertexConstantData[e++]=i[13],this.vertexConstantData[e++]=i[2],this.vertexConstantData[e++]=i[6],this.vertexConstantData[e++]=i[10],this.vertexConstantData[e++]=i[14],this.vertexConstantData[e++]=i[3],this.vertexConstantData[e++]=i[7],this.vertexConstantData[e++]=i[11],this.vertexConstantData[e]=i[15]},e.prototype.setFragmentConst=function(e,t,i,n,s){void 0===t&&(t=0),void 0===i&&(i=0),void 0===n&&(n=0),void 0===s&&(s=0),e*=4,this.fragmentConstantData[e++]=t,this.fragmentConstantData[e++]=i,this.fragmentConstantData[e++]=n,this.fragmentConstantData[e]=s},e._store={},e._abstractionClassPool=new Object,e}(),r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},r(e,t)};function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}"function"==typeof SuppressedError&&SuppressedError;var o,h=function(e){function t(t,i){var n=e.call(this,t)||this;return n._pass=i,n}return a(t,e),Object.defineProperty(t.prototype,"pass",{get:function(){return this._pass},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new t(this.type,this._pass)},t.INVALIDATE="invalidatePass",t}(t.EventBase),l=function(e){function t(t,i){var n=e.call(this,t)||this;return n._material=i,n}return a(t,e),Object.defineProperty(t.prototype,"material",{get:function(){return this._material},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new t(this.type,this._material)},t.INVALIDATE_TEXTURES="invalidateTextures",t.INVALIDATE_PASSES="invalidatePasses",t}(t.EventBase),c=function(e){function n(){var t=e.call(this)||this;return t._passes=[],t._invalidAnimation=!0,t._invalidRender=!0,t._invalidImages=!0,t._imageIndices={},t._usesAnimation=!1,t.images=[],t.samplers=[],t.requiresBlending=!1,t._onInvalidateTexturesDelegate=function(e){return t.onInvalidateTextures(e)},t._onInvalidatePassesDelegate=function(e){return t.onInvalidatePasses(e)},t._onPassInvalidateDelegate=function(e){return t.onPassInvalidate(e)},t}return a(n,e),Object.defineProperty(n.prototype,"animationSet",{get:function(){return this._animationSet},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"material",{get:function(){return this._asset},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"numImages",{get:function(){return this._invalidImages&&this._updateImages(),this._numImages},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"renderOrderId",{get:function(){return this._invalidRender&&this._pUpdateRender(),this._invalidAnimation&&this._updateAnimation(),this._renderOrderId},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"numPasses",{get:function(){return this._invalidAnimation&&this._updateAnimation(),this._passes.length},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"style",{get:function(){return this._asset.style},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"renderElements",{get:function(){return this._useWeak?this._pool.deref():this._pool},enumerable:!1,configurable:!0}),n.prototype.init=function(i,n){e.prototype.init.call(this,i,n,!0),this.materialID=i.id,this._stage=n.stage,n.addMaterial(this),this._owners=new t.WeakAssetSet("_Render_RenderableBase"),this._asset.addEventListener(l.INVALIDATE_TEXTURES,this._onInvalidateTexturesDelegate),this._asset.addEventListener(l.INVALIDATE_PASSES,this._onInvalidatePassesDelegate)},n.prototype.activatePass=function(e){var t;for(this._activePass=this._passes[e],t=this._activePass.shader.numUsedStreams;t<this._stage.numUsedStreams;t++)this._stage.context.setVertexBufferAt(t,null);for(t=this._activePass.shader.numUsedTextures;t<this._stage.numUsedTextures;t++)this._stage.context.setTextureAt(t,null);this._activePass._activate(this.renderElements.renderer.view)},n.prototype.deactivatePass=function(){this._activePass._deactivate(),this._stage.numUsedStreams=this._activePass.shader.numUsedStreams,this._stage.numUsedTextures=this._activePass.shader.numUsedTextures},n.prototype.addOwner=function(e){var t;this._owners.add(e);var i=e.entity.node.container.animator;if(i&&(t=i.animationSet),e.entity.node.container.animator){if(this._animationSet&&t!=this._animationSet)throw new Error("A Material instance cannot be shared across material owners with different animation sets");this._animationSet!=t&&(this._animationSet=t,this._invalidAnimation=!0)}},n.prototype.removeOwner=function(e){this._owners&&(this._owners.remove(e),this._owners.numAssets||this.onClear(null))},n.prototype.getImageIndex=function(e,t){return void 0===t&&(t=0),this._invalidImages&&this._updateImages(),this._imageIndices[e.id][t]},n.prototype.onClear=function(t){var i;null===(i=this.renderElements)||void 0===i||i.removeMaterial(this);for(var n=this._passes.length,s=0;s<n;s++)this._passes[s].removeEventListener(h.INVALIDATE,this._onPassInvalidateDelegate),this._passes[s].dispose();this._passes.length=0,this._asset.removeEventListener(l.INVALIDATE_TEXTURES,this._onInvalidateTexturesDelegate),this._asset.removeEventListener(l.INVALIDATE_PASSES,this._onInvalidatePassesDelegate),this._animationSet=null,this._stage=null,this._owners=null,this._invalidAnimation=!0,this._invalidRender=!0,this._invalidImages=!0,this._imageIndices={},this._usesAnimation=!1,this._activePass=null,this.images=[],this.samplers=[],e.prototype.onClear.call(this,t)},n.prototype.onInvalidatePasses=function(e){for(var t=this._passes.length,i=0;i<t;i++)this._passes[i].invalidate();this._invalidAnimation=!0,this._invalidImages=!0},n.prototype.onPassInvalidate=function(e){this._invalidAnimation=!0},n.prototype.onInvalidateTextures=function(e){this._owners.forEach((function(e){return e._onInvalidateStyle()}))},n.prototype.onInvalidate=function(t){e.prototype.onInvalidate.call(this,t),this._invalidRender=!0,this._invalidAnimation=!0,this.renderElements.renderer!=this._asset&&this.renderElements.renderer.invalidate()},n.prototype._pClearPasses=function(){for(var e=this._passes.length,t=0;t<e;++t)this._passes[t].removeEventListener(h.INVALIDATE,this._onPassInvalidateDelegate);this._passes.length=0},n.prototype._pAddPass=function(e){this._passes.push(e),e.addEventListener(h.INVALIDATE,this._onPassInvalidateDelegate)},n.prototype._pRemovePass=function(e){e.removeEventListener(h.INVALIDATE,this._onPassInvalidateDelegate),this._passes.splice(this._passes.indexOf(e),1)},n.prototype._pUpdateRender=function(){this._invalidImages&&this._updateImages(),this._invalidRender=!1},n.prototype._updateAnimation=function(){this._invalidAnimation=!1;for(var e,t=this._getEnabledGPUAnimation(),i=0,n=1,s=this._passes.length,r=0;r<s;r++)(e=this._passes[r].shader).usesAnimation=t,e._programData?i+=e._programData.id*n:i+=e.programData.id*n,n*=1e3;this._usesAnimation!=t&&(this._usesAnimation=t,this._owners.forEach((function(e){return e._onInvalidateElements()}))),this._renderOrderId=i},n.prototype._updateImages=function(){this._invalidImages=!1;for(var e,t,n,s,r=this._asset.style,a=this._asset.getNumTextures(),o=0,h=0;h<a;h++){t=(e=this._asset.getTextureAt(h)).getNumImages(),n=this._imageIndices[e.id]=new Array;for(var l=0;l<t;l++)s=e.getImageAt(l)||(null==r?void 0:r.getImageAt(e,l))||i.ImageUtils.getDefaultImage2D(),this.images[o]=s.getAbstraction(this._stage),this.samplers[o]=e.getSamplerAt(l)||(null==r?void 0:r.getSamplerAt(e,l))||i.ImageUtils.getDefaultImageSampler(),n[l]=o++}this._numImages=o},n.prototype._getEnabledGPUAnimation=function(){if(this._animationSet){this._animationSet.resetGPUCompatibility();for(var e,t=this._passes.length,i=0;i<t;i++)(e=this._passes[i].shader).usesAnimation=!1,this._owners.forEach((function(t){t.entity.node.container.animator&&t.entity.node.container.animator.testGPUCompatibility(e)}));return!this._animationSet.usesCPU}return!1},n}(t.AbstractionBase),d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),Object.defineProperty(t.prototype,"shader",{get:function(){return this._shader},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"numUsedStreams",{get:function(){return this._shader.numUsedStreams},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"numUsedTextures",{get:function(){return this._shader.numUsedTextures},enumerable:!1,configurable:!0}),t.prototype._includeDependencies=function(e){e.alphaThreshold=this._asset.alphaThreshold,e.useImageRect=this._asset.imageRect,e.usesCurves=this._asset.curves,e.useBothSides=this._asset.bothSides,e.usesUVTransform=this._asset.animateUVs,e.usesColorTransform=this._asset.useColorTransform},t.prototype.invalidate=function(){this._shader.invalidateProgram(),this.dispatchEvent(new h(h.INVALIDATE,this))},t.prototype.dispose=function(){this._shader&&(this._shader.dispose(),this._shader=null)},t.prototype._setRenderState=function(e){this._shader._setRenderState(e)},t.prototype._activate=function(){this._shader._activate()},t.prototype._deactivate=function(){this._shader._deactivate()},t.prototype._initConstantData=function(){},t.prototype._getVertexCode=function(e,t){return""},t.prototype._getFragmentCode=function(e,t){return""},t.prototype._getPostAnimationFragmentCode=function(e,t){return""},t.prototype._getNormalVertexCode=function(e,t){return""},t.prototype._getNormalFragmentCode=function(e,t){return""},t}(c),u=function(e){function i(i){var n=e.call(this)||this;return n._materials=new t.WeakAssetSet("_Render_MaterialBase"),n.renderer=i,n.stage=i.view.stage,n._materialStore=i.group.materialStore,n._materialClassPool=i.group.materialClassPool,n}return a(i,e),i.prototype.requestAbstraction=function(e){var t=this._materialStore[e.assetType];return t.length?t.pop():new this._materialClassPool[e.assetType]},i.prototype.storeAbstraction=function(e){this._materialStore[e.asset.assetType].push(e)},i.prototype.addMaterial=function(e){this._materials.add(e)},i.prototype.removeMaterial=function(e){this._materials.remove(e)},i.prototype.clear=function(){this._materials.forEach((function(e){return e.onClear(null)}))},i.prototype._includeDependencies=function(e){},i.prototype._getVertexCode=function(e,t,i){return""},i.prototype._getFragmentCode=function(e,t,i){return""},i}(t.AssetBase),p=function(e){function t(t,i){var n=e.call(this,t)||this;return n._renderable=i,n}return a(t,e),Object.defineProperty(t.prototype,"renderable",{get:function(){return this._renderable},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new t(this.type,this._renderable)},t.INVALIDATE_MATERIAL="invalidateMaterial",t.INVALIDATE_ELEMENTS="invalidateElements",t.INVALIDATE_STYLE="invalidateStyle",t}(t.EventBase),_=function(){function e(){}return e.getDefaultTextureMaterial=function(){return this._defaultTextureMaterial||this.createDefaultTextureMaterial(),this._defaultTextureMaterial},e.getDefaultCubeTextureMaterial=function(){return this._defaultCubeTextureMaterial||this.createDefaultCubeTextureMaterial(),this._defaultCubeTextureMaterial},e.getDefaultColorMaterial=function(){return e._defaultColorMaterial||e.createDefaultColorMaterial(),e._defaultColorMaterial},e.createDefaultTextureMaterial=function(){this._defaultTextureMaterial=new this._defaultMaterialClass(i.ImageUtils.getDefaultImage2D()),this._defaultTextureMaterial.name="defaultTextureMaterial"},e.createDefaultCubeTextureMaterial=function(){this._defaultCubeTextureMaterial=new this._defaultMaterialClass(i.ImageUtils.getDefaultImageCube()),this._defaultCubeTextureMaterial.name="defaultCubeTextureMaterial"},e.createDefaultColorMaterial=function(){this._defaultColorMaterial=new this._defaultMaterialClass(16777215),this._defaultColorMaterial.name="defaultColorMaterial"},e.setDefaultMaterialClass=function(e){this._defaultMaterialClass=e},e}(),g={USE_ALPHA_CUTOFF:!1,ALPHA_CUTOFF_VALUE:.5,ALLOW_VAO:!0,ENABLE_CONVEX_BOUNDS:!1,CONVEX_MIN_REQUIEST_FOR_BUILD:10,POINTS_COUNT_FOR_CONVEX:10,SMOOTH_CACHED_IMAGE:!0,LINE_BUFFER_DIM:2},m=function(e){function i(){var t=e.call(this)||this;return t._materialDirty=!0,t._elementsDirty=!0,t._styleDirty=!0,t._images=new Array,t._samplers=new Array,t._count=0,t._offset=0,t._maskId=-1,t._onInvalidateElementsDelegate=function(e){return t._onInvalidateElements(e)},t._onInvalidateMaterialDelegate=function(e){return t._onInvalidateMaterial(e)},t._onInvalidateStyleDelegate=function(e){return t._onInvalidateStyle(e)},t}return a(i,e),Object.defineProperty(i.prototype,"images",{get:function(){return this._styleDirty&&this._updateStyle(),this._images},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"samplers",{get:function(){return this._styleDirty&&this._updateStyle(),this._samplers},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"uvMatrix",{get:function(){return this._styleDirty&&this._updateStyle(),this._uvMatrix},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"maskId",{get:function(){return this._maskId},set:function(e){e!==this._maskId&&this._updateMaskHack(e>=0),this._maskId=e},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"stageElements",{get:function(){return this._elementsDirty&&this._updateElements(),this._stageElements},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"renderMaterial",{get:function(){return this._materialDirty&&this._updateMaterial(),this._renderMaterial},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"entity",{get:function(){return this._useWeak?this._pool.deref():this._pool},enumerable:!1,configurable:!0}),i.prototype.init=function(t,i){e.prototype.init.call(this,t,i,!0),this._stage=i.stage,i.addRenderable(this),this._asset.addEventListener(p.INVALIDATE_ELEMENTS,this._onInvalidateElementsDelegate),this._asset.addEventListener(p.INVALIDATE_MATERIAL,this._onInvalidateMaterialDelegate),this._asset.addEventListener(p.INVALIDATE_STYLE,this._onInvalidateStyleDelegate)},i.prototype._updateMaskHack=function(e){var t;if(!(!g.USE_ALPHA_CUTOFF||g.ALPHA_CUTOFF_VALUE<0||g.ALPHA_CUTOFF_VALUE>1)){var i=null===(t=this.renderMaterial)||void 0===t?void 0:t.material;i&&(i.alphaThreshold=e?g.ALPHA_CUTOFF_VALUE:0)}},i.prototype.executeRender=function(e,t,i,n){var s=this._renderMaterial._activePass;s._setRenderState(this);var r=s.shader,a=this.stageElements;r.activeElements!=a&&(r.activeElements=a,a._setRenderState(this,r)),this._stageElements.draw(this,r,this._count,this._offset)},i.prototype.onClear=function(t){var i;this._asset.removeEventListener(p.INVALIDATE_ELEMENTS,this._onInvalidateElementsDelegate),this._asset.removeEventListener(p.INVALIDATE_MATERIAL,this._onInvalidateMaterialDelegate),this._asset.removeEventListener(p.INVALIDATE_STYLE,this._onInvalidateStyleDelegate),null===(i=this.entity)||void 0===i||i.removeRenderable(this),this.renderSceneTransform=null,this._stage=null,this.next=null,this.maskOwners=null,this._renderMaterial.removeOwner(this),this._renderMaterial=null,this._stageElements=null,this._materialDirty=!0,this._elementsDirty=!0,this._styleDirty=!0,e.prototype.onClear.call(this,t)},i.prototype._onInvalidateElements=function(e){this._elementsDirty=!0},i.prototype._onInvalidateMaterial=function(e){this._materialDirty=!0,this._styleDirty=!0},i.prototype._onInvalidateStyle=function(e){this._styleDirty=!0},i.prototype._getStageElements=function(){throw new t.AbstractMethodError},i.prototype._getRenderMaterial=function(){throw new t.AbstractMethodError},i.prototype._getStyle=function(){throw new t.AbstractMethodError},i.prototype._updateElements=function(){this._stageElements=this._getStageElements(),this._elementsDirty=!1},i.prototype._updateMaterial=function(){var e=this._getRenderMaterial();this._renderMaterial!=e&&(this._renderMaterial&&this._renderMaterial.removeOwner(this),this._renderMaterial=e,this._renderMaterial.addOwner(this)),this._materialDirty=!1},i.prototype._updateStyle=function(){var e=this._getStyle();this._materialDirty&&this._updateMaterial();var t=this._renderMaterial.numImages,i=this._renderMaterial.material;this._images.length=t,this._samplers.length=t,this._uvMatrix=e?e.uvMatrix:i.style?i.style.uvMatrix:null;for(var n,s,r,a=this._renderMaterial.material.getNumTextures(),o=0;o<a;o++){t=(n=i.getTextureAt(o)).getNumImages();for(var h=0;h<t;h++)r=this._renderMaterial.getImageIndex(n,h),s=e?e.getImageAt(n,h):null,this._images[r]=s?s.getAbstraction(this._stage):null,this._samplers[r]=e?e.getSamplerAt(n,h):null}this._styleDirty=!1},i.prototype.getDefaultMaterial=function(){return _.getDefaultTextureMaterial()},i}(t.AbstractionBase),f=function(e){function i(){var t=e.call(this)||this;return t._onInvalidateElementsDelegate=function(e){return t._onInvalidateElements(e)},t._onInvalidateMaterialDelegate=function(e){return t._onInvalidateMaterial(e)},t._onInvalidateStyleDelegate=function(e){return t._onInvalidateStyle(e)},t}return a(i,e),Object.defineProperty(i.prototype,"node",{get:function(){return this._asset},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"renderer",{get:function(){return this._pool},enumerable:!1,configurable:!0}),i.prototype.init=function(i,n){e.prototype.init.call(this,i,n),this.stage=n.stage,this._renderables=new t.WeakAssetSet("_Render_RenderableBase"),this._pool.addRenderEntity(this),this._asset.container.addEventListener(p.INVALIDATE_ELEMENTS,this._onInvalidateElementsDelegate),this._asset.container.addEventListener(p.INVALIDATE_MATERIAL,this._onInvalidateMaterialDelegate),this._asset.container.addEventListener(p.INVALIDATE_STYLE,this._onInvalidateStyleDelegate)},i.prototype.onClear=function(t){this._asset.container.removeEventListener(p.INVALIDATE_ELEMENTS,this._onInvalidateElementsDelegate),this._asset.container.removeEventListener(p.INVALIDATE_MATERIAL,this._onInvalidateMaterialDelegate),this._asset.container.removeEventListener(p.INVALIDATE_STYLE,this._onInvalidateStyleDelegate),this._renderables.forEach((function(e){return e.onClear(t)})),this._pool.removeRenderEntity(this),this._renderables=null,e.prototype.onClear.call(this,t)},i.prototype.onInvalidate=function(t){e.prototype.onInvalidate.call(this,t)},i.prototype.addRenderable=function(e){this._renderables.add(e)},i.prototype.removeRenderable=function(e){this._renderables.remove(e)},i.prototype._onInvalidateElements=function(e){},i.prototype._onInvalidateMaterial=function(e){},i.prototype._onInvalidateStyle=function(e){},i.prototype.requestAbstraction=function(e){var t=i._store[e.assetType];return t.length?t.pop():new i._renderRenderableClassPool[e.assetType]},i.prototype.storeAbstraction=function(e){i._store[e.asset.assetType].push(e)},i.registerRenderable=function(e,t){i._renderRenderableClassPool[t.assetType]=e,i._store[t.assetType]=[]},i._store={},i._renderRenderableClassPool=new Object,i}(t.AbstractionBase),v=function(e){function t(t,i){var n=e.call(this,t)||this;return n._style=i,n}return a(t,e),Object.defineProperty(t.prototype,"style",{get:function(){return this._style},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new t(this.type,this._style)},t.INVALIDATE_PROPERTIES="invalidateProperties",t.INVALIDATE_IMAGES="invalidateImages",t}(t.EventBase),y=function(e){function i(){var t=e.call(this)||this;return t._samplers={},t._images={},t._color=16777215,t._onImageInvalidate=function(e){return t._invalidateImages(e)},t._onImageClear=function(e){return t._clearImages(e)},t}return a(i,e),Object.defineProperty(i.prototype,"sampler",{get:function(){return this._sampler},set:function(e){this._sampler!=e&&(this._sampler=e,this._invalidateProperties())},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"image",{get:function(){return this._image},set:function(e){this._image!=e&&(this._image&&(this._image.removeEventListener(t.AssetEvent.INVALIDATE,this._onImageInvalidate),this._image.removeEventListener(t.AssetEvent.CLEAR,this._onImageClear)),this._image=e,this._image&&(this._image.addEventListener(t.AssetEvent.INVALIDATE,this._onImageInvalidate),this._image.addEventListener(t.AssetEvent.CLEAR,this._onImageClear)),this._invalidateProperties())},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"uvMatrix",{get:function(){return this._uvMatrix},set:function(e){this._uvMatrix!=e&&(this._uvMatrix=e,this._invalidateProperties())},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"color",{get:function(){return this._color},set:function(e){this._color!=e&&(this._color=e,this._invalidateProperties())},enumerable:!1,configurable:!0}),i.prototype.getImageAt=function(e,t){var i;return void 0===t&&(t=0),(null===(i=this._images[e.id])||void 0===i?void 0:i[t])||this._image},i.prototype.getSamplerAt=function(e,t){var i;return void 0===t&&(t=0),(null===(i=this._samplers[e.id])||void 0===i?void 0:i[t])||this._sampler},i.prototype.addImageAt=function(e,i,n){void 0===n&&(n=0),this._images[i.id]||(this._images[i.id]={}),this._images[i.id][n]=e,e.addEventListener(t.AssetEvent.INVALIDATE,this._onImageInvalidate),e.addEventListener(t.AssetEvent.CLEAR,this._onImageClear),this._invalidateProperties()},i.prototype.addSamplerAt=function(e,t,i){void 0===i&&(i=0),this._samplers[t.id]||(this._samplers[t.id]={}),this._samplers[t.id][i]=e,this._invalidateProperties()},i.prototype.removeImageAt=function(e,i){var n;void 0===i&&(i=0);var s=null===(n=this._images[e.id])||void 0===n?void 0:n[i];s&&(s.removeEventListener(t.AssetEvent.INVALIDATE,this._onImageInvalidate),s.removeEventListener(t.AssetEvent.CLEAR,this._onImageClear),this._images[e.id][i]=null,this._invalidateProperties())},i.prototype.removeSamplerAt=function(e,t){void 0===t&&(t=0),this._samplers[e.id]&&(this._samplers[e.id][t]=null,this._invalidateProperties())},i.prototype._invalidateProperties=function(){this.dispatchEvent(new v(v.INVALIDATE_PROPERTIES,this))},i.prototype._invalidateImages=function(e){this.dispatchEvent(new v(v.INVALIDATE_IMAGES,this))},i.prototype._clearImages=function(e){var t=e.asset;if(t.isDisposed)if(this._image==t)this.image=null;else e:for(var i in this._images){var n=this._images[i];for(var s in n)if(n[s]==t){delete n[s];break e}}this._invalidateProperties()},i}(t.EventDispatcher),x=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return a(i,e),i.prototype.init=function(t,i){e.prototype.init.call(this,t,i),this._texture=t,this._shader=i,this._stage=i._stage},i.prototype.onClear=function(t){e.prototype.onClear.call(this,t),this._texture=null,this._shader=null,this._stage=null},i.prototype._initVO=function(e){},i.prototype._initConstants=function(){},i.prototype._getFragmentCode=function(e,i,n,s){throw new t.AbstractMethodError},i.prototype._setRenderState=function(e){},i.prototype.activate=function(){},i.prototype.getTextureReg=function(e,t,i){var n=this._shader.imageIndices.indexOf(e);if(-1==n){var s=t.getFreeTextureReg();return i.textures.push(s),this._shader.imageIndices.push(e),s}return i.textures[n]},i}(t.AbstractionBase),I=function(){function e(){this.indexDictionary=new Object}return e.prototype.reset=function(e,t,n){this.rotationRegisters=new Array,this.positionAttribute=t.animatableAttributes[0],this.scaleAndRotateTarget=t.animationTargetRegisters[0];for(var s=1;s<t.animationTargetRegisters.length;s++)this.rotationRegisters.push(t.animationTargetRegisters[s]);if(this.vertexZeroConst=e.getFreeVertexConstant(),this.vertexZeroConst=new i.ShaderRegisterElement(this.vertexZeroConst.regName,this.vertexZeroConst.index,0),this.vertexOneConst=new i.ShaderRegisterElement(this.vertexZeroConst.regName,this.vertexZeroConst.index,1),this.vertexTwoConst=new i.ShaderRegisterElement(this.vertexZeroConst.regName,this.vertexZeroConst.index,2),this.positionTarget=e.getFreeVertexVectorTemp(),e.addVertexTempUsages(this.positionTarget,1),this.positionTarget=new i.ShaderRegisterElement(this.positionTarget.regName,this.positionTarget.index),n)this.velocityTarget=e.getFreeVertexVectorTemp(),e.addVertexTempUsages(this.velocityTarget,1),this.velocityTarget=new i.ShaderRegisterElement(this.velocityTarget.regName,this.velocityTarget.index),this.vertexTime=new i.ShaderRegisterElement(this.velocityTarget.regName,this.velocityTarget.index,3),this.vertexLife=new i.ShaderRegisterElement(this.positionTarget.regName,this.positionTarget.index,3);else{var r=e.getFreeVertexVectorTemp();e.addVertexTempUsages(r,1),this.vertexTime=new i.ShaderRegisterElement(r.regName,r.index,0),