archilogic-com / 3dio-js

JavaScript toolkit for interior apps
https://3d.io
MIT License
273 stars 73 forks source link

Waypoints position and rotation are empty from the scene api #114

Closed Aadjou closed 6 years ago

Aadjou commented 6 years ago

Bug report from SO

How to reproduce

Expected result

Actual result

AVGP commented 6 years ago

Just chiming in here, because this coincides with an observation I made. There's definitely an improvement in here, because I think that looking at the DOM should always reflect the truth* and in this case it doesn't.

However, what I wanted to make y'all aware of is: The DOM itself only supports strings in attributes, i.e. setAttribute('position', '1 2 3') is good, but setAttribute('position', {x: 1, y: 2, z: 3}) is invalid in vanilla DOM. In A-Frame this is fine, tho, because they overwrite setAttribute and getAttribute accordingly. For performance reasons this isn't necessarily reflected back to the DOM in string form (as that conversion costs computation cycles), but it should work.

I think getAframeElements uses the object form when setting the attributes, which I think we might wanna change to the string form, because:

I'm happy to take this issue up, @frederic-schwarz, if you wish me to :)

frederic-schwarz commented 6 years ago

to-aframe-elements.js currently uses strings for setting attributes like here https://github.com/archilogic-com/3dio-js/blob/master/src/scene/structure/to-aframe-elements.js#L292 or here https://github.com/archilogic-com/3dio-js/blob/master/src/scene/structure/to-aframe-elements.js#L175

AVGP commented 6 years ago

So it turns out that the data gets returned just fine:

  document.querySelector('[tour-waypoint]').getAttribute('position') // returns {x: 1, y: 2, z: 3} etc.

You can observe this behaviour in this glitch.

However, we assume you'd want to use the HTML in some way, e.g. use innerHTML to send this to a server. In that case, you need to call element.flushToDom() before, as documented here.

Here is code demonstrating this. When you look at the code you get after clicking the button, you'll see that the elements where flushToDOM was used show up correctly in the text, but the box that was dynamically created (and is a built-in A-Frame element!) does not.