lecodes-sdk 2.4.4 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/gl/Mesh.ts CHANGED
@@ -1,120 +1,120 @@
1
- // A renderable 3D node from raw geometry — the primitive shapes (box/sphere/cylinder/capsule/plane) and
2
- // Mesh.from for a custom Geometry. A GLB import is a different kind: see Model.load.
3
-
4
- import { cx, cy, cz, type Vec3Like } from "../math/vec"
5
- import {
6
- Geometry,
7
- type CapsuleOptions,
8
- type CylinderOptions,
9
- type PlaneOptions,
10
- type SphereOptions,
11
- } from "./Geometry"
12
- import { Material } from "./Material"
13
- import { Node } from "./Node"
14
-
15
- /** Common transform/render options every primitive factory accepts. */
16
- export type MeshOptions = {
17
- material?: Material
18
- position?: Vec3Like
19
- eulerAngles?: Vec3Like
20
- scale?: Vec3Like | number
21
- name?: string
22
- castShadows?: boolean
23
- receiveShadows?: boolean
24
- /** Coarse draw order, 0 (first) … 7 (last); default 4. See `Mesh.renderPriority`. */
25
- renderPriority?: number
26
- }
27
-
28
- export class Mesh extends Node {
29
- private _geometry?: Geometry
30
-
31
- constructor(geometry?: Geometry, material?: Material) {
32
- super()
33
- if (geometry) {
34
- const mat = material ?? Material.unlit()
35
- this._geometry = geometry
36
- this._materials = [ mat ]
37
- _creator.setMesh(this.id, Material.idOf(mat), geometry.vertices, geometry.normals, geometry.indices, geometry.uv, geometry._meshKind, geometry.uv1, geometry.colors)
38
- }
39
- }
40
-
41
- override get geometry(): Geometry | undefined { return this._geometry }
42
- /** Replace the geometry in place — the node, its transform and its material stay, the vertex and
43
- * index buffers are rebuilt. What an editor overlay or a debug drawer redraws with. */
44
- setGeometry(geometry: Geometry): this {
45
- this._geometry = geometry
46
- _creator.setMesh(this.id, Material.idOf(this._materials![0]!), geometry.vertices, geometry.normals, geometry.indices, geometry.uv, geometry._meshKind, geometry.uv1, geometry.colors)
47
- // the host rebuilds the renderable for a new geometry (creator-gl createMesh destroys + builds), which
48
- // resets its priority / culling / shadow flags to the defaults — an overlay redrawn every frame lost its
49
- // renderPriority 7 after one frame and hid inside the model. What was set on this mesh is set again.
50
- if (this._renderPriority !== undefined) this.renderPriority = this._renderPriority
51
- if (this._culling !== undefined) this.culling = this._culling
52
- if (this._castShadows !== undefined) this.castShadows = this._castShadows
53
- if (this._receiveShadows !== undefined) this.receiveShadows = this._receiveShadows
54
- return this
55
- }
56
- private _renderPriority?: number
57
- private _culling?: boolean
58
- private _castShadows?: boolean
59
- private _receiveShadows?: boolean
60
-
61
- /** A Mesh always carries a material (slot 0) — see Node.setMaterial for the slot API. */
62
- override get material(): Material { return this._materials![0]! }
63
- override set material(m: Material) { this.setMaterial(m, 0) }
64
-
65
- set culling(v: boolean) { this._culling = v; _creator.setCulling(this.id, v) }
66
- /** Coarse draw order within the frame: 0 draws first, 7 last, 4 is the default (Filament's
67
- * renderable priority; within one priority opaque draws sort front-to-back, blended back-to-front).
68
- * Something drawn over the scene with `Material.depthTest = false` goes in 7, so nothing drawn
69
- * after it can cover it. Write-only; a host that predates the call ignores it. */
70
- set renderPriority(v: number) {
71
- this._renderPriority = v
72
- if (_creator.setRenderPriority) _creator.setRenderPriority(this.id, Math.max(0, Math.min(7, Math.round(v))))
73
- else if (!Mesh._warnedPriority) { Mesh._warnedPriority = true; console.warn("[mesh] this host has no setRenderPriority — renderPriority ignored") }
74
- }
75
- private static _warnedPriority = false
76
- set castShadows(v: boolean) { this._castShadows = v; _creator.setCastShadows(this.id, v) }
77
- set receiveShadows(v: boolean) { this._receiveShadows = v; _creator.setReceiveShadows(this.id, v) }
78
-
79
- // --- factories ---
80
-
81
- static box(options: MeshOptions & { size?: Vec3Like | number } = {}): Mesh {
82
- // the size goes into the geometry (not a scale after): the lightmap chart is laid out per face area
83
- return apply(new Mesh(Geometry.box(options.size ?? 1), options.material), options)
84
- }
85
-
86
- static sphere(options: MeshOptions & SphereOptions = {}): Mesh {
87
- return apply(new Mesh(Geometry.sphere(options), options.material), options)
88
- }
89
-
90
- static cylinder(options: MeshOptions & CylinderOptions = {}): Mesh {
91
- return apply(new Mesh(Geometry.cylinder(options), options.material), options)
92
- }
93
-
94
- /** A capsule along Y (`radius`, `length` between the cap centres) — a character's or a collider's shape in one mesh. */
95
- static capsule(options: MeshOptions & CapsuleOptions = {}): Mesh {
96
- return apply(new Mesh(Geometry.capsule(options), options.material), options)
97
- }
98
-
99
- static plane(options: MeshOptions & PlaneOptions = {}): Mesh {
100
- return apply(new Mesh(Geometry.plane(options), options.material), options)
101
- }
102
-
103
- /** Wrap a custom Geometry. */
104
- static from(geometry: Geometry, options: MeshOptions = {}): Mesh {
105
- return apply(new Mesh(geometry, options.material), options)
106
- }
107
- }
108
-
109
- const sizeToVec = (s: Vec3Like | number): [number, number, number] => (typeof s === "number" ? [ s, s, s ] : [ cx(s), cy(s), cz(s) ])
110
-
111
- const apply = (mesh: Mesh, o: MeshOptions): Mesh => {
112
- if (o.position) mesh.position = o.position
113
- if (o.eulerAngles) mesh.eulerAngles = o.eulerAngles
114
- if (o.scale !== undefined) mesh.scale = typeof o.scale === "number" ? [ o.scale, o.scale, o.scale ] : o.scale
115
- if (o.name !== undefined) mesh.name = o.name
116
- if (o.castShadows !== undefined) mesh.castShadows = o.castShadows
117
- if (o.receiveShadows !== undefined) mesh.receiveShadows = o.receiveShadows
118
- if (o.renderPriority !== undefined) mesh.renderPriority = o.renderPriority
119
- return mesh
120
- }
1
+ // A renderable 3D node from raw geometry — the primitive shapes (box/sphere/cylinder/capsule/plane) and
2
+ // Mesh.from for a custom Geometry. A GLB import is a different kind: see Model.load.
3
+
4
+ import { cx, cy, cz, type Vec3Like } from "../math/vec"
5
+ import {
6
+ Geometry,
7
+ type CapsuleOptions,
8
+ type CylinderOptions,
9
+ type PlaneOptions,
10
+ type SphereOptions,
11
+ } from "./Geometry"
12
+ import { Material } from "./Material"
13
+ import { Node } from "./Node"
14
+
15
+ /** Common transform/render options every primitive factory accepts. */
16
+ export type MeshOptions = {
17
+ material?: Material
18
+ position?: Vec3Like
19
+ eulerAngles?: Vec3Like
20
+ scale?: Vec3Like | number
21
+ name?: string
22
+ castShadows?: boolean
23
+ receiveShadows?: boolean
24
+ /** Coarse draw order, 0 (first) … 7 (last); default 4. See `Mesh.renderPriority`. */
25
+ renderPriority?: number
26
+ }
27
+
28
+ export class Mesh extends Node {
29
+ private _geometry?: Geometry
30
+
31
+ constructor(geometry?: Geometry, material?: Material) {
32
+ super()
33
+ if (geometry) {
34
+ const mat = material ?? Material.unlit()
35
+ this._geometry = geometry
36
+ this._materials = [ mat ]
37
+ _creator.setMesh(this.id, Material.idOf(mat), geometry.vertices, geometry.normals, geometry.indices, geometry.uv, geometry._meshKind, geometry.uv1, geometry.colors)
38
+ }
39
+ }
40
+
41
+ override get geometry(): Geometry | undefined { return this._geometry }
42
+ /** Replace the geometry in place — the node, its transform and its material stay, the vertex and
43
+ * index buffers are rebuilt. What an editor overlay or a debug drawer redraws with. */
44
+ setGeometry(geometry: Geometry): this {
45
+ this._geometry = geometry
46
+ _creator.setMesh(this.id, Material.idOf(this._materials![0]!), geometry.vertices, geometry.normals, geometry.indices, geometry.uv, geometry._meshKind, geometry.uv1, geometry.colors)
47
+ // the host rebuilds the renderable for a new geometry (creator-gl createMesh destroys + builds), which
48
+ // resets its priority / culling / shadow flags to the defaults — an overlay redrawn every frame lost its
49
+ // renderPriority 7 after one frame and hid inside the model. What was set on this mesh is set again.
50
+ if (this._renderPriority !== undefined) this.renderPriority = this._renderPriority
51
+ if (this._culling !== undefined) this.culling = this._culling
52
+ if (this._castShadows !== undefined) this.castShadows = this._castShadows
53
+ if (this._receiveShadows !== undefined) this.receiveShadows = this._receiveShadows
54
+ return this
55
+ }
56
+ private _renderPriority?: number
57
+ private _culling?: boolean
58
+ private _castShadows?: boolean
59
+ private _receiveShadows?: boolean
60
+
61
+ /** A Mesh always carries a material (slot 0) — see Node.setMaterial for the slot API. */
62
+ override get material(): Material { return this._materials![0]! }
63
+ override set material(m: Material) { this.setMaterial(m, 0) }
64
+
65
+ set culling(v: boolean) { this._culling = v; _creator.setCulling(this.id, v) }
66
+ /** Coarse draw order within the frame: 0 draws first, 7 last, 4 is the default (Filament's
67
+ * renderable priority; within one priority opaque draws sort front-to-back, blended back-to-front).
68
+ * Something drawn over the scene with `Material.depthTest = false` goes in 7, so nothing drawn
69
+ * after it can cover it. Write-only; a host that predates the call ignores it. */
70
+ set renderPriority(v: number) {
71
+ this._renderPriority = v
72
+ if (_creator.setRenderPriority) _creator.setRenderPriority(this.id, Math.max(0, Math.min(7, Math.round(v))))
73
+ else if (!Mesh._warnedPriority) { Mesh._warnedPriority = true; console.warn("[mesh] this host has no setRenderPriority — renderPriority ignored") }
74
+ }
75
+ private static _warnedPriority = false
76
+ set castShadows(v: boolean) { this._castShadows = v; _creator.setCastShadows(this.id, v) }
77
+ set receiveShadows(v: boolean) { this._receiveShadows = v; _creator.setReceiveShadows(this.id, v) }
78
+
79
+ // --- factories ---
80
+
81
+ static box(options: MeshOptions & { size?: Vec3Like | number } = {}): Mesh {
82
+ // the size goes into the geometry (not a scale after): the lightmap chart is laid out per face area
83
+ return apply(new Mesh(Geometry.box(options.size ?? 1), options.material), options)
84
+ }
85
+
86
+ static sphere(options: MeshOptions & SphereOptions = {}): Mesh {
87
+ return apply(new Mesh(Geometry.sphere(options), options.material), options)
88
+ }
89
+
90
+ static cylinder(options: MeshOptions & CylinderOptions = {}): Mesh {
91
+ return apply(new Mesh(Geometry.cylinder(options), options.material), options)
92
+ }
93
+
94
+ /** A capsule along Y (`radius`, `length` between the cap centres) — a character's or a collider's shape in one mesh. */
95
+ static capsule(options: MeshOptions & CapsuleOptions = {}): Mesh {
96
+ return apply(new Mesh(Geometry.capsule(options), options.material), options)
97
+ }
98
+
99
+ static plane(options: MeshOptions & PlaneOptions = {}): Mesh {
100
+ return apply(new Mesh(Geometry.plane(options), options.material), options)
101
+ }
102
+
103
+ /** Wrap a custom Geometry. */
104
+ static from(geometry: Geometry, options: MeshOptions = {}): Mesh {
105
+ return apply(new Mesh(geometry, options.material), options)
106
+ }
107
+ }
108
+
109
+ const sizeToVec = (s: Vec3Like | number): [number, number, number] => (typeof s === "number" ? [ s, s, s ] : [ cx(s), cy(s), cz(s) ])
110
+
111
+ const apply = (mesh: Mesh, o: MeshOptions): Mesh => {
112
+ if (o.position) mesh.position = o.position
113
+ if (o.eulerAngles) mesh.eulerAngles = o.eulerAngles
114
+ if (o.scale !== undefined) mesh.scale = typeof o.scale === "number" ? [ o.scale, o.scale, o.scale ] : o.scale
115
+ if (o.name !== undefined) mesh.name = o.name
116
+ if (o.castShadows !== undefined) mesh.castShadows = o.castShadows
117
+ if (o.receiveShadows !== undefined) mesh.receiveShadows = o.receiveShadows
118
+ if (o.renderPriority !== undefined) mesh.renderPriority = o.renderPriority
119
+ return mesh
120
+ }
package/src/gl/Scene.ts CHANGED
@@ -164,7 +164,7 @@ const installRenderSyncedFrames = (): void => {
164
164
  if (typeof _creator.setFixedUpdate !== "function") return false
165
165
  _creator.setFixedUpdate(fixed)
166
166
  return true
167
- })
167
+ }, () => Presentable.current instanceof Scene) // this engine drives the phases while a 3D scene is on show
168
168
  // Time.scale / Time.paused reach the engine's own clocks (physics, animators, particles) through
169
169
  // setTimeScale; a host without it keeps running its sims at wall-clock speed (feature-detected).
170
170
  _installTimeScale((scale) => { _creator.setTimeScale?.(scale) })