forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.js
More file actions
79 lines (67 loc) · 2.14 KB
/
render.js
File metadata and controls
79 lines (67 loc) · 2.14 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { EventHandler } from '../core/event-handler.js';
/**
* @event
* @private
* @name Render#set:meshes
* @description Fired when the meshes are set
* @param {Mesh[]} meshes - The meshes
*/
/**
* @class
* @private
* @name Render
* @augments EventHandler
* @classdesc A render contains an array of meshes that are referenced by a single hierarchy node in a GLB model, and are accessible using {@link ContainerResource#renders} property. The render is the resource of a Render Asset.
* @description Create a new Render. These are usually created by the GLB loader and not created by hand.
* @property {Mesh[]} meshes The meshes that the render contains
*/
class Render extends EventHandler {
constructor() {
super();
// meshes are reference counted, and this class owns the references and is responsible
// for releasing the meshes when they are no longer referenced
this._meshes = null;
}
destroy() {
this.meshes = null;
}
// decrement references to meshes, destroy the ones with zero references
decRefMeshes() {
if (this._meshes) {
const count = this._meshes.length;
for (let i = 0; i < count; i++) {
const mesh = this._meshes[i];
if (mesh) {
mesh.decRefCount();
if (mesh.getRefCount() < 1) {
mesh.destroy();
this._meshes[i] = null;
}
}
}
}
}
// increments ref count on all meshes
incRefMeshes() {
if (this._meshes) {
const count = this._meshes.length;
for (let i = 0; i < count; i++) {
if (this._meshes[i]) {
this._meshes[i].incRefCount();
}
}
}
}
get meshes() {
return this._meshes;
}
set meshes(value) {
// decrement references on the existing meshes
this.decRefMeshes();
// assign new meshes
this._meshes = value;
this.incRefMeshes();
this.fire('set:meshes', value);
}
}
export { Render };