소스 검색

[ts][pixi] Performance improvements.

Davide Tantillo 1 년 전
부모
커밋
52cc1d44d8
2개의 변경된 파일40개의 추가작업 그리고 30개의 파일을 삭제
  1. 20 14
      spine-ts/spine-pixi/src/DarkSlotMesh.ts
  2. 20 16
      spine-ts/spine-pixi/src/SlotMesh.ts

+ 20 - 14
spine-ts/spine-pixi/src/DarkSlotMesh.ts

@@ -54,26 +54,30 @@ export class DarkSlotMesh extends DarkTintMesh implements ISlotMesh {
 
 
 		const vertLenght = (finalVerticesLength / (darkTint ? 12 : 8)) * 2;
 		const vertLenght = (finalVerticesLength / (darkTint ? 12 : 8)) * 2;
 
 
-		if (this.geometry.getBuffer("aTextureCoord").data?.length !== vertLenght) {
-			this.geometry.getBuffer("aTextureCoord").data = new Float32Array(vertLenght);
+		const textureCoord = this.geometry.getBuffer("aTextureCoord");
+		if (textureCoord.data?.length !== vertLenght) {
+			textureCoord.data = new Float32Array(vertLenght);
 		}
 		}
 
 
-		if (this.geometry.getBuffer("aVertexPosition").data?.length !== vertLenght) {
-			this.geometry.getBuffer("aVertexPosition").data = new Float32Array(vertLenght);
+		const vertexCoord = this.geometry.getBuffer("aVertexPosition");
+		if (vertexCoord.data?.length !== vertLenght) {
+			vertexCoord.data = new Float32Array(vertLenght);
 		}
 		}
 
 
 		let vertIndex = 0;
 		let vertIndex = 0;
 
 
+		let textureCoordData = textureCoord.data;
+		let vertexCoordData = vertexCoord.data;
 		for (let i = 0; i < finalVerticesLength; i += darkTint ? 12 : 8) {
 		for (let i = 0; i < finalVerticesLength; i += darkTint ? 12 : 8) {
 			let auxi = i;
 			let auxi = i;
 
 
-			this.geometry.getBuffer("aVertexPosition").data[vertIndex] = finalVertices[auxi++];
-			this.geometry.getBuffer("aVertexPosition").data[vertIndex + 1] = finalVertices[auxi++];
+			vertexCoordData[vertIndex] = finalVertices[auxi++];
+			vertexCoordData[vertIndex + 1] = finalVertices[auxi++];
 
 
 			auxi += 4; // color
 			auxi += 4; // color
 
 
-			this.geometry.getBuffer("aTextureCoord").data[vertIndex] = finalVertices[auxi++];
-			this.geometry.getBuffer("aTextureCoord").data[vertIndex + 1] = finalVertices[auxi++];
+			textureCoordData[vertIndex] = finalVertices[auxi++];
+			textureCoordData[vertIndex + 1] = finalVertices[auxi++];
 
 
 			vertIndex += 2;
 			vertIndex += 2;
 		}
 		}
@@ -101,18 +105,20 @@ export class DarkSlotMesh extends DarkTintMesh implements ISlotMesh {
 		this.blendMode = SpineTexture.toPixiBlending(slotBlendMode);
 		this.blendMode = SpineTexture.toPixiBlending(slotBlendMode);
 		this.alpha = DarkSlotMesh.auxColor[3];
 		this.alpha = DarkSlotMesh.auxColor[3];
 
 
-		if (this.geometry.indexBuffer.data.length !== finalIndices.length) {
-			this.geometry.indexBuffer.data = new Uint32Array(finalIndices);
+		const indexBuffer = this.geometry.indexBuffer;
+		if (indexBuffer.data.length !== finalIndices.length) {
+			indexBuffer.data = new Uint32Array(finalIndices);
 		} else {
 		} else {
+			const indexBufferData = indexBuffer.data;
 			for (let i = 0; i < finalIndicesLength; i++) {
 			for (let i = 0; i < finalIndicesLength; i++) {
-				this.geometry.indexBuffer.data[i] = finalIndices[i];
+				indexBufferData[i] = finalIndices[i];
 			}
 			}
 		}
 		}
 
 
 		this.name = slotName;
 		this.name = slotName;
 
 
-		this.geometry.getBuffer("aVertexPosition").update();
-		this.geometry.getBuffer("aTextureCoord").update();
-		this.geometry.indexBuffer.update();
+		textureCoord.update();
+		vertexCoord.update();
+		indexBuffer.update();
 	}
 	}
 }
 }

