three-base 2.0.23 → 2.0.24
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/README.md +1 -0
- package/ThreeBase.d.ts +1 -0
- package/ThreeBase.js +27 -15
- package/ThreeBase.ts +31 -18
- package/package.json +1 -1
package/README.md
CHANGED
package/ThreeBase.d.ts
CHANGED
package/ThreeBase.js
CHANGED
|
@@ -281,6 +281,17 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
281
281
|
this.setSize(100, 100);
|
|
282
282
|
this.renderer.domElement.style.opacity = "0";
|
|
283
283
|
}
|
|
284
|
+
// 判断是否有 发光和描边的对象 以便判断是否需要 渲染深度纹理
|
|
285
|
+
hasStrokeOrPass() {
|
|
286
|
+
let has_stroke_or_pass = false;
|
|
287
|
+
this.scene.traverse(obj => {
|
|
288
|
+
const { stroke_enable = false, stroke_width = 1, glow_enable = false, glow_width = 1 } = obj.userData;
|
|
289
|
+
if ((stroke_enable && stroke_width > 0) || (glow_enable && glow_width > 0)) {
|
|
290
|
+
has_stroke_or_pass = true;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
return has_stroke_or_pass;
|
|
294
|
+
}
|
|
284
295
|
// 渲染场景
|
|
285
296
|
render() {
|
|
286
297
|
// 控制器在移动时鼠标不能操作
|
|
@@ -307,23 +318,24 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
307
318
|
}
|
|
308
319
|
// 渲染场景
|
|
309
320
|
this.dispatchEvent({ type: "beforeRender" });
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
321
|
+
const has_stroke_or_pass = this.hasStrokeOrPass();
|
|
322
|
+
if (has_stroke_or_pass) {
|
|
323
|
+
// 把基础场景渲染到 帧缓冲区 在后期通道中会用到
|
|
324
|
+
this.renderer.setRenderTarget(this.baseRenderTarget);
|
|
325
|
+
this.renderer.clear();
|
|
326
|
+
this.renderer.render(this.scene, this.camera);
|
|
327
|
+
this.renderer.setRenderTarget(null);
|
|
328
|
+
}
|
|
314
329
|
// 清空主画布
|
|
315
|
-
this.renderer.setRenderTarget(null);
|
|
316
330
|
this.renderer.clear();
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
glow_pass(this.renderer, this.camera, obj, this.baseDepthTexture);
|
|
326
|
-
});
|
|
331
|
+
this.renderer.render(this.scene, this.camera);
|
|
332
|
+
if (has_stroke_or_pass) {
|
|
333
|
+
// 查找需要绘制描边的对象,并且绘制描边
|
|
334
|
+
this.scene.traverse(obj => {
|
|
335
|
+
stroke_pass(this.renderer, this.camera, obj, this.baseDepthTexture);
|
|
336
|
+
glow_pass(this.renderer, this.camera, obj, this.baseDepthTexture);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
327
339
|
this.dispatchEvent({ type: "afterRender" });
|
|
328
340
|
}
|
|
329
341
|
renderBindThis = this.render.bind(this);
|
package/ThreeBase.ts
CHANGED
|
@@ -347,6 +347,20 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
347
347
|
this.renderer.domElement.style.opacity = "0";
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
+
// 判断是否有 发光和描边的对象 以便判断是否需要 渲染深度纹理
|
|
351
|
+
hasStrokeOrPass() {
|
|
352
|
+
let has_stroke_or_pass = false;
|
|
353
|
+
|
|
354
|
+
this.scene.traverse(obj => {
|
|
355
|
+
const { stroke_enable = false, stroke_width = 1, glow_enable = false, glow_width = 1 } = obj.userData;
|
|
356
|
+
if ((stroke_enable && stroke_width > 0) || (glow_enable && glow_width > 0)) {
|
|
357
|
+
has_stroke_or_pass = true;
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
return has_stroke_or_pass;
|
|
362
|
+
}
|
|
363
|
+
|
|
350
364
|
// 渲染场景
|
|
351
365
|
render() {
|
|
352
366
|
// 控制器在移动时鼠标不能操作
|
|
@@ -380,28 +394,27 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
380
394
|
// 渲染场景
|
|
381
395
|
this.dispatchEvent({ type: "beforeRender" } as never);
|
|
382
396
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
397
|
+
const has_stroke_or_pass = this.hasStrokeOrPass();
|
|
398
|
+
|
|
399
|
+
if (has_stroke_or_pass) {
|
|
400
|
+
// 把基础场景渲染到 帧缓冲区 在后期通道中会用到
|
|
401
|
+
this.renderer.setRenderTarget(this.baseRenderTarget);
|
|
402
|
+
this.renderer.clear();
|
|
403
|
+
this.renderer.render(this.scene, this.camera);
|
|
404
|
+
this.renderer.setRenderTarget(null);
|
|
405
|
+
}
|
|
387
406
|
|
|
388
407
|
// 清空主画布
|
|
389
|
-
this.renderer.setRenderTarget(null);
|
|
390
408
|
this.renderer.clear();
|
|
409
|
+
this.renderer.render(this.scene, this.camera);
|
|
391
410
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
// 查找需要绘制描边的对象,并且绘制描边
|
|
401
|
-
this.scene.traverse(obj => {
|
|
402
|
-
stroke_pass(this.renderer, this.camera, obj, this.baseDepthTexture);
|
|
403
|
-
glow_pass(this.renderer, this.camera, obj, this.baseDepthTexture);
|
|
404
|
-
});
|
|
411
|
+
if (has_stroke_or_pass) {
|
|
412
|
+
// 查找需要绘制描边的对象,并且绘制描边
|
|
413
|
+
this.scene.traverse(obj => {
|
|
414
|
+
stroke_pass(this.renderer, this.camera, obj, this.baseDepthTexture);
|
|
415
|
+
glow_pass(this.renderer, this.camera, obj, this.baseDepthTexture);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
405
418
|
|
|
406
419
|
this.dispatchEvent({ type: "afterRender" } as never);
|
|
407
420
|
}
|