/**
* The base shape
* @constructor
* @param {THREE.Vector3} points that define the shape
*/
class Shape {
constructor(points) {
/**
* The shape's container which is an empty mesh
* @type {THREE.Mesh}
*/
this.mesh = new THREE.Mesh();
this.id = this.mesh.id;
this.mat = new THREE.MeshBasicMaterial({color: 0x0000ff, transparent: true, opacity: .5, side: THREE.DoubleSide});
this.underMat = new THREE.MeshBasicMaterial({color: 0x0000ff, side:
THREE.DoubleSide});
/**
* all the points that represent the shape
*/
this.points = points;
this.updateBgMesh();
this.createUnderMesh();
/* this.createPerpendicularCornerLine() */;
}
/**
* helper to draw lines at corners to the under decking
*/
createPerpendicularCornerLine(){
var index = 0;
var points = vec2sToVec3s(this.points);
points.forEach((point) => {
var lineGeo = new THREE.Geometry();
var p1 = point.clone();
var p2 = p1.clone();
var w = this.underDeckingMesh.geometry.vertices[index];
p2.copy(w);
lineGeo.vertices.push(p1, p2);
var lineMat = new THREE.LineBasicMaterial({color:0xff00ff});
var line = new THREE.Line(lineGeo, lineMat);
this.mesh.add(line);
index++;
});
}
/**
* The background mesh.
* Updates only on finalize.
*/
updateBgMesh() {
if (this.bgMesh) {
this.mesh.remove(this.bgMesh);
}
var pointType = this.points[0];
var levelGeo;
if(pointType instanceof THREE.Vector2){
levelGeo = this.createShape2dGeo(this.points);
} else if(pointType instanceof THREE.Vector3){
throw new Error('points are not type vector2');
}
this.bgMesh = new THREE.Mesh(levelGeo, this.mat);
this.bgMesh.name = 'bgMesh';
this.mesh.add(this.bgMesh);
}
/**
* Create and returns a...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.