@awayjs/renderer
Version:
Renderer for AwayJS
1 lines • 142 kB
JavaScript
!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.abstractions=new t.AbstractionSet(this),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,i){e._store[i].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;case i.BlendMode.ERASE:this._blendFactor=[i.ContextGLBlendFactor.ZERO,i.ContextGLBlendFactor.ONE_MINUS_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=e.entity.colorTransform;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.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._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 i=e.call(this)||this;return i._owners=new t.WeakAssetSet,i._passes=[],i._invalidAnimation=!0,i._invalidRender=!0,i._invalidImages=!0,i._imageIndices={},i._usesAnimation=!1,i.images=[],i.samplers=[],i.requiresBlending=!1,i._onInvalidateTexturesDelegate=function(e){return i.onInvalidateTextures(e)},i._onInvalidatePassesDelegate=function(e){return i.onInvalidatePasses(e)},i._onPassInvalidateDelegate=function(e){return i.onPassInvalidate(e)},i}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._useWeak?this._asset.deref():this._asset},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"renderElements",{get:function(){return this._pool},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}),n.prototype.init=function(t,i){e.prototype.init.call(this,t,i,!0),this.materialID=t.id,this._stage=i.stage,t.addEventListener(l.INVALIDATE_TEXTURES,this._onInvalidateTexturesDelegate),t.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()},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.numAssets&&(this._owners.remove(e),this._owners.numAssets||this.onClear())},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(){for(var t=this._passes.length,i=0;i<t;i++)this._passes[i].removeEventListener(h.INVALIDATE,this._onPassInvalidateDelegate),this._passes[i].dispose();this._passes.length=0,this._owners.clear();var n=this.material;n&&(n.removeEventListener(l.INVALIDATE_TEXTURES,this._onInvalidateTexturesDelegate),n.removeEventListener(l.INVALIDATE_PASSES,this._onInvalidatePassesDelegate)),this._animationSet=null,this._stage=null,this._invalidAnimation=!0,this._invalidRender=!0,this._invalidImages=!0,this._imageIndices={},this._usesAnimation=!1,this._activePass=null,this.images.length=0,this.samplers.length=0,e.prototype.onClear.call(this)},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(){e.prototype.onInvalidate.call(this),this._invalidRender=!0,this._invalidAnimation=!0,this.renderElements.renderer!=this.material&&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(){var e=this.material;this._invalidImages=!1;for(var t,n,s,r=e.style,a=e.getNumTextures(),o=0,h=0;h<a;h++){n=(t=e.getTextureAt(h)).getNumImages(),s=this._imageIndices[t.id]=[];for(var l=0;l<n;l++)this.images[o]=(null==r?void 0:r.getImageAt(t,l))||t.getImageAt(l)||i.ImageUtils.getDefaultImage2D(),this.samplers[o]=(null==r?void 0:r.getSamplerAt(t,l))||t.getSamplerAt(l)||i.ImageUtils.getDefaultImageSampler(),s[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){var t=this.material;e.alphaThreshold=t.alphaThreshold,e.useImageRect=t.imageRect,e.usesCurves=t.curves,e.useBothSides=t.bothSides,e.usesUVTransform=t.animateUVs,e.usesColorTransform=t.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.abstractions=new t.AbstractionSet(n),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,t){this._materialStore[t].push(e)},i.prototype.clear=function(){this.abstractions.forEach((function(e){return e.onClear()}))},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(){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}(),_=function(e){function i(){var t=e.call(this)||this;return t._materialDirty=!0,t._elementsDirty=!0,t._styleDirty=!0,t._images=[],t._samplers=[],t._count=0,t._offset=0,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,"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._pool},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"renderable",{get:function(){return this._useWeak?this._asset.deref():this._asset},enumerable:!1,configurable:!0}),i.prototype.init=function(t,i){e.prototype.init.call(this,t,i,!0),this._stage=i.renderer.stage,t._renderObjects[i.id]=this},i.prototype.draw=function(){var e=this._renderMaterial._activePass;e._setRenderState(this);var t=e.shader,i=this.stageElements;t.activeElements!=i&&(t.activeElements=i,i._setRenderState(this,t)),i.draw(this,t,this._count,this._offset)},i.prototype.onClear=function(){var t=this.renderable;t&&delete t._renderObjects[this._pool.id],this._stage=null,this.next=null,this._renderMaterial.removeOwner(this),this._renderMaterial=null,this._stageElements=null,this._materialDirty=!0,this._elementsDirty=!0,this._styleDirty=!0,this._images.length=0,this._samplers.length=0,this._uvMatrix=null,e.prototype.onClear.call(this)},i.prototype._onInvalidateElements=function(){this._elementsDirty=!0},i.prototype._onInvalidateMaterial=function(){this._materialDirty=!0,this._styleDirty=!0},i.prototype._onInvalidateStyle=function(){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;var n=e?e.uvMatrix:i.style?i.style.uvMatrix:null;n&&(this._uvMatrix=this.stageElements.transformMatrix(this,n));for(var s,r,a=this._renderMaterial.material.getNumTextures(),o=0;o<a;o++){t=(s=i.getTextureAt(o)).getNumImages();for(var h=0;h<t;h++)r=this._renderMaterial.getImageIndex(s,h),this._images[r]=this._stage.abstractions.getAbstraction((null==e?void 0:e.getImageAt(s,h))||this._renderMaterial.images[r]),this._samplers[r]=(null==e?void 0:e.getSamplerAt(s,h))||this._renderMaterial.samplers[r]}this._styleDirty=!1},i.prototype.getDefaultMaterial=function(){return p.getDefaultTextureMaterial()},i}(t.AbstractionBase),g=function(){function e(e){this.pool=e,this._abstractions={}}return Object.defineProperty(e.prototype,"finalizer",{get:function(){var e=this;return this.__finalizer||(this.__finalizer=new FinalizationRegistry((function(t){var i=e._abstractions[t];i&&i.onClear()})))},enumerable:!1,configurable:!0}),e.prototype.forEach=function(e){for(var t in this._abstractions)e(this._abstractions[t])},e.prototype.getAbstraction=function(e){return this._abstractions[e.id]||(this._abstractions[e.id]=this.getNewAbstraction(e))},e.prototype.checkAbstraction=function(e){return this._abstractions[e.id]},e.prototype.clearAbstraction=function(e,t){this.pool.storeAbstraction(this._abstractions[e],t),delete this._abstractions[e]},e.prototype.getNewAbstraction=function(e){var t=this.pool.requestAbstraction(e);return t.init(e,this.pool),t},e}(),m=function(e){function t(){var t=e.call(this)||this;return t.abstractions=new g(t),t}return a(t,e),Object.defineProperty(t.prototype,"node",{get:function(){return this._asset},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"renderer",{get:function(){return this._pool},enumerable:!1,configurable:!0}),t.prototype.init=function(t,i){e.prototype.init.call(this,t,i),t.container._renderObjects[i.id]=this},t.prototype.onClear=function(){this.abstractions.forEach((function(e){return e.onClear()}));var t=this._asset.container;t&&delete t._renderObjects[this.renderer.id],this.renderSceneTransform=null,this.colorTransform=null,this.maskOwners=null,e.prototype.onClear.call(this)},t.prototype.onInvalidate=function(){e.prototype.onInvalidate.call(this)},t.prototype._onInvalidateElements=function(){},t.prototype._onInvalidateMaterial=function(){},t.prototype._onInvalidateStyle=function(){},t.prototype.requestAbstraction=function(e){var i=t._store[e.assetType];return i.length?i.pop():new t._renderRenderableClassPool[e.assetType]},t.prototype.storeAbstraction=function(e,i){t._store[i].push(e)},t.registerRenderable=function(e,i){t._renderRenderableClassPool[i.assetType]=e,t._store[i.assetType]=[]},t._store={},t._renderRenderableClassPool={},t}(t.AbstractionBase),f=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),v=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._samplers={},t._images={},t._color=16777215,t}return a(t,e),Object.defineProperty(t.prototype,"sampler",{get:function(){return this._sampler},set:function(e){this._sampler!=e&&(this._sampler=e,this._invalidateProperties())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"image",{get:function(){return this._image},set:function(e){this._image!=e&&(this._image&&this._image.removeOwner(this),this._image=e,this._image&&this._image.addOwner(this),this._invalidateProperties())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uvMatrix",{get:function(){return this._uvMatrix},set:function(e){this._uvMatrix!=e&&(this._uvMatrix=e,this._invalidateProperties())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"color",{get:function(){return this._color},set:function(e){this._color!=e&&(this._color=e,this._invalidateProperties())},enumerable:!1,configurable:!0}),t.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},t.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},t.prototype.addImageAt=function(e,t,i){void 0===i&&(i=0),this._images[t.id]||(this._images[t.id]={}),this._images[t.id][i]=e,this._image.addOwner(this),this._invalidateProperties()},t.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()},t.prototype.removeImageAt=function(e,t){var i;void 0===t&&(t=0),(null===(i=this._images[e.id])||void 0===i?void 0:i[t])&&(this._image.removeOwner(this),this._images[e.id][t]=null,this._invalidateProperties())},t.prototype.removeSamplerAt=function(e,t){void 0===t&&(t=0),this._samplers[e.id]&&(this._samplers[e.id][t]=null,this._invalidateProperties())},t.prototype._invalidateProperties=function(){this.dispatchEvent(new f(f.INVALIDATE_PROPERTIES,this))},t.prototype.onImageInvalidate=function(e){this.dispatchEvent(new f(f.INVALIDATE_IMAGES,this))},t.prototype.onImageClear=function(e){if(e.isDisposed)if(this._image==e)this.image=null;else e:for(var t in this._images){var i=this._images[t];for(var n in i)if(i[n]==e){delete i[n];break e}}this._invalidateProperties()},t}(t.AssetBase),y=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return a(i,e),Object.defineProperty(i.prototype,"texture",{get:function(){return this._useWeak?this._asset.deref():this._asset},enumerable:!1,configurable:!0}),i.prototype.init=function(t,i){e.prototype.init.call(this,t,i,!0),this._shader=i,this._stage=i._stage},i.prototype.onClear=function(){e.prototype.onClear.call(this),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),x=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),this.vertexLife=new i.ShaderRegisterElement(r.regName,r.index,1)}},e.prototype.setUVSourceAndTarget=function(e){this.uvVar=e.animatedUV,this.uvAttribute=e.uvInput,this.uvTarget=new i.ShaderRegisterElement(this.positionTarget.regName,this.positionTarget.index)},e.prototype.setRegisterIndex=function(e,t,i){var n=this.indexDictionary[e.id];null==n&&(n=this.indexDictionary[e.id]=new Array(8)),n[t]=i},e.prototype.getRegisterIndex=function(e,t){return this.indexDictionary[e.id][t]},e}(),b=function(e){function t(){return e.call(this)||this}return a(t,e),Object.defineProperty(t.prototype,"stateClass",{get:function(){return this._pStateClass},enumerable:!1,configurable:!0}),t.prototype.dispose=function(){},Object.defineProperty(t.prototype,"assetType",{get:function(){return t.assetType},enumerable:!1,configurable:!0}),t.assetType="[asset AnimationNodeBase]",t}(t.AssetBase),I=function(e){function t(t,i){var n=e.call(this,t)||this;return n._attributesView=i,n}return a(t,e),Object.defineProperty(t.prototype,"attributesView",{get:function(){return this._attributesView},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new t(this.type,this._attributesView)},t.INVALIDATE_INDICES="invalidateIndices",t.CLEAR_INDICES="clearIndices",t.INVALIDATE_VERTICES="invalidateVertices",t.CLEAR_VERTICES="clearVertices",t}(t.EventBase),C=function(){function e(){}return e.generateFaceNormals=function(e,t,n,s,r){void 0===r&&(r=0);var a=e.get(s,r),o=t.get(t.count);null==n?n=new i.Float4Attributes(s+r):n.count<s+r&&(n.count=s+r);var h,l,c,d,u,p,_,g,m,f,v,y,x,b,I,C,T,D,w,A=e.stride,V=t.dimensions,E=t.stride,M=n.get(s,r),S=s*A,P=0,R=0;if(3==V)for(P=0;P<S;P+=A)l=o[h=a[P]*E],u=o[h+1],g=o[h+2],c=o[h=a[P+1]*E],p=o[h+1],m=o[h+2],d=o[h=a[P+2]*E],_=o[h+1],C=(y=o[h+2]-g)*(b=p-u)-(v=_-u)*(I=m-g),T=(f=d-l)*I-y*(x=c-l),D=v*x-f*b,w=Math.sqrt(C*C+T*T+D*D),M[R++]=C,M[R++]=T,M[R++]=D,M[R++]=w;else if(2==V)for(P=0;P<S;P+=A)M[R++]=0,M[R++]=0,M[R++]=1,M[R++]=1;return n},e.generateNormals=function(e,t,n,s){var r=e.get(e.count),a=t.get(t.count);null==n&&(n=new i.Float3Attributes(s));var o,h,l=e.dimensions,c=n.stride,d=n.get(n.count),u=n.count*c;for(o=0;o<u;o+=c)d[o]=0,d[o+1]=0,d[o+2]=0;u=e.count*l;var p,_,g,m,f=0,v=1,y=2;for(o=0;o<u;o+=l)d[h=r[o]*c]+=a[f],d[h+1]+=a[v],d[h+2]+=a[y],d[h=r[o+1]*c]+=a[f],d[h+1]+=a[v],d[h+2]+=a[y],d[h=r[o+2]*c]+=a[f],d[h+1]+=a[v],d[h+2]+=a[y],f+=4,v+=4,y+=4;for(u=n.count*c,o=0;o<u;o+=c)p=d[o],_=d[o+1],g=d[o+2],m=1/Math.sqrt(p*p+_*_+g*g),d[o]=p*m,d[o+1]=_*m,d[o+2]=g*m;return n},e.generateFaceTangents=function(e,t,n,s,r,a,o){void 0===a&&(a=0);var h=e.get(r,a),l=t.get(t.count),c=n.get(n.count);null==s?s=new i.Float4Attributes(r+a):s.count<r+a&&(s.count=r+a);var d,u,p,_,g,m,f,v,y,x,b,I,C,T,D,w=e.dimensions,A=t.dimensions,V=t.stride,E=n.stride,M=s.get(r,a),S=0,P=r*w;for(S=0;S<P;S+=w)d=h[S],u=h[S+1],p=h[S+2],_=c[d*E+1],f=c[u*E+1]-_,v=c[p*E+1]-_,g=u*V,m=p*V,x=l[_=d*V],C=v*(l[g]-x)-f*(l[m]-x),b=l[_+1],T=v*(l[g+1]-b)-f*(l[m+1]-b),3==A?(I=l[_+2],D=v*(l[g+2]-I)-f*(l[