mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
[ts][threejs] Prefill normals at construction; they are always constant and perpendicular. See #2952.
This commit is contained in:
parent
2a73be09b7
commit
6e7727c836
@ -27,11 +27,10 @@
|
|||||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
import * as THREE from "three"
|
|
||||||
|
|
||||||
import { ThreeJsTexture, ThreeBlendOptions } from "./ThreeJsTexture.js";
|
|
||||||
import { BlendMode } from "@esotericsoftware/spine-core";
|
import { BlendMode } from "@esotericsoftware/spine-core";
|
||||||
|
import * as THREE from "three"
|
||||||
import { SkeletonMesh } from "./SkeletonMesh.js";
|
import { SkeletonMesh } from "./SkeletonMesh.js";
|
||||||
|
import { ThreeBlendOptions, ThreeJsTexture } from "./ThreeJsTexture.js";
|
||||||
|
|
||||||
export type MaterialWithMap = THREE.Material & { map: THREE.Texture | null };
|
export type MaterialWithMap = THREE.Material & { map: THREE.Texture | null };
|
||||||
export class MeshBatcher extends THREE.Mesh {
|
export class MeshBatcher extends THREE.Mesh {
|
||||||
@ -59,19 +58,35 @@ export class MeshBatcher extends THREE.Mesh {
|
|||||||
this.vertexSize += 3;
|
this.vertexSize += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
let vertices = this.vertices = new Float32Array(maxVertices * this.vertexSize);
|
this.vertices = new Float32Array(maxVertices * this.vertexSize);
|
||||||
let indices = this.indices = new Uint16Array(maxVertices * 3);
|
this.indices = new Uint16Array(maxVertices * 3);
|
||||||
let geo = new THREE.BufferGeometry();
|
|
||||||
let vertexBuffer = this.vertexBuffer = new THREE.InterleavedBuffer(vertices, this.vertexSize);
|
const normals = new Float32Array(maxVertices * 3);
|
||||||
vertexBuffer.usage = WebGLRenderingContext.DYNAMIC_DRAW;
|
for (let i = 0; i < maxVertices * 3; i += 3) {
|
||||||
|
normals[i] = 0;
|
||||||
|
normals[i + 1] = 0;
|
||||||
|
normals[i + 2] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vertexBuffer = new THREE.InterleavedBuffer(this.vertices, this.vertexSize)
|
||||||
|
this.vertexBuffer = vertexBuffer;
|
||||||
|
this.vertexBuffer.usage = WebGLRenderingContext.DYNAMIC_DRAW;
|
||||||
|
|
||||||
|
const geo = new THREE.BufferGeometry();
|
||||||
geo.setAttribute("position", new THREE.InterleavedBufferAttribute(vertexBuffer, 3, 0, false));
|
geo.setAttribute("position", new THREE.InterleavedBufferAttribute(vertexBuffer, 3, 0, false));
|
||||||
geo.setAttribute("color", new THREE.InterleavedBufferAttribute(vertexBuffer, 4, 3, false));
|
geo.setAttribute("color", new THREE.InterleavedBufferAttribute(vertexBuffer, 4, 3, false));
|
||||||
geo.setAttribute("uv", new THREE.InterleavedBufferAttribute(vertexBuffer, 2, 7, false));
|
geo.setAttribute("uv", new THREE.InterleavedBufferAttribute(vertexBuffer, 2, 7, false));
|
||||||
if (twoColorTint) {
|
if (twoColorTint)
|
||||||
geo.setAttribute("darkcolor", new THREE.InterleavedBufferAttribute(vertexBuffer, 3, 9, false));
|
geo.setAttribute("darkcolor", new THREE.InterleavedBufferAttribute(vertexBuffer, 3, 9, false));
|
||||||
}
|
|
||||||
geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
const normalBuffer = new THREE.BufferAttribute(normals, 3);
|
||||||
geo.getIndex()!.usage = WebGLRenderingContext.DYNAMIC_DRAW;
|
normalBuffer.usage = WebGLRenderingContext.STATIC_DRAW;
|
||||||
|
geo.setAttribute("normal", normalBuffer);
|
||||||
|
|
||||||
|
const indexBuffer = new THREE.BufferAttribute(this.indices, 1);
|
||||||
|
indexBuffer.usage = WebGLRenderingContext.DYNAMIC_DRAW;
|
||||||
|
geo.setIndex(indexBuffer);
|
||||||
|
|
||||||
geo.drawRange.start = 0;
|
geo.drawRange.start = 0;
|
||||||
geo.drawRange.count = 0;
|
geo.drawRange.count = 0;
|
||||||
this.geometry = geo;
|
this.geometry = geo;
|
||||||
@ -180,7 +195,6 @@ export class MeshBatcher extends THREE.Mesh {
|
|||||||
index.addUpdateRange(0, this.indicesLength);
|
index.addUpdateRange(0, this.indicesLength);
|
||||||
geo.drawRange.start = 0;
|
geo.drawRange.start = 0;
|
||||||
geo.drawRange.count = this.indicesLength;
|
geo.drawRange.count = this.indicesLength;
|
||||||
geo.computeVertexNormals();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addMaterialGroup (indicesLength: number, materialGroup: number) {
|
addMaterialGroup (indicesLength: number, materialGroup: number) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user