-
Notifications
You must be signed in to change notification settings - Fork 46
/
mesh-geometry.ts
61 lines (55 loc) · 1.85 KB
/
mesh-geometry.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Geometry } from "@pixi/core"
import { MeshShader } from "../mesh-shader"
import { MeshGeometryAttribute } from "./mesh-geometry-attribute"
import { MeshGeometryTarget } from "./mesh-geometry-target"
/**
* Geometry with mesh data (i.e. positions, normals, uvs).
*/
export class MeshGeometry3D {
private _shaderGeometry: { [id: string]: Geometry } = {}
indices?: MeshGeometryAttribute
positions?: MeshGeometryAttribute
uvs?: MeshGeometryAttribute[]
normals?: MeshGeometryAttribute
tangents?: MeshGeometryAttribute
targets?: MeshGeometryTarget[]
joints?: MeshGeometryAttribute
weights?: MeshGeometryAttribute
colors?: MeshGeometryAttribute
/**
* Returns geometry with attributes required by the specified shader.
* @param shader The shader to use.
*/
getShaderGeometry(shader: MeshShader) {
return this._shaderGeometry[shader.name]
}
/**
* Creates geometry with attributes required by the specified shader.
* @param shader The shader to use.
* @param instanced Value indicating if the geometry will be instanced.
*/
addShaderGeometry(shader: MeshShader, instanced: boolean) {
this._shaderGeometry[shader.name] = shader.createShaderGeometry(this, instanced)
}
/**
* Returns a value indicating if geometry with required attributes has been
* created by the specified shader.
* @param shader The shader to test.
* @param instanced Value indicating if the geometry is instanced.
*/
hasShaderGeometry(shader: MeshShader, instanced: boolean) {
if (this._shaderGeometry[shader.name]) {
return !instanced || (instanced && this._shaderGeometry[shader.name].instanced)
}
return false
}
/**
* Destroys the geometry and it's used resources.
*/
destroy() {
for (let name in this._shaderGeometry) {
this._shaderGeometry[name].destroy()
}
this._shaderGeometry = {}
}
}