bimspot / xeokit-react

Integratation of the xeokit viewer into a React application.
33 stars 22 forks source link

New feature request #6

Closed chloesun closed 5 years ago

chloesun commented 5 years ago

I'm trying to extend the functionality of GLTFViewer component. One method is to highlight the entity based on the given id, and another one is to reset the view, and I tried to implement by myself:

  highlightEntity = (id) => {
    let lastEntity = null;
    const { scene } = this.viewer;
    const currentEntity = scene.objects[id];  // return undefined here
    if (!lastEntity || id !== lastEntity.id) {
      if (lastEntity) {
        lastEntity.highlighted = false;
      }
      lastEntity = currentEntity;
      currentEntity.highlighted = true;
    } else {
      if (lastEntity) {
        lastEntity.highlighted = false;
        lastEntity = null;
      }
    }
    currentEntity.highlighted = true;
  };

While trying to console.log(scene.objects), I was expecting to get the object contains all the objects, but I got an empty object { }, but when I click the little triangle, I can see the objects inside..and I can't access the value. Hovering the little i icon, it shows Value below was evaluated just now log

About resetting the view, I found this https://xeokit.github.io/xeokit-sdk/docs/class/src/viewer/Viewer.js~Viewer.html#instance-method-resetView,

resetView=( )=>{
 this.viewer.resetView();
}

and I added a button in the render method to trigger resetView, but this doesn't work...

Hope to get some input from you guys, thanks!

barnabasmolnar commented 5 years ago

Regarding your 2nd question:

I believe I've already run into this issue and I seem to recall that the resetView method is not fully implemented in the xeokit library:

https://xeokit.github.io/xeokit-sdk/docs/file/src/viewer/Viewer.js.html#lineNumber241

Might be worth opening an issue about this over there.

As for your highlighting question, I'll try and have a look at it sometime in the near future hopefully.

chloesun commented 5 years ago

@barnabasmolnar Thanks, I already submitted an issue over there, just found this method https://xeokit.github.io/xeokit-sdk/docs/class/src/viewer/scene/scene/Scene.js~Scene.html#instance-method-setObjectsHighlighted looks like it may solve my first issue

chloesun commented 5 years ago

I tried to use that method and it leads to the same problem. I tested with an id of an object and went through the debugger to figure out what's wrong:

12 11 Pass this.objects to _withEntities and you can see the this.objects which is entities is an empty{ } object, so no entity is selected and highlighted. @xeolabs