+ 20 - 16
spine-ts/spine-pixi/src/SlotMesh.ts

@@ -62,32 +62,34 @@ export class SlotMesh extends Mesh implements ISlotMesh {
 
 
 		const vertLenght = (finalVerticesLength / (darkTint ? 12 : 8)) * 2;
 		const vertLenght = (finalVerticesLength / (darkTint ? 12 : 8)) * 2;
 
 
-		if (this.geometry.getBuffer("aTextureCoord").data?.length !== vertLenght) {
-			this.geometry.getBuffer("aTextureCoord").data = new Float32Array(vertLenght);
+		const textureCoord = this.geometry.getBuffer("aTextureCoord");
+		if (textureCoord.data?.length !== vertLenght) {
+			textureCoord.data = new Float32Array(vertLenght);
 		}
 		}
 
 
-		if (this.geometry.getBuffer("aVertexPosition").data?.length !== vertLenght) {
-			this.geometry.getBuffer("aVertexPosition").data = new Float32Array(vertLenght);
+		const vertexCoord = this.geometry.getBuffer("aVertexPosition");
+		if (vertexCoord.data?.length !== vertLenght) {
+			vertexCoord.data = new Float32Array(vertLenght);
 		}
 		}
 
 
 		let vertIndex = 0;
 		let vertIndex = 0;
 
 
+		let textureCoordData = textureCoord.data;
+		let vertexCoordData = vertexCoord.data;
 		for (let i = 0; i < finalVerticesLength; i += darkTint ? 12 : 8) {
 		for (let i = 0; i < finalVerticesLength; i += darkTint ? 12 : 8) {
 			let auxi = i;
 			let auxi = i;
 
 
-			this.geometry.getBuffer("aVertexPosition").data[vertIndex] = finalVertices[auxi++];
-			this.geometry.getBuffer("aVertexPosition").data[vertIndex + 1] = finalVertices[auxi++];
+			vertexCoordData[vertIndex] = finalVertices[auxi++];
+			vertexCoordData[vertIndex + 1] = finalVertices[auxi++];
 
 
 			auxi += 4; // color
 			auxi += 4; // color
 
 
-			this.geometry.getBuffer("aTextureCoord").data[vertIndex] = finalVertices[auxi++];
-			this.geometry.getBuffer("aTextureCoord").data[vertIndex + 1] = finalVertices[auxi++];
+			textureCoordData[vertIndex] = finalVertices[auxi++];
+			textureCoordData[vertIndex + 1] = finalVertices[auxi++];
 
 
 			vertIndex += 2;
 			vertIndex += 2;
 		}
 		}
 
 
-		// console.log(vertLenght, auxVert.length);
-
 		if (darkTint && !this.warnedTwoTint) {
 		if (darkTint && !this.warnedTwoTint) {
 			console.warn("DarkTint is not enabled by default. To enable use a DarkSlotMesh factory while creating the Spine object.");
 			console.warn("DarkTint is not enabled by default. To enable use a DarkSlotMesh factory while creating the Spine object.");
 			this.warnedTwoTint = true;
 			this.warnedTwoTint = true;
@@ -102,18 +104,20 @@ export class SlotMesh extends Mesh implements ISlotMesh {
 		this.alpha = SlotMesh.auxColor[3];
 		this.alpha = SlotMesh.auxColor[3];
 		this.blendMode = SpineTexture.toPixiBlending(slotBlendMode);
 		this.blendMode = SpineTexture.toPixiBlending(slotBlendMode);
 
 
-		if (this.geometry.indexBuffer.data.length !== finalIndices.length) {
-			this.geometry.indexBuffer.data = new Uint32Array(finalIndices);
+		const indexBuffer = this.geometry.indexBuffer;
+		if (indexBuffer.data.length !== finalIndices.length) {
+			indexBuffer.data = new Uint32Array(finalIndices);
 		} else {
 		} else {
+			const indexBufferData = indexBuffer.data;
 			for (let i = 0; i < finalIndicesLength; i++) {
 			for (let i = 0; i < finalIndicesLength; i++) {
-				this.geometry.indexBuffer.data[i] = finalIndices[i];
+				indexBufferData[i] = finalIndices[i];
 			}
 			}
 		}
 		}
 
 
 		this.name = slotName;
 		this.name = slotName;
 
 
-		this.geometry.getBuffer("aVertexPosition").update();
-		this.geometry.getBuffer("aTextureCoord").update();
-		this.geometry.indexBuffer.update();
+		textureCoord.update();
+		vertexCoord.update();
+		indexBuffer.update();
 	}
 	}
 }
 }