46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
const RailingObjectGame = (function(){
|
|
|
|
const RailingObjectGame = function(hollow_bond, segment, material, room_model){
|
|
|
|
const self = this;
|
|
this.segment = segment;
|
|
this.collider = new RailingCollider(hollow_bond, segment);
|
|
|
|
const world_cx = (segment.xf + segment.xt) * 0.5;
|
|
const world_cz = (segment.zf + segment.zt) * 0.5;
|
|
|
|
const room_cx = room_model.x + (room_model.width * 0.5);
|
|
const room_cz = room_model.z + (room_model.depth * 0.5);
|
|
|
|
const local_x = world_cx - room_cx;
|
|
const local_y = -room_model.height * 0.5;
|
|
const local_z = world_cz - room_cz;
|
|
|
|
const geom_fac = (hollow_bond.geometries && hollow_bond.geometries.railing)
|
|
|| (hollow_bond.dungeon && hollow_bond.dungeon.geometries && hollow_bond.dungeon.geometries.railing)
|
|
|| new RailingGeometryGame(hollow_bond);
|
|
|
|
const mat_fac = (hollow_bond.materials && hollow_bond.materials.railing)
|
|
|| (hollow_bond.dungeon && hollow_bond.dungeon.materials && hollow_bond.dungeon.materials.railing)
|
|
|| new RailingMaterialGame(hollow_bond);
|
|
|
|
// Si material es null o undefined, obtenemos uno válido directamente
|
|
const resolved_material = material || mat_fac.get();
|
|
|
|
const geometry = geom_fac.get_for_segment(segment);
|
|
|
|
this.mesh = new THREE.Mesh(geometry, resolved_material);
|
|
this.mesh.position.set(local_x, local_y, local_z);
|
|
|
|
this.destroy = () => {
|
|
if(self.mesh && self.mesh.parent){
|
|
self.mesh.parent.remove(self.mesh);
|
|
}
|
|
};
|
|
|
|
};
|
|
|
|
return RailingObjectGame;
|
|
})(); |