1

At the present moment, I am writing code that cues off of the coordinates of furniture items in a 3d scene.

From what I gather, each furniture piece possesses its own coordinates which are based off of the furniture pieces parent. Whether the parent be the level or a group etc...

If the parent happens to be the "level" the furniture pieces' coordinates directly entail where the furniture piece resides in the 3d scene.

However, if a furniture piece happens to have a non-level parent, the coordinates of the furniture piece are based off of the parent(s).

Basically, in my code I am writing a recursive function that takes in a furniture node and grabs its coordinates.

As the recursive function iterates it climbs the levels of the parents and increments the original coordinates in accordance with the coordinates of the node that is currently in the function.

If the class of node currently in the function is that of "io3d-level" the recursive function will stop and return the incremented coordinates. This is because a node with a class of "io3d-level" must possess a coordinate object of {0, 0, 0}.

Again, the recursive function will iterate from the level of a furniture node and climb the structure of the parents grabbing and adding their coordinates onto the original coordinates of the furniture node until the current class of the node within the function is the level, at which point the function stops and returns the coordinates.

This recursive function appears to produce pristine results in almost all cases.

However, this function does not return pristinely accurate coordinates for a minority of furniture nodes sent through it.

The assumption behind this recursive function is that a furniture nodes' true coordinates, relative to the level, can be obtained via grabbing the coordinates of all of the furniture nodes' parents and summing them. Obviously taking into account that x coordinates are summed with x coordinates and z coordinates are summed with z coordinates.

Is this assumption false?

Am I perhaps misinterpreting the coordinate system that belies the 3d.io scenes?

2 Answers2

1

This can be done directly without inaccuracies using the three.js handle.

let worldCoordinates = obj.data3dView.threeParent.getWorldPosition();
Sam Johnson
  • 624
  • 1
  • 7
  • 20
0

I assume something goes wrong in your code

So best is to share your code, so we don't have to guess.

Here is a small snippet that applies the parent location for an element when dealing with scene structure

// apply parent location
function applyLocation(element, parent) {
  // Rotate element on the XZ plane around parent's center
  var angleY = -parent.ry * Math.PI / 180
  var rotatedX = element.x * Math.cos(angleY) - element.z * Math.sin(angleY)
  var rotatedZ = element.z * Math.cos(angleY) + element.x * Math.sin(angleY)

  // Get parent space coordinates for our element
  element.x = parent.x + rotatedX
  element.y += parent.y
  element.z = parent.z + rotatedZ
  element.ry += parent.ry
  return element
}
Frederic
  • 326
  • 1
  • 5
  • Thank you so much for your feedback Frederic. – Kashi Halma Jun 04 '18 at 13:24
  • please click the green check if the answer solved your problem – Frederic Jun 08 '18 at 09:09
  • 1
    Greetings Frederic, I will go forth and click the green check. First i'd like to share how me and one of my colleagues were able to arrive at our desired point in this 3d.io endeavor. In a basic sense, all me and my colleague wanted was to get the world coordinates of every single furniture piece. Our original approach was to climb the furniture nodes parent structures, grabbing their coordinates whilst taking into account factors such as rotation. We found that we could simply use let worldCoordinates = furniture.data3dView.threeParent.getWorldPosition(); which gave us exactly what we wanted. – Kashi Halma Jun 10 '18 at 20:50