//https://furnishup.github.io/blueprint3d/example/#
import { Reporter } from '../reporter/reporter.js';
import { checkPropTypes } from '../lib.js';
import { BuildableComponent } from '../package/component/buildable_component.js';
import { WrappedMaterial } from '../package/material/wrapped_material.js';
import { Project } from '../project.js';
import {
PlaneGeometry,
Vector3,
Mesh,
MeshBasicMaterial
} from '../../node_modules/three/build/three.module.js';
/**
* Create a space with floor and walls based on the given parameters
* ToDo:
* - copy workings of furnishup
* - create a 2D view?
*
* */
class Space extends BuildableComponent {
/**
* @param {Reporter} reporter
* @param {Object} settings
* @param {UUID} [settings.id]
* @param {string} [settings.name]
* @param {Vector3} [settings.dimensions]
*/
constructor( reporter, settings ) {
super(
reporter,
settings
);
checkPropTypes(
settings,
{
name: "string",
dimensions: Vector3,
},
{
material: WrappedMaterial
}
);
this._name = settings.name;
this._dimensions = settings.dimensions;
this._material = settings.material;
}
static _exportName = {
singular: 'space',
plural: 'spaces'
};
async _build( part ){
const quality = 'medium';
this._status[ part ][ quality ].setState( 'loading');
switch (part) {
case 'UI':
if (this._settings.thumbnail) {
this._setContent('UI', quality, this._settings.thumbnail.content.main[quality]);
}
else {
this._setContent('UI', quality, Project.defaultImages.missing.cloneNode(true));
}
break;
case 'main':
console.log( "build()");
const geometry = new PlaneGeometry( this._dimensions.x, this._dimensions.y );
//console.log( "geo", geometry)
let material;
if( this.material ){
material = this.material.content.main.medium;
}else{
material = new MeshBasicMaterial( {color: 0xffff00, side: THREE.DoubleSide} );
}
//console.log( "mat", material)
const floorPlane = new Mesh( geometry, material );
//console.log( floorPlane )
//return floorPlane
this._setContent( 'main', quality, floorPlane );
break;
}
return this;
}
}
export { Space };