-
-
Notifications
You must be signed in to change notification settings - Fork 36.4k
Expand file tree
/
Copy pathRenderObjects.js
More file actions
218 lines (158 loc) · 5.38 KB
/
RenderObjects.js
File metadata and controls
218 lines (158 loc) · 5.38 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import ChainMap from './ChainMap.js';
import RenderObject from './RenderObject.js';
const _chainKeys = [];
/**
* This module manages the render objects of the renderer.
*
* @private
*/
class RenderObjects {
/**
* Constructs a new render object management component.
*
* @param {Renderer} renderer - The renderer.
* @param {Nodes} nodes - Renderer component for managing nodes related logic.
* @param {Geometries} geometries - Renderer component for managing geometries.
* @param {Pipelines} pipelines - Renderer component for managing pipelines.
* @param {Bindings} bindings - Renderer component for managing bindings.
* @param {Info} info - Renderer component for managing metrics and monitoring data.
*/
constructor( renderer, nodes, geometries, pipelines, bindings, info ) {
/**
* The renderer.
*
* @type {Renderer}
*/
this.renderer = renderer;
/**
* Renderer component for managing nodes related logic.
*
* @type {Nodes}
*/
this.nodes = nodes;
/**
* Renderer component for managing geometries.
*
* @type {Geometries}
*/
this.geometries = geometries;
/**
* Renderer component for managing pipelines.
*
* @type {Pipelines}
*/
this.pipelines = pipelines;
/**
* Renderer component for managing bindings.
*
* @type {Bindings}
*/
this.bindings = bindings;
/**
* Renderer component for managing metrics and monitoring data.
*
* @type {Info}
*/
this.info = info;
/**
* A dictionary that manages render contexts in chain maps
* for each pass ID.
*
* @type {Object<string,ChainMap>}
*/
this.chainMaps = {};
}
/**
* Returns a render object for the given object and state data.
*
* @param {Object3D} object - The 3D object.
* @param {Material} material - The 3D object's material.
* @param {Scene} scene - The scene the 3D object belongs to.
* @param {Camera} camera - The camera the 3D object should be rendered with.
* @param {LightsNode} lightsNode - The lights node.
* @param {RenderContext} renderContext - The render context.
* @param {ClippingContext} clippingContext - The clipping context.
* @param {string} [passId] - An optional ID for identifying the pass.
* @return {RenderObject} The render object.
*/
get( object, material, scene, camera, lightsNode, renderContext, clippingContext, passId ) {
const chainMap = this.getChainMap( passId );
// set chain keys
_chainKeys[ 0 ] = object;
_chainKeys[ 1 ] = material;
_chainKeys[ 2 ] = renderContext;
_chainKeys[ 3 ] = lightsNode;
//
let renderObject = chainMap.get( _chainKeys );
if ( renderObject === undefined ) {
renderObject = this.createRenderObject( this.nodes, this.geometries, this.renderer, object, material, scene, camera, lightsNode, renderContext, clippingContext, passId );
chainMap.set( _chainKeys, renderObject );
} else {
// update references
renderObject.camera = camera;
//
renderObject.updateClipping( clippingContext );
if ( renderObject.needsGeometryUpdate ) {
renderObject.setGeometry( object.geometry );
}
if ( renderObject.version !== material.version || renderObject.needsUpdate ) {
if ( renderObject.initialCacheKey !== renderObject.getCacheKey() ) {
renderObject.dispose();
renderObject = this.get( object, material, scene, camera, lightsNode, renderContext, clippingContext, passId );
} else {
renderObject.version = material.version;
}
}
}
// reset chain array
_chainKeys[ 0 ] = null;
_chainKeys[ 1 ] = null;
_chainKeys[ 2 ] = null;
_chainKeys[ 3 ] = null;
//
return renderObject;
}
/**
* Returns a chain map for the given pass ID.
*
* @param {string} [passId='default'] - The pass ID.
* @return {ChainMap} The chain map.
*/
getChainMap( passId = 'default' ) {
return this.chainMaps[ passId ] || ( this.chainMaps[ passId ] = new ChainMap() );
}
/**
* Frees internal resources.
*/
dispose() {
this.chainMaps = {};
}
/**
* Factory method for creating render objects with the given list of parameters.
*
* @param {Nodes} nodes - Renderer component for managing nodes related logic.
* @param {Geometries} geometries - Renderer component for managing geometries.
* @param {Renderer} renderer - The renderer.
* @param {Object3D} object - The 3D object.
* @param {Material} material - The object's material.
* @param {Scene} scene - The scene the 3D object belongs to.
* @param {Camera} camera - The camera the object should be rendered with.
* @param {LightsNode} lightsNode - The lights node.
* @param {RenderContext} renderContext - The render context.
* @param {ClippingContext} clippingContext - The clipping context.
* @param {string} [passId] - An optional ID for identifying the pass.
* @return {RenderObject} The render object.
*/
createRenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext, clippingContext, passId ) {
const chainMap = this.getChainMap( passId );
const renderObject = new RenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext, clippingContext );
renderObject.onDispose = () => {
this.pipelines.delete( renderObject );
this.bindings.deleteForRender( renderObject );
this.nodes.delete( renderObject );
chainMap.delete( renderObject.getChainArray() );
};
return renderObject;
}
}
export default RenderObjects;