switch to quaternion rotation
parent
b6ac86ce7e
commit
212baebd78
|
@ -99,7 +99,7 @@ GameLib.D3.API.Mesh = function(
|
||||||
this.skinWeights = skinWeights;
|
this.skinWeights = skinWeights;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
||||||
materials = [new GameLib.D3.API.Material(null, GameLib.D3.Material.MATERIAL_TYPE_BASIC)];
|
materials = [new GameLib.D3.API.Material(null, GameLib.D3.Material.MATERIAL_TYPE_STANDARD, 'Material Mesh (' + this.id + ')')];
|
||||||
}
|
}
|
||||||
this.materials = materials;
|
this.materials = materials;
|
||||||
|
|
||||||
|
|
|
@ -453,6 +453,14 @@ GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) {
|
||||||
geometry.computeFaceNormals();
|
geometry.computeFaceNormals();
|
||||||
// geometry.computeBoundingBox();
|
// geometry.computeBoundingBox();
|
||||||
geometry.computeVertexNormals();
|
geometry.computeVertexNormals();
|
||||||
|
|
||||||
|
// geometry.verticesNeedUpdate = true;
|
||||||
|
// geometry.elementsNeedUpdate = true;
|
||||||
|
// geometry.morphTargetsNeedUpdate = true;
|
||||||
|
// geometry.uvsNeedUpdate = true;
|
||||||
|
// geometry.normalsNeedUpdate = true;
|
||||||
|
// geometry.colorsNeedUpdate = true;
|
||||||
|
// geometry.tangentsNeedUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -477,29 +485,49 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
|
||||||
var instanceMaterials = function(result, material){
|
var instanceMaterials = function(result, material){
|
||||||
result.push(material.instance);
|
material.instance.needsUpdate = true;
|
||||||
|
result.push(material.instance);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.skeleton) {
|
if (this.skeleton) {
|
||||||
instance = new THREE.SkinnedMesh(
|
|
||||||
geometry,
|
if (this.materials.length === 1) {
|
||||||
this.materials.reduce(
|
instance = new THREE.SkinnedMesh(
|
||||||
instanceMaterials,
|
geometry,
|
||||||
[]
|
this.materials[0].instance
|
||||||
)
|
)
|
||||||
);
|
} else {
|
||||||
|
instance = new THREE.SkinnedMesh(
|
||||||
|
geometry,
|
||||||
|
this.materials.map(
|
||||||
|
function(material) {
|
||||||
|
return material.instance;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
instance.add(this.skeleton.rootBoneInstance);
|
instance.add(this.skeleton.rootBoneInstance);
|
||||||
instance.bind(this.skeleton.instance);
|
instance.bind(this.skeleton.instance);
|
||||||
} else {
|
} else {
|
||||||
instance = new THREE.Mesh(
|
if (this.materials.length === 1) {
|
||||||
geometry,
|
instance = new THREE.Mesh(
|
||||||
this.materials.reduce(
|
geometry,
|
||||||
instanceMaterials,
|
this.materials[0].instance
|
||||||
[]
|
)
|
||||||
)
|
} else {
|
||||||
);
|
instance = new THREE.Mesh(
|
||||||
|
geometry,
|
||||||
|
this.materials.map(
|
||||||
|
function(material) {
|
||||||
|
return material.instance;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createInstanceDefaults(instance);
|
this.createInstanceDefaults(instance);
|
||||||
|
@ -523,7 +551,16 @@ GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
this.instance.geometry = this.createInstanceGeometry(this.instance.geometry);
|
this.instance.geometry = this.createInstanceGeometry(this.instance.geometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.parentMesh && this.parentMesh.loaded) {
|
this.quaternion.axis.instance.x = this.quaternion.axis.x;
|
||||||
|
this.quaternion.axis.instance.y = this.quaternion.axis.y;
|
||||||
|
this.quaternion.axis.instance.z = this.quaternion.axis.z;
|
||||||
|
//
|
||||||
|
// var v = new THREE.Vector3();
|
||||||
|
// v.applyAxisAngle(this.quaternion.axis.instance, this.quaternion.angle);
|
||||||
|
|
||||||
|
this.quaternion.instance.setFromAxisAngle(this.quaternion.axis.instance, this.quaternion.angle);
|
||||||
|
|
||||||
|
if (this.parentMesh && this.parentMesh.loaded) {
|
||||||
|
|
||||||
if (this.instance.parent !== this.parentMesh.instance) {
|
if (this.instance.parent !== this.parentMesh.instance) {
|
||||||
this.instance.parent = this.parentMesh.instance;
|
this.instance.parent = this.parentMesh.instance;
|
||||||
|
@ -533,9 +570,13 @@ GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
this.instance.position.y = this.localPosition.y;
|
this.instance.position.y = this.localPosition.y;
|
||||||
this.instance.position.z = this.localPosition.z;
|
this.instance.position.z = this.localPosition.z;
|
||||||
|
|
||||||
this.instance.rotation.x = this.localRotation.x;
|
// this.localRotation.x = this.localRotation.instance.x;
|
||||||
this.instance.rotation.y = this.localRotation.y;
|
// this.localRotation.y = this.localRotation.instance.y;
|
||||||
this.instance.rotation.z = this.localRotation.z;
|
// this.localRotation.z = this.localRotation.instance.z;
|
||||||
|
|
||||||
|
// this.instance.rotation.x = this.localRotation.x;
|
||||||
|
// this.instance.rotation.y = this.localRotation.y;
|
||||||
|
// this.instance.rotation.z = this.localRotation.z;
|
||||||
|
|
||||||
this.instance.scale.x = this.localScale.x;
|
this.instance.scale.x = this.localScale.x;
|
||||||
this.instance.scale.y = this.localScale.y;
|
this.instance.scale.y = this.localScale.y;
|
||||||
|
@ -543,10 +584,10 @@ GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.instance.quaternion.x = this.quaternion.x;
|
// this.localRotation.instance.applyAxisAngle(this.quaternion.axis.instance, this.quaternion.angle);
|
||||||
this.instance.quaternion.y = this.quaternion.y;
|
// this.localRotation.x = this.localRotation.instance.x;
|
||||||
this.instance.quaternion.z = this.quaternion.z;
|
// this.localRotation.y = this.localRotation.instance.y;
|
||||||
this.instance.quaternion.w = this.quaternion.w;
|
// this.localRotation.z = this.localRotation.instance.z;
|
||||||
|
|
||||||
this.instance.position.x = this.position.x + this.localPosition.x;
|
this.instance.position.x = this.position.x + this.localPosition.x;
|
||||||
this.instance.position.y = this.position.y + this.localPosition.y;
|
this.instance.position.y = this.position.y + this.localPosition.y;
|
||||||
|
@ -556,16 +597,19 @@ GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
this.instance.scale.y = this.scale.y * this.localScale.y;
|
this.instance.scale.y = this.scale.y * this.localScale.y;
|
||||||
this.instance.scale.z = this.scale.z * this.localScale.z;
|
this.instance.scale.z = this.scale.z * this.localScale.z;
|
||||||
|
|
||||||
this.instance.up.x = this.up.x;
|
|
||||||
this.instance.up.y = this.up.y;
|
|
||||||
this.instance.up.z = this.up.z;
|
|
||||||
|
|
||||||
this.instance.rotateX(this.localRotation.x);
|
// this.instance.rotateX(this.localRotation.x);
|
||||||
this.instance.rotateY(this.localRotation.y);
|
// this.instance.rotateY(this.localRotation.y);
|
||||||
this.instance.rotateZ(this.localRotation.z);
|
// this.instance.rotateZ(this.localRotation.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance.name = this.name;
|
this.instance.quaternion.copy(this.quaternion.instance);
|
||||||
|
|
||||||
|
this.instance.up.x = this.up.x;
|
||||||
|
this.instance.up.y = this.up.y;
|
||||||
|
this.instance.up.z = this.up.z;
|
||||||
|
|
||||||
|
this.instance.name = this.name;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -579,7 +623,7 @@ GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
// this.helper.updateInstance();
|
// this.helper.updateInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.computeBoundingBox(this.instance.geometry);
|
// this.computeBoundingBox(this.instance.geometry);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -82,18 +82,7 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
|
||||||
|
|
||||||
this.updateVerticesFromGeometryInstance(geometry);
|
this.updateVerticesFromGeometryInstance(geometry);
|
||||||
|
|
||||||
this.materials.push(
|
/**
|
||||||
new GameLib.D3.Material(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.D3.API.Material(
|
|
||||||
null,
|
|
||||||
GameLib.D3.Material.MATERIAL_TYPE_STANDARD,
|
|
||||||
'Material Plane ' + this.id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If this is a heightmap - first generate the z-coordinates
|
* If this is a heightmap - first generate the z-coordinates
|
||||||
*/
|
*/
|
||||||
if (this.isHeightMap) {
|
if (this.isHeightMap) {
|
||||||
|
|
|
@ -133,16 +133,16 @@ GameLib.D3.RigidBody.prototype.updateInstance = function() {
|
||||||
this.instance.position.y = this.position.y;
|
this.instance.position.y = this.position.y;
|
||||||
this.instance.position.z = this.position.z;
|
this.instance.position.z = this.position.z;
|
||||||
|
|
||||||
this.instance.quaternion.x = this.quaternion.x;
|
this.instance.quaternion.setFromAxisAngle(new CANNON.Vec3(this.quaternion.axis.x, this.quaternion.axis.y, this.quaternion.axis.z), this.quaternion.angle);
|
||||||
this.instance.quaternion.y = this.quaternion.y;
|
|
||||||
this.instance.quaternion.z = this.quaternion.z;
|
|
||||||
this.instance.quaternion.w = this.quaternion.w;
|
|
||||||
|
|
||||||
this.instance.velocity.x = this.velocity.x;
|
this.instance.velocity.x = this.velocity.x;
|
||||||
this.instance.velocity.y = this.velocity.y;
|
this.instance.velocity.y = this.velocity.y;
|
||||||
this.instance.velocity.z = this.velocity.z;
|
this.instance.velocity.z = this.velocity.z;
|
||||||
|
|
||||||
this.instance.angularVelocity = this.angularVelocity;
|
this.instance.angularVelocity.x = this.angularVelocity.x;
|
||||||
|
this.instance.angularVelocity.y = this.angularVelocity.y;
|
||||||
|
this.instance.angularVelocity.z = this.angularVelocity.z;
|
||||||
|
|
||||||
this.instance.linearDamping = this.linearDamping;
|
this.instance.linearDamping = this.linearDamping;
|
||||||
this.instance.angularDamping = this.angularDamping;
|
this.instance.angularDamping = this.angularDamping;
|
||||||
this.instance.allowSleep = this.allowSleep;
|
this.instance.allowSleep = this.allowSleep;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* @param physics
|
* @param physics
|
||||||
* @param apiShape
|
* @param apiShape
|
||||||
* @param zValues
|
* @param heightData
|
||||||
* @param minValue
|
* @param minValue
|
||||||
* @param maxValue
|
* @param maxValue
|
||||||
* @param elementSize
|
* @param elementSize
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
GameLib.D3.Shape.HeightMap = function (
|
GameLib.D3.Shape.HeightMap = function (
|
||||||
physics,
|
physics,
|
||||||
apiShape,
|
apiShape,
|
||||||
zValues,
|
heightData,
|
||||||
minValue,
|
minValue,
|
||||||
maxValue,
|
maxValue,
|
||||||
elementSize
|
elementSize
|
||||||
|
@ -19,10 +19,10 @@ GameLib.D3.Shape.HeightMap = function (
|
||||||
this.physics = physics;
|
this.physics = physics;
|
||||||
this.physics.isNotCannonThrow();
|
this.physics.isNotCannonThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(zValues)) {
|
if (GameLib.Utils.UndefinedOrNull(heightData)) {
|
||||||
zValues = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10];
|
heightData = [[10, 10, 10], [10, 10, 10], [10, 10, 10]];
|
||||||
}
|
}
|
||||||
this.zValues = zValues;
|
this.heightData = heightData;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(minValue)) {
|
if (GameLib.Utils.UndefinedOrNull(minValue)) {
|
||||||
minValue = 0;
|
minValue = 0;
|
||||||
|
@ -56,10 +56,8 @@ GameLib.D3.Shape.HeightMap.prototype.constructor = GameLib.D3.Shape.HeightMap;
|
||||||
GameLib.D3.Shape.HeightMap.prototype.createInstance = function() {
|
GameLib.D3.Shape.HeightMap.prototype.createInstance = function() {
|
||||||
|
|
||||||
var instance = new CANNON.Heightfield(
|
var instance = new CANNON.Heightfield(
|
||||||
this.zValues,
|
this.heightData,
|
||||||
{
|
{
|
||||||
minValue : this.minValue,
|
|
||||||
maxValue : this.maxValue,
|
|
||||||
elemSize : this.elementSize
|
elemSize : this.elementSize
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -71,9 +69,9 @@ GameLib.D3.Shape.HeightMap.prototype.createInstance = function() {
|
||||||
* Update instance
|
* Update instance
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Shape.HeightMap.prototype.updateInstance = function() {
|
GameLib.D3.Shape.HeightMap.prototype.updateInstance = function() {
|
||||||
this.instance.data = this.zValues;
|
this.instance.data = this.heightData;
|
||||||
this.instance.minValue = this.minValue;
|
// this.instance.minValue = this.minValue;
|
||||||
this.instance.maxValue = this.maxValue;
|
// this.instance.maxValue = this.maxValue;
|
||||||
this.instance.elemSize = this.elemSize;
|
this.instance.elemSize = this.elemSize;
|
||||||
this.instance.update();
|
this.instance.update();
|
||||||
// this.instance.updateBoundingSphereRadius();
|
// this.instance.updateBoundingSphereRadius();
|
||||||
|
@ -84,7 +82,7 @@ GameLib.D3.Shape.HeightMap.prototype.updateInstance = function() {
|
||||||
|
|
||||||
GameLib.D3.Shape.HeightMap.prototype.toApiObject = function() {
|
GameLib.D3.Shape.HeightMap.prototype.toApiObject = function() {
|
||||||
var apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this);
|
var apiShape = GameLib.D3.Shape.prototype.toApiObject.call(this);
|
||||||
apiShape.zValues = this.zValues;
|
apiShape.heightData = this.heightData;
|
||||||
apiShape.minValue = this.minValue;
|
apiShape.minValue = this.minValue;
|
||||||
apiShape.maxValue = this.maxValue;
|
apiShape.maxValue = this.maxValue;
|
||||||
apiShape.elemSize = this.elemSize;
|
apiShape.elemSize = this.elemSize;
|
||||||
|
@ -105,36 +103,47 @@ GameLib.D3.Shape.HeightMap.prototype.setFromMesh = function() {
|
||||||
|
|
||||||
var dim1Array = Array.prototype.slice.call(this.parentMesh.getHeightData());
|
var dim1Array = Array.prototype.slice.call(this.parentMesh.getHeightData());
|
||||||
|
|
||||||
var w = 0;
|
// var w = this.parentMesh.widthSegments + 1;
|
||||||
|
//
|
||||||
|
// var h = 0;
|
||||||
|
|
||||||
var h = 0;
|
// var offset = 0;
|
||||||
|
|
||||||
var width = this.parentMesh.widthSegments + 1;
|
this.heightData = [];
|
||||||
|
|
||||||
var height = this.parentMesh.heightSegments + 1;
|
for (var x = 0; x <= this.parentMesh.widthSegments; x++) {
|
||||||
|
|
||||||
var dim2Array = dim1Array.reduce(
|
this.heightData[x] = [];
|
||||||
function(result, value) {
|
|
||||||
|
|
||||||
result[h].push(value);
|
for (var y = 0; y <= this.parentMesh.heightSegments; y++) {
|
||||||
|
|
||||||
w++;
|
this.heightData[x][y] = dim1Array[((x * (this.parentMesh.widthSegments + 1)) + y)];
|
||||||
|
|
||||||
if (w === this.parentMesh.widthSegments) {
|
}
|
||||||
w = 0;
|
|
||||||
h++;
|
|
||||||
result[h] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
}
|
||||||
}.bind(this),
|
|
||||||
[[]]
|
|
||||||
);
|
|
||||||
|
|
||||||
this.zValues = dim2Array;
|
|
||||||
|
|
||||||
this.minValue = 0;
|
|
||||||
this.maxValue = (this.parentMesh.widthSegments + 1) * (this.parentMesh.heightSegments + 1);
|
// this.heightData = dim1Array.reduce(
|
||||||
|
// function(result, value) {
|
||||||
|
//
|
||||||
|
// result[h].push(value);
|
||||||
|
//
|
||||||
|
// w--;
|
||||||
|
//
|
||||||
|
// if (w === 0) {
|
||||||
|
// w = this.parentMesh.widthSegments;
|
||||||
|
//
|
||||||
|
// if (h < this.parentMesh.heightSegments) {
|
||||||
|
// h++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
// }.bind(this),
|
||||||
|
// result
|
||||||
|
// );
|
||||||
|
|
||||||
this.updateInstance();
|
this.updateInstance();
|
||||||
};
|
};
|
||||||
|
@ -146,7 +155,7 @@ GameLib.D3.Shape.HeightMap.FromObject = function(physics, objectShape) {
|
||||||
return new GameLib.D3.Shape.HeightMap(
|
return new GameLib.D3.Shape.HeightMap(
|
||||||
physics,
|
physics,
|
||||||
apiShape,
|
apiShape,
|
||||||
objectShape.zValues,
|
objectShape.heightData,
|
||||||
objectShape.minValue,
|
objectShape.minValue,
|
||||||
objectShape.maxValue,
|
objectShape.maxValue,
|
||||||
objectShape.elemSize
|
objectShape.elemSize
|
||||||
|
|
|
@ -262,13 +262,51 @@ GameLib.System.GUI.prototype.buildQuaternionControl = function(folder, component
|
||||||
this.controller(folder, object, property, 'w', step, listen, affected);
|
this.controller(folder, object, property, 'w', step, listen, affected);
|
||||||
this.controller(folder, object, property, 'angle', step, listen, affected);
|
this.controller(folder, object, property, 'angle', step, listen, affected);
|
||||||
|
|
||||||
|
folder.add(
|
||||||
|
object[property]['axis'],
|
||||||
|
'x',
|
||||||
|
-1,
|
||||||
|
1,
|
||||||
|
0.01
|
||||||
|
).onChange(
|
||||||
|
function(value) {
|
||||||
|
affected.map(function(component){
|
||||||
|
component[property]['axis'].x = Number(value);
|
||||||
|
component.updateInstance();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
object = object[property];
|
folder.add(
|
||||||
property = 'axis';
|
object[property]['axis'],
|
||||||
|
'y',
|
||||||
|
-1,
|
||||||
|
1,
|
||||||
|
0.01
|
||||||
|
).onChange(
|
||||||
|
function(value) {
|
||||||
|
affected.map(function(component){
|
||||||
|
component[property]['axis'].y = Number(value);
|
||||||
|
component.updateInstance();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
folder.add(
|
||||||
|
object[property]['axis'],
|
||||||
|
'z',
|
||||||
|
-1,
|
||||||
|
1,
|
||||||
|
0.01
|
||||||
|
).onChange(
|
||||||
|
function(value) {
|
||||||
|
affected.map(function(component){
|
||||||
|
component[property]['axis'].z = Number(value);
|
||||||
|
component.updateInstance();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.controller(folder, object, property, 'x', step, listen, affected);
|
|
||||||
this.controller(folder, object, property, 'y', step, listen, affected);
|
|
||||||
this.controller(folder, object, property, 'z', step, listen, affected);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemplate, property) {
|
GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemplate, property) {
|
||||||
|
@ -321,11 +359,21 @@ GameLib.System.GUI.prototype.buildVectorControl = function(folder, componentTemp
|
||||||
* @param folder
|
* @param folder
|
||||||
* @param componentTemplate
|
* @param componentTemplate
|
||||||
*/
|
*/
|
||||||
GameLib.System.GUI.prototype.buildEntitySelectionControl = function(folder, componentTemplate) {
|
GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, componentTemplate, property) {
|
||||||
|
|
||||||
var options = GameLib.EntityManager.Instance.queryComponents(GameLib.Entity).reduce(
|
var constructor = null;
|
||||||
function(result, entity) {
|
|
||||||
result[entity.name] = entity;
|
if (property === 'parentEntity') {
|
||||||
|
constructor = GameLib.Entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'parentMesh') {
|
||||||
|
constructor = GameLib.D3.Mesh
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = GameLib.EntityManager.Instance.queryComponents(constructor).reduce(
|
||||||
|
function(result, object) {
|
||||||
|
result[object.name] = object;
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -337,47 +385,44 @@ GameLib.System.GUI.prototype.buildEntitySelectionControl = function(folder, comp
|
||||||
|
|
||||||
var affected = componentTemplate.affected;
|
var affected = componentTemplate.affected;
|
||||||
|
|
||||||
folder.add(object, 'parentEntity', options).listen().onChange(
|
folder.add(object, property, options).listen().onChange(
|
||||||
|
|
||||||
function(value) {
|
function(value) {
|
||||||
|
|
||||||
var newEntity = null;
|
var newComponent = null;
|
||||||
|
|
||||||
if (value !== 'null') {
|
if (value !== 'null') {
|
||||||
newEntity = GameLib.EntityManager.Instance.findEntityById(value);
|
newComponent = GameLib.EntityManager.Instance.findComponentById(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
affected.map(
|
affected.map(
|
||||||
function(component) {
|
function(component) {
|
||||||
|
|
||||||
component.parentEntity = newEntity;
|
component[property] = newComponent;
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
if (property === 'parentEntity') {
|
||||||
GameLib.Event.PARENT_ENTITY_CHANGE,
|
GameLib.Event.Emit(
|
||||||
{
|
GameLib.Event.PARENT_ENTITY_CHANGE,
|
||||||
originalEntity : this.initialValue,
|
{
|
||||||
newEntity : newEntity,
|
originalEntity : this.initialValue,
|
||||||
object : component
|
newEntity : newComponent,
|
||||||
}
|
object : component
|
||||||
);
|
}
|
||||||
}.bind(this)
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.BUILD_GUI,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
this.initialValue = newEntity;
|
}.bind(this)
|
||||||
}
|
);
|
||||||
).onFinishChange(
|
|
||||||
function(){
|
if (property === 'parentEntity') {
|
||||||
// GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
// GameLib.Event.BUILD_GUI,
|
GameLib.Event.BUILD_GUI,
|
||||||
// {
|
null
|
||||||
//
|
);
|
||||||
// }
|
}
|
||||||
// )
|
|
||||||
|
this.initialValue = newComponent;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -981,7 +1026,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, -255, 255, 1));
|
controllers.push(folder.add(object, property, -255, 255, 1));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'aspect'
|
property === 'aspect' ||
|
||||||
|
property === 'wireframeLineWidth'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, 0, 5, 0.001));
|
controllers.push(folder.add(object, property, 0, 5, 0.001));
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -996,12 +1042,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, 1, 1000, 1));
|
controllers.push(folder.add(object, property, 1, 1000, 1));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'angle' ||
|
|
||||||
property === 'width' ||
|
property === 'width' ||
|
||||||
property === 'height' ||
|
property === 'height' ||
|
||||||
property === 'depth'
|
property === 'depth' ||
|
||||||
|
property === 'radius'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, -1000, 1000, 1));
|
controllers.push(folder.add(object, property, -1000, 1000, 0.1));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'near' ||
|
property === 'near' ||
|
||||||
property === 'distanceGrain' ||
|
property === 'distanceGrain' ||
|
||||||
|
@ -1015,11 +1061,12 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, -100, 100, 0.001));
|
controllers.push(folder.add(object, property, -100, 100, 0.001));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'radius'
|
property === 'rrradius'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, 0, 1000, 0.01));
|
controllers.push(folder.add(object, property, 0, 1000, 0.01));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'thetaLength'
|
property === 'thetaLength' ||
|
||||||
|
property === 'angle'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, -Math.PI * 2, Math.PI * 2, 0.01));
|
controllers.push(folder.add(object, property, -Math.PI * 2, Math.PI * 2, 0.01));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1467,8 +1514,11 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
|
||||||
this.buildQuaternionControl(folder, componentTemplate, templateProperty);
|
this.buildQuaternionControl(folder, componentTemplate, templateProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (templateProperty === 'parentEntity') {
|
if (
|
||||||
this.buildEntitySelectionControl(folder, componentTemplate);
|
templateProperty === 'parentEntity' ||
|
||||||
|
templateProperty === 'parentMesh'
|
||||||
|
) {
|
||||||
|
this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -685,12 +685,18 @@ GameLib.System.Linking.prototype.materialTypeChanged = function(data) {
|
||||||
|
|
||||||
if (inUse) {
|
if (inUse) {
|
||||||
|
|
||||||
mesh.instance.material = mesh.materials.map(function(material){
|
if (mesh.materials.length === 1) {
|
||||||
return material.instance;
|
mesh.instance.material = mesh.materials[0].instance
|
||||||
});
|
} else {
|
||||||
|
mesh.instance.material = mesh.materials.map(
|
||||||
|
function(material) {
|
||||||
|
return material.instance;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
mesh.instance.geometry.uvsNeedUpdate = true;
|
mesh.instance.geometry.uvsNeedUpdate = true;
|
||||||
|
mesh.instance.material.needsUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,38 +48,61 @@ GameLib.System.Visualization.prototype.start = function() {
|
||||||
|
|
||||||
GameLib.System.Visualization.prototype.visualize = function(data) {
|
GameLib.System.Visualization.prototype.visualize = function(data) {
|
||||||
|
|
||||||
var shape = this.instance;
|
var shape = data.shape;
|
||||||
|
|
||||||
var geometry = new THREE.Geometry();
|
var parentMesh = shape.parentMesh;
|
||||||
|
|
||||||
var v0 = new CANNON.Vec3();
|
shape.setFromMesh();
|
||||||
var v1 = new CANNON.Vec3();
|
|
||||||
var v2 = new CANNON.Vec3();
|
var apiMesh = new GameLib.D3.API.Mesh();
|
||||||
for (var xi = 0; xi < shape.data.length - 1; xi++) {
|
|
||||||
for (var yi = 0; yi < shape.data[xi].length - 1; yi++) {
|
apiMesh.name = 'Visualization Mesh for Shape ' + shape.name;
|
||||||
for (var k = 0; k < 2; k++) {
|
|
||||||
shape.getConvexTrianglePillar(xi, yi, k===0);
|
if (shape instanceof GameLib.D3.Shape.HeightMap) {
|
||||||
v0.copy(shape.pillarConvex.vertices[0]);
|
var v0 = new CANNON.Vec3();
|
||||||
v1.copy(shape.pillarConvex.vertices[1]);
|
var v1 = new CANNON.Vec3();
|
||||||
v2.copy(shape.pillarConvex.vertices[2]);
|
var v2 = new CANNON.Vec3();
|
||||||
v0.vadd(shape.pillarOffset, v0);
|
for (var xi = 0; xi < shape.heightData.length - 1; xi++) {
|
||||||
v1.vadd(shape.pillarOffset, v1);
|
for (var yi = 0; yi < shape.heightData[xi].length - 1; yi++) {
|
||||||
v2.vadd(shape.pillarOffset, v2);
|
for (var k = 0; k < 2; k++) {
|
||||||
geometry.vertices.push(
|
shape.instance.getConvexTrianglePillar(xi, yi, k===0);
|
||||||
new THREE.Vector3(v0.x, v0.y, v0.z),
|
v0.copy(shape.instance.pillarConvex.vertices[0]);
|
||||||
new THREE.Vector3(v1.x, v1.y, v1.z),
|
v1.copy(shape.instance.pillarConvex.vertices[1]);
|
||||||
new THREE.Vector3(v2.x, v2.y, v2.z)
|
v2.copy(shape.instance.pillarConvex.vertices[2]);
|
||||||
);
|
v0.vadd(shape.instance.pillarOffset, v0);
|
||||||
var i = geometry.vertices.length - 3;
|
v1.vadd(shape.instance.pillarOffset, v1);
|
||||||
geometry.faces.push(new THREE.Face3(i, i+1, i+2));
|
v2.vadd(shape.instance.pillarOffset, v2);
|
||||||
|
apiMesh.vertices.push(
|
||||||
|
new GameLib.D3.API.Vertex(
|
||||||
|
new GameLib.API.Vector3(v0.x, v0.y, v0.z)
|
||||||
|
),
|
||||||
|
new GameLib.D3.API.Vertex(
|
||||||
|
new GameLib.API.Vector3(v1.x, v1.y, v1.z)
|
||||||
|
),
|
||||||
|
new GameLib.D3.API.Vertex(
|
||||||
|
new GameLib.API.Vector3(v2.x, v2.y, v2.z)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
var i = apiMesh.vertices.length - 3;
|
||||||
|
apiMesh.faces.push(
|
||||||
|
new GameLib.D3.API.Face(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
i,
|
||||||
|
i+1,
|
||||||
|
i+2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
geometry.computeBoundingSphere();
|
|
||||||
geometry.computeFaceNormals();
|
|
||||||
mesh = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial());
|
|
||||||
|
|
||||||
this.mesh = mesh;
|
new GameLib.D3.Mesh(
|
||||||
|
this.graphics,
|
||||||
|
apiMesh
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Visualization.prototype.stopVisualize = function(data) {
|
GameLib.System.Visualization.prototype.stopVisualize = function(data) {
|
||||||
|
|
Loading…
Reference in New Issue