Skip to content

Commit

Permalink
fix: create renderer3d component in picking plugin #1094
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Jun 14, 2023
1 parent f64e45d commit 136ddfd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 13 additions & 7 deletions packages/g-plugin-device-renderer/src/PickingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import type { BatchManager } from './renderer';
import type { RenderGraphPlugin } from './RenderGraphPlugin';
import { SceneUniform, SceneUniformBufferIndex } from './RenderGraphPlugin';
import { Renderable3D } from './components/Renderable3D';

/**
* max depth when doing multi-layer picking
Expand Down Expand Up @@ -53,15 +54,20 @@ export class PickingPlugin implements RenderingPlugin {

const handleMounted = (e: FederatedEvent) => {
const object = e.target as DisplayObject;

// @ts-ignore
const renderable3D = object.renderable3D;
if (renderable3D) {
// generate picking id for later use
const pickingId = this.pickingIdGenerator.getId(object);
renderable3D.pickingId = pickingId;
renderable3D.encodedPickingColor =
this.pickingIdGenerator.encodePickingColor(pickingId);
if (!object.renderable3D) {
// @ts-ignore
object.renderable3D = new Renderable3D();
}

// @ts-ignore
const renderable3D = object.renderable3D;
// generate picking id for later use
const pickingId = this.pickingIdGenerator.getId(object);
renderable3D.pickingId = pickingId;
renderable3D.encodedPickingColor =
this.pickingIdGenerator.encodePickingColor(pickingId);
};

renderingService.hooks.init.tap(PickingPlugin.tag, () => {
Expand Down
10 changes: 4 additions & 6 deletions packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ export class RenderGraphPlugin implements RenderingPlugin {
return;
}

const renderable3D = new Renderable3D();

// add geometry & material required by Renderable3D
// object.entity.addComponent(Geometry3D);
// object.entity.addComponent(Material3D);
// @ts-ignore
object.renderable3D = renderable3D;
if (!object.renderable3D) {
// @ts-ignore
object.renderable3D = new Renderable3D();
}

this.batchManager.add(object);
};
Expand Down

0 comments on commit 136ddfd

Please sign in to comment.