-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMesh.ts
51 lines (47 loc) · 1.93 KB
/
Mesh.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
import { CameraRenderer, isCameraRenderer } from '../renderers/utils'
import { ProjectedObject3D } from '../objects3D/ProjectedObject3D'
import { ProjectedMeshBaseMixin } from './mixins/ProjectedMeshBaseMixin'
import { MeshBaseParams } from './mixins/MeshBaseMixin'
import { GPUCurtains } from '../../curtains/GPUCurtains'
/**
* Create a 3D Mesh.
*
* A 3D Mesh is a basically a {@link ProjectedObject3D} with a {@link core/geometries/Geometry.Geometry | Geometry} and a {@link core/materials/RenderMaterial.RenderMaterial | RenderMaterial}.
*
* You need to pass at least a valid {@link core/geometries/Geometry.Geometry | Geometry} as parameter.<br>
* If no shaders are provided, it will use the normals colors as default shading.
*
* @example
* ```javascript
* // set our main GPUCurtains instance
* const gpuCurtains = new GPUCurtains({
* container: '#canvas' // selector of our WebGPU canvas container
* })
*
* // set the GPU device
* // note this is asynchronous
* await gpuCurtains.setDevice()
*
* // create a mesh with a box geometry
* // will use the normals colors as default shading
* const mesh = new Mesh(gpuCurtains, {
* label: 'My mesh',
* geometry: new BoxGeometry(),
* })
* ```
*/
export class Mesh extends ProjectedMeshBaseMixin(ProjectedObject3D) {
/**
* Mesh constructor
* @param renderer - {@link CameraRenderer} object or {@link GPUCurtains} class object used to create this {@link Mesh}
* @param parameters - {@link MeshBaseParams | parameters} use to create this {@link Mesh}
*/
constructor(renderer: CameraRenderer | GPUCurtains, parameters: MeshBaseParams) {
// we could pass our curtains object OR our curtains renderer object
renderer = (renderer && (renderer as GPUCurtains).renderer) || (renderer as CameraRenderer)
isCameraRenderer(renderer, parameters.label ? parameters.label + ' Mesh' : 'Mesh')
// @ts-ignore
super(renderer, null, parameters)
this.type = 'Mesh'
}
}