gohyperr / hecs

A high performance lightweight ECS with a plugin ecosystem!
MIT License
23 stars 1 forks source link

Rendering objects with CSS3DRenderer #21

Closed canadaduane closed 3 years ago

canadaduane commented 4 years ago

I'm having a bit of difficulty getting Three's CSS3DRenderer to work in conjunction with hecs-plugin-three.

I want the ability to render both Object3D-type objects as well as CSS3DObject-type objects. Each is added to a separate three.js scene graph, but both share the same camera and transform data.

The problem seems to be that hecs-plugin-three assumes that an entity with component WorldTransform should automatically get an Object3D component added:

export class Object3DSystem extends System {
  order = Groups.Initialization

  static queries = {
    new: [WorldTransform, Not(Object3D)],
    active: [WorldTransform, Object3D],
    removed: [Not(WorldTransform), Object3D],
  }
...
  update() {
    this.queries.new.forEach(entity => {
      const object3d = new THREE.Object3D()
      object3d.name = entity.name
      object3d.userData.entityId = entity.id
      this.presentation.scene.add(object3d)
      this.presentation.object3ds.push(object3d)
      entity.add(Object3D, { value: object3d })
    })
...

WorldTransform is part of hecs-plugin-core, and gets added automatically when a Transform component is added to the entity. If I include hecs-plugin-three, then every entity automatically also gets an Object3D added as well.

I'm trying to think of a way to tell hecs-plugin-three that for this particular entity with WorldTransform, don't add the Object3D component to it, and don't add it to the presentation.scene graph. Let me handle it elsewhere (i.e. by a CSSObject3DSystem, for example).

canadaduane commented 4 years ago

I think I mostly have this working now. It turned out that in order to create mixed-mode HTML+WebGL, I needed an Object3D anyway, so although it might be nice to not add Object3D when unnecessary, it's no longer pressing for me.

ashconnell commented 3 years ago

Yeah hecs-plugin-three might be a confusing name but the intention was to only support the WebGLRenderer.

It would probably be better to have a separate plugin but I might be wrong?

canadaduane commented 3 years ago

I think we can close this. It was flexible enough for me, and I agree a more complex setup might merit a separate plugin.