face select mode - cylinder updates
parent
b3d9556461
commit
e22904841a
|
@ -154,7 +154,7 @@ GameLib.D3.API.Material = function(
|
||||||
this.materialType = materialType;
|
this.materialType = materialType;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = 'Material (' + materialType + ')';
|
name = 'Material (' + this.id + ')';
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
/**
|
||||||
|
* Raw Mesh.Cylinder API object
|
||||||
|
* @constructor
|
||||||
|
* @param apiMesh
|
||||||
|
* @param radiusTop
|
||||||
|
* @param radiusBottom
|
||||||
|
* @param height
|
||||||
|
* @param radiusSegments
|
||||||
|
* @param heightSegments
|
||||||
|
* @param openEnded
|
||||||
|
* @param thetaStart
|
||||||
|
* @param thetaLength
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Mesh.Cylinder = function(
|
||||||
|
apiMesh,
|
||||||
|
radiusTop,
|
||||||
|
radiusBottom,
|
||||||
|
height,
|
||||||
|
radiusSegments,
|
||||||
|
heightSegments,
|
||||||
|
openEnded,
|
||||||
|
thetaStart,
|
||||||
|
thetaLength
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
|
||||||
|
apiMesh = {
|
||||||
|
meshType : GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(radiusTop)) {
|
||||||
|
radiusTop = 1;
|
||||||
|
}
|
||||||
|
this.radiusTop = radiusTop;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(radiusBottom)) {
|
||||||
|
radiusBottom = 1;
|
||||||
|
}
|
||||||
|
this.radiusBottom = radiusBottom;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
|
height = 5;
|
||||||
|
}
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(radiusSegments)) {
|
||||||
|
radiusSegments = 10;
|
||||||
|
}
|
||||||
|
this.radiusSegments = radiusSegments;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
|
||||||
|
heightSegments = 10;
|
||||||
|
}
|
||||||
|
this.heightSegments = heightSegments;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(openEnded)) {
|
||||||
|
openEnded = false;
|
||||||
|
}
|
||||||
|
this.openEnded = openEnded;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(thetaStart)) {
|
||||||
|
thetaStart = 0;
|
||||||
|
}
|
||||||
|
this.thetaStart = thetaStart;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(thetaLength)) {
|
||||||
|
thetaLength = Math.PI * 2;
|
||||||
|
}
|
||||||
|
this.thetaLength = thetaLength;
|
||||||
|
|
||||||
|
GameLib.D3.API.Mesh.call(
|
||||||
|
this,
|
||||||
|
apiMesh.id,
|
||||||
|
apiMesh.meshType,
|
||||||
|
apiMesh.name,
|
||||||
|
apiMesh.vertices,
|
||||||
|
apiMesh.faces,
|
||||||
|
apiMesh.materials,
|
||||||
|
apiMesh.parentMesh,
|
||||||
|
apiMesh.parentScene,
|
||||||
|
apiMesh.skeleton,
|
||||||
|
apiMesh.skinIndices,
|
||||||
|
apiMesh.skinWeights,
|
||||||
|
apiMesh.position,
|
||||||
|
apiMesh.quaternion,
|
||||||
|
apiMesh.rotation,
|
||||||
|
apiMesh.scale,
|
||||||
|
apiMesh.up,
|
||||||
|
apiMesh.modelMatrix,
|
||||||
|
apiMesh.renderOrder,
|
||||||
|
apiMesh.isBufferMesh,
|
||||||
|
apiMesh.useQuaternion,
|
||||||
|
apiMesh.visible,
|
||||||
|
apiMesh.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Mesh.Cylinder.prototype = Object.create(GameLib.D3.API.Mesh.prototype);
|
||||||
|
GameLib.D3.API.Mesh.Cylinder.prototype.constructor = GameLib.D3.API.Mesh.Cylinder;
|
|
@ -224,6 +224,7 @@ GameLib.D3.Face.prototype.createHelper = function(mesh) {
|
||||||
g: this.color.g,
|
g: this.color.g,
|
||||||
b: this.color.b
|
b: this.color.b
|
||||||
},
|
},
|
||||||
|
|
||||||
material : {
|
material : {
|
||||||
emissive : {
|
emissive : {
|
||||||
r: mesh.materials[this.materialIndex].emissive.r,
|
r: mesh.materials[this.materialIndex].emissive.r,
|
||||||
|
@ -234,20 +235,27 @@ GameLib.D3.Face.prototype.createHelper = function(mesh) {
|
||||||
vertexColors : mesh.materials[this.materialIndex].vertexColors
|
vertexColors : mesh.materials[this.materialIndex].vertexColors
|
||||||
};
|
};
|
||||||
|
|
||||||
this.instance.color.r = 1;
|
this.instance.vertexColors = [
|
||||||
this.instance.color.g = 0;
|
new THREE.Color(1,0,0),
|
||||||
this.instance.color.b = 0;
|
new THREE.Color(0,1,0),
|
||||||
|
new THREE.Color(0,0,1)
|
||||||
|
];
|
||||||
|
|
||||||
|
// this.instance.color.r = 1;
|
||||||
|
// this.instance.color.g = 0;
|
||||||
|
// this.instance.color.b = 0;
|
||||||
|
|
||||||
mesh.instance.geometry.colorsNeedUpdate = true;
|
|
||||||
//
|
//
|
||||||
// mesh.materials[this.materialIndex].emissive.r = 0.5;
|
// mesh.materials[this.materialIndex].emissive.r = 0.5;
|
||||||
// mesh.materials[this.materialIndex].emissive.g = 0.5;
|
// mesh.materials[this.materialIndex].emissive.g = 0.5;
|
||||||
// mesh.materials[this.materialIndex].emissive.b = 0.5;
|
// mesh.materials[this.materialIndex].emissive.b = 0.5;
|
||||||
// mesh.materials[this.materialIndex].updateInstance('emissive');
|
// mesh.materials[this.materialIndex].updateInstance('emissive');
|
||||||
|
|
||||||
mesh.materials[this.materialIndex].vertexColors = GameLib.D3.Material.TYPE_FACE_COLORS;
|
mesh.materials[this.materialIndex].vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
|
||||||
mesh.materials[this.materialIndex].updateInstance('vertexColors');
|
mesh.materials[this.materialIndex].updateInstance('vertexColors');
|
||||||
|
|
||||||
|
mesh.instance.geometry.elementsNeedUpdate = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Face.prototype.removeHelper = function(mesh) {
|
GameLib.D3.Face.prototype.removeHelper = function(mesh) {
|
||||||
|
|
|
@ -584,6 +584,18 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
||||||
if (property === 'materials') {
|
if (property === 'materials') {
|
||||||
if (this.materials.length === 1 && this.materials[0].instance) {
|
if (this.materials.length === 1 && this.materials[0].instance) {
|
||||||
this.instance.material = this.materials[0].instance;
|
this.instance.material = this.materials[0].instance;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var materialInstances = this.materials.map(
|
||||||
|
function(material) {
|
||||||
|
|
||||||
|
var materialInstance = material.instance;
|
||||||
|
|
||||||
|
return materialInstance;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance.material = materialInstances;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,83 +1,39 @@
|
||||||
/**
|
/**
|
||||||
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
||||||
* @param graphics GameLib.GraphicsRuntime
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
* @param apiMesh GameLib.D3.API.Mesh
|
* @param apiMeshCylinder
|
||||||
* @param radiusTop
|
|
||||||
* @param radiusBottom
|
|
||||||
* @param height
|
|
||||||
* @param radiusSegments
|
|
||||||
* @param heightSegments
|
|
||||||
* @param openEnded
|
|
||||||
* @param thetaStart
|
|
||||||
* @param thetaLength
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.Cylinder = function (
|
GameLib.D3.Mesh.Cylinder = function (
|
||||||
graphics,
|
graphics,
|
||||||
apiMesh,
|
apiMeshCylinder
|
||||||
radiusTop,
|
|
||||||
radiusBottom,
|
|
||||||
height,
|
|
||||||
radiusSegments,
|
|
||||||
heightSegments,
|
|
||||||
openEnded,
|
|
||||||
thetaStart,
|
|
||||||
thetaLength
|
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiMeshCylinder)) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
|
apiMeshCylinder = {
|
||||||
apiMesh = {
|
meshType : GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER
|
||||||
meshType: GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(radiusTop)) {
|
GameLib.D3.API.Mesh.Cylinder.call(
|
||||||
radiusTop = 1;
|
this,
|
||||||
}
|
apiMeshCylinder,
|
||||||
this.radiusTop = radiusTop;
|
apiMeshCylinder.radiusTop,
|
||||||
|
apiMeshCylinder.radiusBottom,
|
||||||
if (GameLib.Utils.UndefinedOrNull(radiusBottom)) {
|
apiMeshCylinder.height,
|
||||||
radiusBottom = 1;
|
apiMeshCylinder.radiusSegments,
|
||||||
}
|
apiMeshCylinder.heightSegments,
|
||||||
this.radiusBottom = radiusBottom;
|
apiMeshCylinder.openEnded,
|
||||||
|
apiMeshCylinder.thetaStart,
|
||||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
apiMeshCylinder.thetaLength
|
||||||
height = 5;
|
);
|
||||||
}
|
|
||||||
this.height = height;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(radiusSegments)) {
|
|
||||||
radiusSegments = 10;
|
|
||||||
}
|
|
||||||
this.radiusSegments = radiusSegments;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
|
|
||||||
heightSegments = 10;
|
|
||||||
}
|
|
||||||
this.heightSegments = heightSegments;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(openEnded)) {
|
|
||||||
openEnded = false;
|
|
||||||
}
|
|
||||||
this.openEnded = openEnded;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(thetaStart)) {
|
|
||||||
thetaStart = 0;
|
|
||||||
}
|
|
||||||
this.thetaStart = thetaStart;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(thetaLength)) {
|
|
||||||
thetaLength = Math.PI * 2;
|
|
||||||
}
|
|
||||||
this.thetaLength = thetaLength;
|
|
||||||
|
|
||||||
GameLib.D3.Mesh.call(
|
GameLib.D3.Mesh.call(
|
||||||
this,
|
this,
|
||||||
this.graphics,
|
graphics,
|
||||||
apiMesh
|
apiMeshCylinder
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,38 +59,20 @@ GameLib.D3.Mesh.Cylinder.prototype.createInstance = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||||
|
|
||||||
this.instance.userData.radiusTop = this.radiusTop;
|
|
||||||
this.instance.userData.radiusBottom = this.radiusBottom;
|
|
||||||
this.instance.userData.height = this.height;
|
|
||||||
this.instance.userData.radiusSegments = this.radiusSegments;
|
|
||||||
this.instance.userData.heightSegments = this.heightSegments;
|
|
||||||
this.instance.userData.openEnded = this.openEnded;
|
|
||||||
this.instance.userData.thetaStart = this.thetaStart;
|
|
||||||
this.instance.userData.thetaLength = this.thetaLength;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Mesh.Cylinder.prototype.updateInstance = function(property) {
|
GameLib.D3.Mesh.Cylinder.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.instance.userData.radiusTop !== this.radiusTop ||
|
property === 'radiusTop' ||
|
||||||
this.instance.userData.radiusBottom !== this.radiusBottom ||
|
property === 'radiusBottom' ||
|
||||||
this.instance.userData.height !== this.height ||
|
property === 'height' ||
|
||||||
this.instance.userData.radiusSegments !== this.radiusSegments ||
|
property === 'radiusSegments' ||
|
||||||
this.instance.userData.heightSegments !== this.heightSegments ||
|
property === 'heightSegments' ||
|
||||||
this.instance.userData.openEnded !== this.openEnded ||
|
property === 'openEnded' ||
|
||||||
this.instance.userData.thetaStart !== this.thetaStart ||
|
property === 'thetaStart' ||
|
||||||
this.instance.userData.thetaLength !== this.thetaLength
|
property === 'thetaLength'
|
||||||
) {
|
) {
|
||||||
this.instance.userData.radiusTop = this.radiusTop;
|
|
||||||
this.instance.userData.radiusBottom = this.radiusBottom;
|
|
||||||
this.instance.userData.height = this.height;
|
|
||||||
this.instance.userData.radiusSegments = this.radiusSegments;
|
|
||||||
this.instance.userData.heightSegments = this.heightSegments;
|
|
||||||
this.instance.userData.openEnded = this.openEnded;
|
|
||||||
this.instance.userData.thetaStart = this.thetaStart;
|
|
||||||
this.instance.userData.thetaLength = this.thetaLength;
|
|
||||||
|
|
||||||
var geometry = new THREE.CylinderGeometry(
|
var geometry = new THREE.CylinderGeometry(
|
||||||
this.radiusTop,
|
this.radiusTop,
|
||||||
this.radiusBottom,
|
this.radiusBottom,
|
||||||
|
@ -153,7 +91,6 @@ GameLib.D3.Mesh.Cylinder.prototype.updateInstance = function(property) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
|
GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,26 +114,30 @@ GameLib.D3.Mesh.Cylinder.prototype.toApiObject = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a standard object mesh to a GameLib.D3.Mesh
|
* This function turns the cylinder into a 'display' where each plane on the cylinder is mapped onto a flat texture
|
||||||
* @param graphics GameLib.GraphicsRuntime
|
|
||||||
* @param objectMesh {Object}
|
|
||||||
* @constructor
|
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.Cylinder.FromObject = function(graphics, objectMesh) {
|
GameLib.D3.Mesh.Cylinder.prototype.turnIntoDisplay = function() {
|
||||||
|
|
||||||
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);
|
this.heightSegments = 1;
|
||||||
|
this.updateInstance('heightSegments');
|
||||||
|
|
||||||
return new GameLib.D3.Mesh.Cylinder(
|
this.openEnded = true;
|
||||||
graphics,
|
this.updateInstance('openEnded');
|
||||||
apiMesh,
|
|
||||||
objectMesh.radiusTop,
|
this.materials.map(
|
||||||
objectMesh.radiusBottom,
|
function(material){
|
||||||
objectMesh.height,
|
material.remove();
|
||||||
objectMesh.radiusSegments,
|
}
|
||||||
objectMesh.heightSegments,
|
|
||||||
objectMesh.openEnded,
|
|
||||||
objectMesh.thetaStart,
|
|
||||||
objectMesh.thetaLength
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.materials = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < this.radiusSegments; i++) {
|
||||||
|
this.materials.push(
|
||||||
|
new GameLib.D3.Material(this.graphics)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateInstance('materials');
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue