vue-gl / vue-gl

Vue.js components rendering 3D WebGL graphics reactively with three.js

Home Page:https://vue-gl.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Require name for objects tracked in vgl-namespace?

unreal opened this issue · comments

First of all, thank you for your work on this! I am excited to build something with vue-gl shortly and hoping to contribute.

I am not sure if this is a legitimate issue, but I was confused when my scene stopped working as soon as I added a name to my camera. It turns out that the vgl-renderer gets the camera from vgl-namespace via it's optional camera prop. The name prop on cameras is also optional.

This ends up working ok by default since the lookup finds the camera by looking up the 'undefined' key in vglNamespace.cameras, but it can be problematic. For example, if I create two unnamed cameras within a vgl-renderer, the last one overwrites the first within the vgl-namespace.

Maybe this is intentional, but I wonder if it would be better to require the name property on objects that get stored in vgl-namespace by name (e.g. scenes, cameras, geometries, etc.)

I thought that usually one camera and one scene are set, so it would be used conveniently without naming. But as you say, it might confuse...
To achieve both of them, I'd like to handle case of the camera or scene prop is undefined.

I thought that usually one camera and one scene are set, so it would be used conveniently without naming.

I figured that was your intent as well, but I think I saw one other issue where someone had a similar experience.

What about this:

In the case where a VglRenderer does not specify a camera, it checks the VglNamespace for cameras. If there is only one defined, it uses that one regardless of the camera's name. If there is more than one it throws an error saying that the camera prop is required when more than one camera is available.

I assume (but I'm not sure) that THREE.js will throw an error if the camera prop is passed in with an invalid camera name.

I also think it would be a good idea to add methods to VglNamespace for things like adding cameras, scenes, etc. to make sure the keys are not overwritten e.g. in the case where someone has two cameras with no name prop.

Thank you for your suggestions.

to make sure the keys are not overwritten e.g. in the case where someone has two cameras with no name prop.

Sounds good, developer friendly.
I divided it to another issue to simplify tasks.

then,
TODO:

  • VglRenderer should throw error when camera is undefined and two or more cameras exists.
  • VglRenderer should use the any camera when camera is undefined and only one camera exists.
  • same for scenes.
  • check if an error is thrown when the specified (by name) camera does not exist.