Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit 2d1144d

Browse files
committed
Initial work to make renderers serializable, and viewable in the ParametersView
1 parent 30e0f6d commit 2d1144d

9 files changed

Lines changed: 410 additions & 53 deletions

File tree

src/app/ContentBridge.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ const $log = Symbol('log');
99
const $eval = Symbol('eval');
1010
const $dispatchToContent = Symbol('dispatchToContent');
1111
const $renderers = Symbol('renderers');
12+
const $renderingInfo = Symbol('renderingInfo');
1213

1314
const VERBOSE_CONTENT_BRIDGE = false;
1415

1516
export default class ContentBridge extends EventTarget {
1617
/**
1718
* Events:
1819
* 'load'
19-
* 'entity-update' { object, uuid }
20+
* 'entity-update' { entity, uuid }
2021
* 'scene-graph-update' { uuid, graph }
2122
* 'overview-update' { type, entities }
22-
* 'renderer-update' {}
23+
* 'rendering-info-update' {}
24+
* 'renderer-update' { renderer, id }
2325
*/
2426
constructor() {
2527
super();
@@ -28,6 +30,7 @@ export default class ContentBridge extends EventTarget {
2830
this[$overviews] = new Map();
2931
this[$sceneGraphs] = new Map();
3032
this[$renderers] = new Map();
33+
this[$renderingInfo] = new Map();
3134

3235
this.port = browser.runtime.connect({
3336
name: 'three-devtools',
@@ -74,8 +77,11 @@ export default class ContentBridge extends EventTarget {
7477
while (uuids.length) {
7578
const uuid = uuids.shift();
7679
const entity = this.getEntity(uuid);
77-
if (entity && !data[entity.uuid]) {
78-
data[entity.uuid] = entity;
80+
// In renderers case, uuid is an id.
81+
// @TODO should probably abstract away the differences
82+
// between UUID and synthesized renderer ids.
83+
if (entity && !data[uuid]) {
84+
data[uuid] = entity;
7985

8086
// entities can have several dependencies, like textures on materials,
8187
// or a Mesh's geometry
@@ -90,6 +96,10 @@ export default class ContentBridge extends EventTarget {
9096
return data;
9197
}
9298

99+
getRenderingInfo(uuid) {
100+
return this[$renderingInfo].get(uuid);
101+
}
102+
93103
getResourcesOverview(type) {
94104
return this[$overviews].get(type);
95105
}
@@ -132,6 +142,10 @@ export default class ContentBridge extends EventTarget {
132142
this[$dispatchToContent]('_request-scene-graph', { uuid });
133143
}
134144

145+
requestRenderingInfo(uuid) {
146+
this[$dispatchToContent]('_request-rendering-info', { uuid });
147+
}
148+
135149
select(uuid) {
136150
if (!uuid) {
137151
return;
@@ -158,6 +172,7 @@ export default class ContentBridge extends EventTarget {
158172
this[$overviews].clear();
159173
this[$sceneGraphs].clear();
160174
this[$renderers].clear();
175+
this[$renderingInfo].clear();
161176

162177
this[$eval](injection);
163178
this.dispatchEvent(new CustomEvent('load'));
@@ -187,11 +202,20 @@ export default class ContentBridge extends EventTarget {
187202
},
188203
}));
189204
break;
205+
case 'rendering-info':
206+
this.dispatchEvent(new CustomEvent('rendering-info-update', {
207+
detail: data,
208+
}));
209+
this[$renderingInfo].set(data.id, data);
210+
break;
190211
case 'entity':
191212
if (data.type === 'renderer') {
192213
this[$renderers].set(data.id, data);
193214
this.dispatchEvent(new CustomEvent('renderer-update', {
194-
detail: data,
215+
detail: {
216+
renderer: data,
217+
id: data.id,
218+
},
195219
}));
196220
} else if (Array.isArray(data)) {
197221
for (let entity of data) {

src/app/data/renderers.js

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
const PBR = {
2+
name: 'Physically-based Rendering',
3+
type: 'group',
4+
props: [{
5+
name: 'Physically Correct Lights',
6+
prop: 'physicallyCorrectLights',
7+
type: 'boolean',
8+
default: false,
9+
}, {
10+
name: 'Gamma',
11+
prop: 'gammaFactor',
12+
type: 'number',
13+
default: 2,
14+
}, {
15+
// @TODO
16+
name: 'Output Encoding',
17+
prop: 'outputEncoding',
18+
type: 'enum'
19+
}]
20+
};
21+
22+
const ToneMapping = {
23+
name: 'Tone Mapping',
24+
type: 'group',
25+
props: [{
26+
// @TODO
27+
name: 'Type',
28+
prop: 'toneMapping',
29+
type: 'enum',
30+
}, {
31+
name: 'Exposure',
32+
prop: 'toneMappingExposure',
33+
type: 'number',
34+
default: 1,
35+
}],
36+
};
37+
38+
const ShadowMap = {
39+
name: 'Shadow Map',
40+
type: 'group',
41+
props: [{
42+
name: 'Enabled',
43+
prop: 'shadowMap.enabled',
44+
type: 'boolean',
45+
default: false,
46+
}, {
47+
name: 'Auto Update',
48+
prop: 'shadowMap.autoUpdate',
49+
type: 'boolean',
50+
default: true,
51+
}, {
52+
// @TODO enum
53+
name: 'Shadow Type',
54+
prop: 'shadowMap.type',
55+
type: 'enum'
56+
}],
57+
};
58+
59+
const BufferClearing = {
60+
name: 'Buffer Clearing',
61+
type: 'group',
62+
props: [{
63+
name: 'Auto Clear',
64+
prop: 'autoClear',
65+
type: 'boolean',
66+
default: true,
67+
}, {
68+
name: 'Auto Clear Color',
69+
prop: 'autoClearColor',
70+
type: 'boolean',
71+
default: true,
72+
}, {
73+
name: 'Auto Clear Depth',
74+
prop: 'autoClearDepth',
75+
type: 'boolean',
76+
default: true,
77+
}, {
78+
name: 'Auto Clear Stencil',
79+
prop: 'autoClearStencil',
80+
type: 'boolean',
81+
default: true,
82+
}]
83+
};
84+
85+
86+
// Does not have a further classification yet
87+
const Capabilities = {
88+
name: 'Capabilities',
89+
type: 'group',
90+
props: [{
91+
name: 'WebGL2',
92+
prop: 'capabilities.isWebGL2',
93+
type: 'boolean',
94+
readonly: true,
95+
}, {
96+
name: 'Precision',
97+
prop: 'capabilities.precision',
98+
type: 'string',
99+
readonly: true,
100+
}, {
101+
name: 'Float Fragment Textures',
102+
prop: 'capabilities.floatFragmentTextures',
103+
type: 'boolean',
104+
readonly: true,
105+
}, {
106+
name: 'Float Vertex Textures',
107+
prop: 'capabilities.floatVertexTextures',
108+
type: 'boolean',
109+
readonly: true,
110+
}, {
111+
name: 'Logarithmic Depth Buffer',
112+
prop: 'capabilities.logarithmicDepthBuffer',
113+
type: 'boolean',
114+
readonly: true,
115+
}, {
116+
name: 'Max Anisotropy',
117+
prop: 'capabilities.maxAnisotropy',
118+
type: 'number',
119+
readonly: true,
120+
}, {
121+
name: 'Max Precision',
122+
prop: 'capabilities.maxPrecision',
123+
type: 'string',
124+
readonly: true,
125+
}, {
126+
name: 'Max Attributes',
127+
prop: 'capabilities.maxAttributes',
128+
type: 'int',
129+
readonly: true,
130+
}, {
131+
name: 'Max Cubemap Size',
132+
prop: 'capabilities.maxCubemapSize',
133+
type: 'int',
134+
readonly: true,
135+
}, {
136+
name: 'Max Fragment Uniforms',
137+
prop: 'capabilities.maxFragmentUniforms',
138+
type: 'int',
139+
readonly: true,
140+
}, {
141+
name: 'Max Texture Size',
142+
prop: 'capabilities.maxTextureSize',
143+
type: 'int',
144+
readonly: true,
145+
}, {
146+
name: 'Max Textures',
147+
prop: 'capabilities.maxTextures',
148+
type: 'int',
149+
readonly: true,
150+
}, {
151+
name: 'Max Varyings',
152+
prop: 'capabilities.maxVaryings',
153+
type: 'int',
154+
readonly: true,
155+
}, {
156+
name: 'Max Vertex Textures',
157+
prop: 'capabilities.maxVertexTextures',
158+
type: 'int',
159+
readonly: true,
160+
}, {
161+
name: 'Max Vertex Uniforms',
162+
prop: 'capabilities.maxVertexUniforms',
163+
type: 'int',
164+
readonly: true,
165+
}, {
166+
name: 'Vertex Textures',
167+
prop: 'capabilities.vertexTextures',
168+
type: 'boolean',
169+
readonly: true,
170+
}]
171+
};
172+
173+
// @TODO clippingPlanes
174+
const Clipping = {
175+
name: 'Clipping',
176+
type: 'group',
177+
props: [{
178+
name: 'Local Clipping',
179+
prop: 'localClippingEnabled',
180+
type: 'boolean',
181+
default: false,
182+
}],
183+
};
184+
185+
const Scene = {
186+
name: 'Scene',
187+
type: 'group',
188+
props: [{
189+
name: 'Sort Objects',
190+
prop: 'sortObjects',
191+
type: 'boolean',
192+
default: true,
193+
}],
194+
};
195+
196+
const MorphLimits = {
197+
name: 'Morph Limits',
198+
type: 'group',
199+
props: [{
200+
name: 'Max Morph Targets',
201+
prop: 'maxMorphTargets',
202+
type: 'int',
203+
default: 8,
204+
min: 0,
205+
max: 8,
206+
}, {
207+
name: 'Max Morph Normals',
208+
prop: 'maxMorphNormals',
209+
type: 'int',
210+
default: 4,
211+
min: 0,
212+
max: 4,
213+
}],
214+
};
215+
216+
const WebGLRenderer = {
217+
type: 'renderer',
218+
props: [
219+
{
220+
name: 'Check Shader Errors',
221+
prop: 'debug.checkShaderErrors',
222+
type: 'boolean',
223+
default: true,
224+
},
225+
PBR,
226+
ToneMapping,
227+
ShadowMap,
228+
BufferClearing,
229+
Capabilities,
230+
Clipping,
231+
Scene,
232+
MorphLimits,
233+
],
234+
};
235+
236+
export default {
237+
WebGLRenderer: WebGLRenderer,
238+
WebGL1Renderer: WebGLRenderer,
239+
};

0 commit comments

Comments
 (0)