Hey all,
I’m currently trying to make a ‘dungeon generator’ - I have a set few Scene objects that each have an EntryNode, ExitNode and Room mesh inside of it. I’m having trouble setting the position of the Room object based on the previous’ room ExitNode.
The model is structured like so:
Scene
L Entry_Node (instanceof THREE.Mesh) position: 0,0,0
L Room (instaceof THREE.Group), positiom 0,0,23
L (Several Children that are irrelevant)
L Exit_Node position: 0,0,46
Rooms aren’t guaranteed to be uniform in size or always be the same size, otherwise this would be simple.
I’m currently creating a room like so:
_generateRoom(name) {
let room = common.assets.model(name); // Returns THREE.Scene with EntryNode, Room and ExitNode as children
const entryNode = room.children.find(e => e.name.startsWith('Node_Entry'));
const exitNode = room.children.find(e => e.name.startsWith('Node_Exit'));
return [room, entryNode, exitNode];
}
And I’m trying to attach multiple of these rooms like so:
_preGenerate(count) {
let rooms = [];
for (let i = 0; i < count; i++) {
const room = this._generateRoom('endless_straight3'); // Returns an array as [Room, EntryNode, ExitNode]
this._stage.add(room[0]);
room[0].updateMatrixWorld();
if (rooms.length > 0) {
this._exitNode.updateMatrixWorld(true);
this._exitNode.getWorldPosition(room[0].position);
} else {
room[0].position.setScalar(0);
}
this._exitNode = room[2];
console.log(room[0].position);
rooms.push(room);
}
}
However, the issue is that at this._exitNode.getWorldPosition(room[0].position);
- it always returns (seemingly) the local postion of the exit node - THREE.Vector3(0, 0, 46)
I expect it to return the position of the exit node based on the world position - so 46 for the first room, 92 for the second room, 138 for the third, and so on.
Not sure what’s going wrong here, any help is appreciated!
cc. https://stackoverflow.com/questions/56129746/trouble-getting-world-position-of-object-in-three-js