import { Configuration } from '../configurator/configuration.js';
import { Block } from '../package/block/block.js';
import { Project } from '../project.js'
import {
Box3,
Vector3,
Box3Helper,
Quaternion,
Group
} from '../../node_modules/three/build/three.module.js';
/**
* @param {Configuration} configuration - source object ( block or configuration)
*/
const bboxLayer = Project.layerMap.boundingBox
function drawBoundingBoxes( configuration ){
var configContent = configuration.content.main.medium
//test log
//console.log( configuration )
// console.log( configuration.blockInstances )
//console.log( configContent )
// console.log( configContent.children[0].getWorldPosition(vec) )
// console.log( configContent.children[0].getWorldQuaternion(quat) )
//CREATE BOUNDINGBOXES ------------------------------
var vec = new Vector3
var quat = new Quaternion
//group to create box3 for the entire configuration
var dimGroup = new Group()
//array for all created Box3 of blocks
var allBoxes =[ ]
//check for block or configuration
if ( configuration instanceof Block ){
configContent = configContent.block
var boundingBox = configuration.boundingBox.clone()
//get world position & rotation
boundingBox.position.copy( configContent.getWorldPosition(vec) ) //apply world position
boundingBox.position.add( configuration.boundingBox.position ) //apply origin
boundingBox.quaternion.copy( configContent.getWorldQuaternion(quat) ) //apply world rotation
dimGroup.add( boundingBox )
var box = new Box3().setFromObject( boundingBox )
allBoxes.push(box)
}
else if ( configuration instanceof Configuration ){
//loop through all blockinstances and create Box3
for( var i = 0; i<configuration.blockInstances.length; i++ ){
//get the origial block boudingbox
var boundingBox = configuration.blockInstances[i].block.boundingBox.clone() //deze nog checken op id origin?
//get world position & rotation
boundingBox.position.copy( configContent.children[i].getWorldPosition(vec) ) //apply world position
boundingBox.position.add( configuration.blockInstances[i].block.boundingBox.position ) //apply origin
boundingBox.quaternion.copy( configContent.children[i].getWorldQuaternion(quat) ) //apply world rotation
dimGroup.add( boundingBox )
var box = new Box3().setFromObject( boundingBox )
allBoxes.push(box)
//add boxHelper
};
};
var boxGroup = new Box3().setFromObject( dimGroup )
//console.log( boxGroup.min, boxGroup.max )
var boxHelper = new Box3Helper( boxGroup, 0xFF0000 )
//boxHelper.visible = false;
boxHelper.layers.set( bboxLayer )
//scene.add( boxHelper )
configContent.add( boxHelper )
return boxGroup
}
export{ drawBoundingBoxes }