face select mode - cylinder updates
parent
b3d9556461
commit
e22904841a
|
@ -154,7 +154,7 @@ GameLib.D3.API.Material = function(
|
|||
this.materialType = materialType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Material (' + materialType + ')';
|
||||
name = 'Material (' + this.id + ')';
|
||||
}
|
||||
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,
|
||||
b: this.color.b
|
||||
},
|
||||
|
||||
material : {
|
||||
emissive : {
|
||||
r: mesh.materials[this.materialIndex].emissive.r,
|
||||
|
@ -234,20 +235,27 @@ GameLib.D3.Face.prototype.createHelper = function(mesh) {
|
|||
vertexColors : mesh.materials[this.materialIndex].vertexColors
|
||||
};
|
||||
|
||||
this.instance.color.r = 1;
|
||||
this.instance.color.g = 0;
|
||||
this.instance.color.b = 0;
|
||||
this.instance.vertexColors = [
|
||||
new THREE.Color(1,0,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.g = 0.5;
|
||||
// mesh.materials[this.materialIndex].emissive.b = 0.5;
|
||||
// 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.instance.geometry.elementsNeedUpdate = true;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Face.prototype.removeHelper = function(mesh) {
|
||||
|
|
|
@ -584,6 +584,18 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
|||
if (property === 'materials') {
|
||||
if (this.materials.length === 1 && 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
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiMesh GameLib.D3.API.Mesh
|
||||
* @param radiusTop
|
||||
* @param radiusBottom
|
||||
* @param height
|
||||
* @param radiusSegments
|
||||
* @param heightSegments
|
||||
* @param openEnded
|
||||
* @param thetaStart
|
||||
* @param thetaLength
|
||||
* @param apiMeshCylinder
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Mesh.Cylinder = function (
|
||||
graphics,
|
||||
apiMesh,
|
||||
radiusTop,
|
||||
radiusBottom,
|
||||
height,
|
||||
radiusSegments,
|
||||
heightSegments,
|
||||
openEnded,
|
||||
thetaStart,
|
||||
thetaLength
|
||||
apiMeshCylinder
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType: GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER
|
||||
if (GameLib.Utils.UndefinedOrNull(apiMeshCylinder)) {
|
||||
apiMeshCylinder = {
|
||||
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.Cylinder.call(
|
||||
this,
|
||||
apiMeshCylinder,
|
||||
apiMeshCylinder.radiusTop,
|
||||
apiMeshCylinder.radiusBottom,
|
||||
apiMeshCylinder.height,
|
||||
apiMeshCylinder.radiusSegments,
|
||||
apiMeshCylinder.heightSegments,
|
||||
apiMeshCylinder.openEnded,
|
||||
apiMeshCylinder.thetaStart,
|
||||
apiMeshCylinder.thetaLength
|
||||
);
|
||||
|
||||
GameLib.D3.Mesh.call(
|
||||
this,
|
||||
this.graphics,
|
||||
apiMesh
|
||||
graphics,
|
||||
apiMeshCylinder
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -103,38 +59,20 @@ GameLib.D3.Mesh.Cylinder.prototype.createInstance = function() {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
||||
if (
|
||||
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
|
||||
property === 'radiusTop' ||
|
||||
property === 'radiusBottom' ||
|
||||
property === 'height' ||
|
||||
property === 'radiusSegments' ||
|
||||
property === 'heightSegments' ||
|
||||
property === 'openEnded' ||
|
||||
property === 'thetaStart' ||
|
||||
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(
|
||||
this.radiusTop,
|
||||
this.radiusBottom,
|
||||
|
@ -153,7 +91,6 @@ GameLib.D3.Mesh.Cylinder.prototype.updateInstance = function(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
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param objectMesh {Object}
|
||||
* @constructor
|
||||
* This function turns the cylinder into a 'display' where each plane on the cylinder is mapped onto a flat texture
|
||||
*/
|
||||
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(
|
||||
graphics,
|
||||
apiMesh,
|
||||
objectMesh.radiusTop,
|
||||
objectMesh.radiusBottom,
|
||||
objectMesh.height,
|
||||
objectMesh.radiusSegments,
|
||||
objectMesh.heightSegments,
|
||||
objectMesh.openEnded,
|
||||
objectMesh.thetaStart,
|
||||
objectMesh.thetaLength
|
||||
this.openEnded = true;
|
||||
this.updateInstance('openEnded');
|
||||
|
||||
this.materials.map(
|
||||
function(material){
|
||||
material.remove();
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
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