kfarr / aframe-city-builder

🏗️ A-Frame project demonstrating touch controls for building a VR city scene
https://aframe.city
MIT License
87 stars 37 forks source link

the new 'erase' feature screws up placing new objects #20

Closed kfarr closed 7 years ago

kfarr commented 7 years ago

when working with a scene that has some objects deleted, new objects that are placed sometimes spawn an unexpected object. when saving these cities, they don't reload as expected.

i think this is due to the mechanism of assigning an ID to newly placed objects: https://github.com/kfarr/aframe-city-builder/blob/master/lib/builder-controls.js#L185

as newly placed objects are given an id of 'object' + document.getElementById('city').childElementCount;, if a scene has deleted items then newly created items might have the same ID as an object already on the scene, resulting in this odd behavior.

a fix would be to generate a near-random UUID for each newly created object. this will break the rudimentary undo feature which needs an overhaul anyway.

kfarr commented 7 years ago

simple guid generator here: https://jsfiddle.net/briguy37/2MVFd/

saving should be tested again