1

This is quite hard to understand, I am working with current xml3D.js version 5.2.

I am plaing with *BoundingBox() functions to ease the positioning of assets & cameras. Contents are properly loaded, The error appears unsing an xml3D assets file. It there anything specific to the xml3D assets ?.

The xml3D contents

Following is derived from https://github.com/xml3d/xml3d.js/wiki/Using-Assets-and-Models

<body>
<xml3d class="xml3d" view="#defaultView">
    <defs>
      <!-- camera position -->
      <transform id="t_camera" translation="0 0 40" rotation="0 1 0 0"></transform>
      <transform id="m_transform" scale="0.1 0.1 0.1"></transform>
      <transform id="t_Lamp" translation="0 0 -400"></transform>
      <transform id="r_Lamp" rotation="1 0 0 -0.2"></transform>

      <!-- permanent light -->
      <lightshader id="ls_directional" script="urn:xml3d:lightshader:directional">
          <float3 name="intensity">0.6 0.6 0.6</float3>
      </lightshader>
      <transform id="t_directional" rotation="1 0 0 -0.2" />
      <!-- //permanent light -->
    </defs>

    <!-- Our viewpoint from where we see the 3D content -->
    <group id="viewGroup" transform="#t_camera">
        <view id="defaultView"></view>
    </group>

    <!-- permanent light -->
    <group transform="#t_directional">
        <light shader="#ls_directional"></light>
    </group>
    <!-- //permanent light -->

     <!-- our model include -->
    <group transform="#m_transform">
     <model id="xmlmodel" src="ciccio.xml#ciccio"></model>
    </group>
</xml3d>
</body>
<script>
  // attach event to the mesh
document.querySelector("#xmlmodel").addEventListener("click", function() {
    var model = document.getElementById("xmlmodel");
    alert("my center is " + model.getLocalBoundingBox().center().toDOMString());
});
</script>

So when I click on the model, it runs the specified call to getLocalBoundingBox() and throws the error :

getLocalBoundingBox — xml3d.js:15685TypeError: this.renderNode.getObjectSpaceBoundingBox is not a function. (In 'this.renderNode.getObjectSpaceBoundingBox(bbox)', 'this.renderNode.getObjectSpaceBoundingBox' is undefined)

jbheren
  • 516
  • 3
  • 11

1 Answers1

2

Sorry you were having trouble with this, it seems like a bug slipped in during one of the recent updates. I've pushed a fix to the upcoming 5.2.2 patch and uploaded a preview build for you to try: xml3d-5.2.2-min.js

If you're going to be using this to position cameras though you may want to use getWorldBoundingBox instead, as the local bounding box doesn't take into account any transformations coming from higher up in the hierarchy (for example your <group transform="#m_transform">. So you'd get a bounding box for the model itself but it may not be at the same location in the scene.

csvurt
  • 236
  • 1
  • 2
  • I am not sure to understand how positioning works. If I set the camera's `examinePoint:` value to the `model.getWorldBoundingBox().center()`, it looks like the rotation origin is set between the camera and the model . I expected this rotation origin point to be the center of the model so that model can "rotate on itself" when draging mouse. Any advise ? – jbheren Nov 21 '16 at 23:23
  • Try removing the transformation on the camera's parent `` element. This transform is basically moving the camera an additional 40 units on the z-axis _after_ the camera's own transformation (inc. examinePoint) is calculated. That's why the rotation center seems to be off. You could also try using the `camera.examine(model)` function. This is a convenience function but you'll still have to remove the parent transformation. – csvurt Nov 22 '16 at 08:24