move to faster buffergeometries - blender upload working again - gui starts to support multiple selections again
parent
597191bf58
commit
def400d385
|
@ -15,7 +15,7 @@
|
||||||
"lodash": "^4.17.2",
|
"lodash": "^4.17.2",
|
||||||
"npm": "^4.0.2",
|
"npm": "^4.0.2",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"three": "^0.84.0",
|
"three": "*",
|
||||||
"through2": "^2.0.1"
|
"through2": "^2.0.1"
|
||||||
},
|
},
|
||||||
"repository": "https://github.com/ToywheelDev/game-lib.git",
|
"repository": "https://github.com/ToywheelDev/game-lib.git",
|
||||||
|
|
|
@ -38,6 +38,7 @@ GameLib.Component = function(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.dependencies.length === 0) {
|
if (this.dependencies.length === 0) {
|
||||||
|
|
||||||
delete this.dependencies;
|
delete this.dependencies;
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
|
@ -19,6 +19,10 @@ GameLib.API.Vector2.prototype.copy = function () {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.API.Vector2.prototype.equals = function (v) {
|
||||||
|
return this.x === v.x && this.y === v.y;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an API vector from an Object vector
|
* Returns an API vector from an Object vector
|
||||||
* @param objectVector
|
* @param objectVector
|
||||||
|
|
|
@ -40,6 +40,10 @@ GameLib.API.Vector3.prototype.sub = function (v) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.API.Vector3.prototype.equals = function (v) {
|
||||||
|
return this.x === v.x && this.y === v.y && this.z === v.z;
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.API.Vector3.prototype.cross = function (v) {
|
GameLib.API.Vector3.prototype.cross = function (v) {
|
||||||
return new GameLib.API.Vector3(
|
return new GameLib.API.Vector3(
|
||||||
this.y * v.z - this.z * v.y,
|
this.y * v.z - this.z * v.y,
|
||||||
|
|
|
@ -21,6 +21,10 @@ GameLib.API.Vector4 = function (x, y, z, w) {
|
||||||
this.w = w;
|
this.w = w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.API.Vector4.prototype.equals = function (v) {
|
||||||
|
return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an API vector from an Object vector
|
* Returns an API vector from an Object vector
|
||||||
* @param objectVector
|
* @param objectVector
|
||||||
|
|
|
@ -49,7 +49,24 @@ GameLib.D3.API.Light = function(
|
||||||
this.lightType = lightType;
|
this.lightType = lightType;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = 'Light (' + id + ')';
|
|
||||||
|
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
||||||
|
name = 'Ambient ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||||
|
name = 'Directional ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||||||
|
name = 'Point ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.lightType === GameLib.D3.Light.LIGHT_TYPE_SPOT) {
|
||||||
|
name = 'Spot ';
|
||||||
|
}
|
||||||
|
|
||||||
|
name += 'Light (' + id + ')';
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
* @param clipShadows
|
* @param clipShadows
|
||||||
* @param visible
|
* @param visible
|
||||||
* @param overdraw
|
* @param overdraw
|
||||||
* @param shading
|
* @param flatShading
|
||||||
* @param bumpScale
|
* @param bumpScale
|
||||||
* @param normalScale
|
* @param normalScale
|
||||||
* @param displacementScale
|
* @param displacementScale
|
||||||
|
@ -117,7 +117,7 @@ GameLib.D3.API.Material = function(
|
||||||
clipShadows,
|
clipShadows,
|
||||||
visible,
|
visible,
|
||||||
overdraw,
|
overdraw,
|
||||||
shading,
|
flatShading,
|
||||||
bumpScale,
|
bumpScale,
|
||||||
normalScale,
|
normalScale,
|
||||||
displacementScale,
|
displacementScale,
|
||||||
|
@ -368,10 +368,10 @@ GameLib.D3.API.Material = function(
|
||||||
}
|
}
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(shading)) {
|
if (GameLib.Utils.UndefinedOrNull(flatShading)) {
|
||||||
shading = GameLib.D3.Material.TYPE_FLAT_SHADING;
|
flatShading = false;
|
||||||
}
|
}
|
||||||
this.shading = shading;
|
this.flatShading = flatShading;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(bumpScale)) {
|
if (GameLib.Utils.UndefinedOrNull(bumpScale)) {
|
||||||
bumpScale = 1;
|
bumpScale = 1;
|
||||||
|
@ -608,7 +608,7 @@ GameLib.D3.API.Material.FromObject = function(objectMaterial) {
|
||||||
objectMaterial.clipShadows,
|
objectMaterial.clipShadows,
|
||||||
objectMaterial.visible,
|
objectMaterial.visible,
|
||||||
objectMaterial.overdraw,
|
objectMaterial.overdraw,
|
||||||
objectMaterial.shading,
|
objectMaterial.flatShading,
|
||||||
objectMaterial.bumpScale,
|
objectMaterial.bumpScale,
|
||||||
objectMaterial.normalScale,
|
objectMaterial.normalScale,
|
||||||
objectMaterial.displacementScale,
|
objectMaterial.displacementScale,
|
||||||
|
|
|
@ -100,7 +100,8 @@ GameLib.D3.Helper.prototype.createInstance = function() {
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
||||||
instance = new THREE.EdgesHelper(this.object.instance, 0x00FF00);
|
var edges = new THREE.EdgesGeometry(this.object.instance.geometry);
|
||||||
|
instance = new THREE.LineSegments(edges, new THREE.LineBasicMaterial({color:0x00ff00, linewidth:2}))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) {
|
if (this.helperType === GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT) {
|
||||||
|
|
|
@ -42,10 +42,13 @@ GameLib.D3.Image.prototype = Object.create(GameLib.D3.API.Image.prototype);
|
||||||
GameLib.D3.Image.prototype.constructor = GameLib.D3.Image;
|
GameLib.D3.Image.prototype.constructor = GameLib.D3.Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a light instance
|
* Creates an image instance
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Image.prototype.createInstance = function() {
|
GameLib.D3.Image.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
console.log('image create instance');
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,8 @@ GameLib.D3.Input.Editor = function (
|
||||||
this.mouseUp = null;
|
this.mouseUp = null;
|
||||||
this.mouseWheel = null;
|
this.mouseWheel = null;
|
||||||
|
|
||||||
|
this.selectAll = false;
|
||||||
|
|
||||||
this.controlLeft = false;
|
this.controlLeft = false;
|
||||||
|
|
||||||
this.raycaster = new GameLib.D3.Raycaster(
|
this.raycaster = new GameLib.D3.Raycaster(
|
||||||
|
@ -123,11 +125,14 @@ GameLib.D3.Input.Editor.FromObject = function(graphics, objectComponent) {
|
||||||
GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
|
GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
|
||||||
|
|
||||||
return function(event) {
|
return function(event) {
|
||||||
|
|
||||||
console.log('entity ' + entity.name + ' emitted keypress ' + event.code);
|
console.log('entity ' + entity.name + ' emitted keypress ' + event.code);
|
||||||
|
|
||||||
|
var meshes = null;
|
||||||
|
|
||||||
if (event.code === 'Delete') {
|
if (event.code === 'Delete') {
|
||||||
|
|
||||||
var meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]);
|
meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]);
|
||||||
|
|
||||||
var deletedMeshes = [];
|
var deletedMeshes = [];
|
||||||
|
|
||||||
|
@ -161,6 +166,22 @@ GameLib.D3.Input.Editor.prototype.onKeyDown = function(entity, entityManager) {
|
||||||
this.controlLeft = true;
|
this.controlLeft = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.code === 'KeyA') {
|
||||||
|
|
||||||
|
this.selectAll = !this.selectAll;
|
||||||
|
|
||||||
|
meshes = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh]);
|
||||||
|
|
||||||
|
meshes.map(function(mesh){
|
||||||
|
if (this.selectAll) {
|
||||||
|
this.selectMesh(mesh);
|
||||||
|
} else {
|
||||||
|
this.deSelectMesh(mesh);
|
||||||
|
}
|
||||||
|
}.bind(this))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// BELOW is just a test to stop systems from keypress - it works nicely :)
|
// BELOW is just a test to stop systems from keypress - it works nicely :)
|
||||||
// but of course, when the system is stopped it can no longer be started by keypress
|
// but of course, when the system is stopped it can no longer be started by keypress
|
||||||
// var inputSystem = entity.getComponents(GameLib.System).reduce(
|
// var inputSystem = entity.getComponents(GameLib.System).reduce(
|
||||||
|
@ -234,9 +255,9 @@ GameLib.D3.Input.Editor.prototype.onMouseWheel = function(entity) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Input.Editor.prototype.removeHelper = function(mesh, entity) {
|
GameLib.D3.Input.Editor.prototype.removeHelper = function(mesh) {
|
||||||
|
|
||||||
var components = entity.getComponents(GameLib.D3.Helper);
|
var components = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Helper);
|
||||||
|
|
||||||
var helper = components.reduce(
|
var helper = components.reduce(
|
||||||
function (result, component) {
|
function (result, component) {
|
||||||
|
@ -257,13 +278,72 @@ GameLib.D3.Input.Editor.prototype.removeHelper = function(mesh, entity) {
|
||||||
*/
|
*/
|
||||||
mesh.instance.material.polygonOffset = mesh.polygonOffset;
|
mesh.instance.material.polygonOffset = mesh.polygonOffset;
|
||||||
|
|
||||||
entity.removeComponent(helper);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.warn('failed to locate helper object which should exist for ' + mesh.name);
|
console.warn('failed to locate helper object which should exist for ' + mesh.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return helper;
|
return helper;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.selectMesh = function(mesh) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If mesh is already selected, do nothing
|
||||||
|
*/
|
||||||
|
if (mesh.selected === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify our component as being 'selected'
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
mesh.selected = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a helper to the scene
|
||||||
|
* @type GameLib.D3.Helper
|
||||||
|
*/
|
||||||
|
|
||||||
|
var helper = new GameLib.D3.Helper(
|
||||||
|
this.graphics,
|
||||||
|
null,
|
||||||
|
mesh.name + ' Helper',
|
||||||
|
mesh,
|
||||||
|
GameLib.D3.Helper.HELPER_TYPE_EDGES
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backup the polygonOffset value, then set it to 'true' - helps for clear nice outlines
|
||||||
|
*/
|
||||||
|
mesh.polygonOffset = mesh.instance.material.polygonOffset;
|
||||||
|
|
||||||
|
mesh.instance.material.polygonOffset = true;
|
||||||
|
|
||||||
|
mesh.parentScene.instance.add(helper.instance);
|
||||||
|
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.MESH_SELECTED,
|
||||||
|
{
|
||||||
|
mesh : mesh
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.deSelectMesh = function(mesh) {
|
||||||
|
|
||||||
|
mesh.selected = false;
|
||||||
|
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.MESH_DESELECTED,
|
||||||
|
{
|
||||||
|
mesh : mesh
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.removeHelper(mesh);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MouseDown events
|
* MouseDown events
|
||||||
* @param entity GameLib.Entity
|
* @param entity GameLib.Entity
|
||||||
|
@ -285,8 +365,6 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager)
|
||||||
this.mouse.x = (event.offsetX / renderer.instance.domElement.width) * 2 - 1;
|
this.mouse.x = (event.offsetX / renderer.instance.domElement.width) * 2 - 1;
|
||||||
this.mouse.y = -(event.offsetY / renderer.instance.domElement.height) * 2 + 1;
|
this.mouse.y = -(event.offsetY / renderer.instance.domElement.height) * 2 + 1;
|
||||||
|
|
||||||
var cameras = entity.getComponents(GameLib.D3.Camera);
|
|
||||||
|
|
||||||
var scenes = entity.getComponents(GameLib.D3.Scene);
|
var scenes = entity.getComponents(GameLib.D3.Scene);
|
||||||
|
|
||||||
var intersects = scenes.reduce(
|
var intersects = scenes.reduce(
|
||||||
|
@ -344,63 +422,10 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity, entityManager)
|
||||||
*/
|
*/
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
/**
|
|
||||||
* Notify our component as being 'selected'
|
|
||||||
* @type {boolean}
|
|
||||||
*/
|
|
||||||
mesh.selected = !mesh.selected;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a helper to the scene
|
|
||||||
* @type GameLib.D3.Helper
|
|
||||||
*/
|
|
||||||
var helper = null;
|
|
||||||
|
|
||||||
var scene = mesh.parentScene;
|
|
||||||
|
|
||||||
if (!scene) {
|
|
||||||
console.warn('the scene object for this mesh could not be located : ' + mesh.name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mesh.selected) {
|
if (mesh.selected) {
|
||||||
|
this.deSelectMesh(mesh);
|
||||||
helper = new GameLib.D3.Helper(
|
|
||||||
this.graphics,
|
|
||||||
null,
|
|
||||||
mesh.name + ' Helper',
|
|
||||||
mesh,
|
|
||||||
GameLib.D3.Helper.HELPER_TYPE_EDGES
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Backup the polygonOffset value, then set it to 'true' - helps for clear nice outlines
|
|
||||||
*/
|
|
||||||
mesh.polygonOffset = mesh.instance.material.polygonOffset;
|
|
||||||
|
|
||||||
mesh.instance.material.polygonOffset = true;
|
|
||||||
|
|
||||||
entity.addComponent(helper);
|
|
||||||
|
|
||||||
scene.instance.add(helper.instance);
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.MESH_SELECTED,
|
|
||||||
{
|
|
||||||
mesh : mesh
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
this.selectMesh(mesh);
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.MESH_DESELECTED,
|
|
||||||
{
|
|
||||||
mesh : mesh
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.removeHelper(mesh, entity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ GameLib.D3.Material = function(
|
||||||
apiMaterial.clipShadows,
|
apiMaterial.clipShadows,
|
||||||
apiMaterial.visible,
|
apiMaterial.visible,
|
||||||
apiMaterial.overdraw,
|
apiMaterial.overdraw,
|
||||||
apiMaterial.shading,
|
apiMaterial.flatShading,
|
||||||
apiMaterial.bumpScale,
|
apiMaterial.bumpScale,
|
||||||
apiMaterial.normalScale,
|
apiMaterial.normalScale,
|
||||||
apiMaterial.displacementScale,
|
apiMaterial.displacementScale,
|
||||||
|
@ -372,12 +372,12 @@ GameLib.D3.Material.prototype.createStandardMaterialInstance = function() {
|
||||||
displacementScale: this.displacementScale,
|
displacementScale: this.displacementScale,
|
||||||
refractionRatio: this.refractionRatio,
|
refractionRatio: this.refractionRatio,
|
||||||
fog: this.fog,
|
fog: this.fog,
|
||||||
shading: this.shading,
|
flatShading: this.flatShading,
|
||||||
wireframe: this.wireframe,
|
wireframe: this.wireframe,
|
||||||
wireframeLinewidth: this.wireframeLineWidth,
|
wireframeLinewidth: this.wireframeLineWidth,
|
||||||
wireframeLinecap: this.wireframeLineCap,
|
wireframeLinecap: this.wireframeLineCap,
|
||||||
wireframeLinejoin: this.wireframeLineJoin,
|
wireframeLinejoin: this.wireframeLineJoin,
|
||||||
vertexColors: this.vertexColors,
|
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS,
|
||||||
skinning: this.skinning,
|
skinning: this.skinning,
|
||||||
morphTargets: this.morphTargets,
|
morphTargets: this.morphTargets,
|
||||||
morphNormals: this.morphNormals
|
morphNormals: this.morphNormals
|
||||||
|
@ -408,7 +408,7 @@ GameLib.D3.Material.prototype.createPointsMaterialInstance = function() {
|
||||||
color: this.color.instance,
|
color: this.color.instance,
|
||||||
size: this.pointSize,
|
size: this.pointSize,
|
||||||
sizeAttenuation: this.pointSizeAttenuation,
|
sizeAttenuation: this.pointSizeAttenuation,
|
||||||
vertexColors: GameLib.D3.Material.TYPE_NO_COLORS,
|
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS,
|
||||||
fog: this.fog
|
fog: this.fog
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -447,12 +447,12 @@ GameLib.D3.Material.prototype.createPhongMaterialInstance = function() {
|
||||||
combine: this.combine,
|
combine: this.combine,
|
||||||
refractionRatio: this.refractionRatio,
|
refractionRatio: this.refractionRatio,
|
||||||
fog: this.fog,
|
fog: this.fog,
|
||||||
shading: this.shading,
|
flatShading: this.flatShading,
|
||||||
wireframe: this.wireframe,
|
wireframe: this.wireframe,
|
||||||
wireframeLinewidth: this.wireframeLineWidth,
|
wireframeLinewidth: this.wireframeLineWidth,
|
||||||
wireframeLinecap: this.wireframeLineCap,
|
wireframeLinecap: this.wireframeLineCap,
|
||||||
wireframeLinejoin: this.wireframeLineJoin,
|
wireframeLinejoin: this.wireframeLineJoin,
|
||||||
vertexColors: this.vertexColors,
|
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS,
|
||||||
skinning: this.skinning,
|
skinning: this.skinning,
|
||||||
morphTargets: this.morphTargets,
|
morphTargets: this.morphTargets,
|
||||||
morphNormals: this.morphNormals
|
morphNormals: this.morphNormals
|
||||||
|
@ -481,7 +481,7 @@ GameLib.D3.Material.prototype.createMeshBasicMaterialInstance = function() {
|
||||||
visible: this.visible,
|
visible: this.visible,
|
||||||
side: this.side,
|
side: this.side,
|
||||||
color: this.color.instance,
|
color: this.color.instance,
|
||||||
vertexColors: GameLib.D3.Material.TYPE_NO_COLORS,
|
vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS,
|
||||||
fog: this.fog
|
fog: this.fog
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -586,12 +586,12 @@ GameLib.D3.Material.prototype.updateStandardMaterialInstance = function() {
|
||||||
this.instance.displacementScale = this.displacementScale;
|
this.instance.displacementScale = this.displacementScale;
|
||||||
this.instance.refractionRatio = this.refractionRatio;
|
this.instance.refractionRatio = this.refractionRatio;
|
||||||
this.instance.fog = this.fog;
|
this.instance.fog = this.fog;
|
||||||
this.instance.shading = this.shading;
|
this.instance.flatShading = this.flatShading;
|
||||||
this.instance.wireframe = this.wireframe;
|
this.instance.wireframe = this.wireframe;
|
||||||
this.instance.wireframeLinewidth = this.wireframeLineWidth;
|
this.instance.wireframeLinewidth = this.wireframeLineWidth;
|
||||||
this.instance.wireframeLinecap = this.wireframeLineCap;
|
this.instance.wireframeLinecap = this.wireframeLineCap;
|
||||||
this.instance.wireframeLinejoin = this.wireframeLineJoin;
|
this.instance.wireframeLinejoin = this.wireframeLineJoin;
|
||||||
this.instance.vertexColors = this.vertexColors;
|
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
|
||||||
this.instance.skinning = this.skinning;
|
this.instance.skinning = this.skinning;
|
||||||
this.instance.morphTargets = this.morphTargets;
|
this.instance.morphTargets = this.morphTargets;
|
||||||
this.instance.morphNormals = this.morphNormals;
|
this.instance.morphNormals = this.morphNormals;
|
||||||
|
@ -620,7 +620,7 @@ GameLib.D3.Material.prototype.updatePointsMaterialInstance = function() {
|
||||||
this.instance.color = this.color.instance;
|
this.instance.color = this.color.instance;
|
||||||
this.instance.size = this.pointSize;
|
this.instance.size = this.pointSize;
|
||||||
this.instance.sizeAttenuation = this.pointSizeAttenuation;
|
this.instance.sizeAttenuation = this.pointSizeAttenuation;
|
||||||
this.instance.vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
|
||||||
this.instance.fog = this.fog;
|
this.instance.fog = this.fog;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -658,12 +658,12 @@ GameLib.D3.Material.prototype.updatePhongMaterialInstance = function() {
|
||||||
this.instance.combine = this.combine;
|
this.instance.combine = this.combine;
|
||||||
this.instance.refractionRatio = this.refractionRatio;
|
this.instance.refractionRatio = this.refractionRatio;
|
||||||
this.instance.fog = this.fog;
|
this.instance.fog = this.fog;
|
||||||
this.instance.shading = this.shading;
|
this.instance.flatShading = this.flatShading;
|
||||||
this.instance.wireframe = this.wireframe;
|
this.instance.wireframe = this.wireframe;
|
||||||
this.instance.wireframeLinewidth = this.wireframeLineWidth;
|
this.instance.wireframeLinewidth = this.wireframeLineWidth;
|
||||||
this.instance.wireframeLinecap = this.wireframeLineCap;
|
this.instance.wireframeLinecap = this.wireframeLineCap;
|
||||||
this.instance.wireframeLinejoin = this.wireframeLineJoin;
|
this.instance.wireframeLinejoin = this.wireframeLineJoin;
|
||||||
this.instance.vertexColors = this.vertexColors;
|
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
|
||||||
this.instance.skinning = this.skinning;
|
this.instance.skinning = this.skinning;
|
||||||
this.instance.morphTargets = this.morphTargets;
|
this.instance.morphTargets = this.morphTargets;
|
||||||
this.instance.morphNormals = this.morphNormals;
|
this.instance.morphNormals = this.morphNormals;
|
||||||
|
@ -690,7 +690,7 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() {
|
||||||
this.instance.visible = this.visible;
|
this.instance.visible = this.visible;
|
||||||
this.instance.side = this.side;
|
this.instance.side = this.side;
|
||||||
this.instance.color = this.color.instance;
|
this.instance.color = this.color.instance;
|
||||||
this.instance.vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
|
||||||
this.instance.fog = this.fog;
|
this.instance.fog = this.fog;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -700,6 +700,8 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Material.prototype.createInstance = function() {
|
GameLib.D3.Material.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
console.log('material create instance');
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
||||||
|
@ -736,6 +738,8 @@ GameLib.D3.Material.prototype.createInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Material.prototype.updateInstance = function() {
|
GameLib.D3.Material.prototype.updateInstance = function() {
|
||||||
|
|
||||||
|
console.log('material update instance');
|
||||||
|
|
||||||
if (!this.instance) {
|
if (!this.instance) {
|
||||||
console.warn('Attempt to update a non-existent instance');
|
console.warn('Attempt to update a non-existent instance');
|
||||||
return;
|
return;
|
||||||
|
@ -939,7 +943,7 @@ GameLib.D3.Material.prototype.toApiObject = function(save) {
|
||||||
this.clipShadows,
|
this.clipShadows,
|
||||||
this.visible,
|
this.visible,
|
||||||
this.overdraw,
|
this.overdraw,
|
||||||
this.shading,
|
this.flatShading,
|
||||||
this.bumpScale,
|
this.bumpScale,
|
||||||
this.normalScale,
|
this.normalScale,
|
||||||
this.displacementScale,
|
this.displacementScale,
|
||||||
|
|
|
@ -189,134 +189,6 @@ GameLib.D3.Mesh.prototype.updateVerticesFromGeometryInstance = function(geometry
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply vertex data to geometry instance
|
|
||||||
* @param geometry
|
|
||||||
*/
|
|
||||||
GameLib.D3.Mesh.prototype.applyVertexDataToInstance = function(geometry) {
|
|
||||||
|
|
||||||
if (this.vertices.length > 0) {
|
|
||||||
geometry.vertices = [];
|
|
||||||
this.vertices.map(
|
|
||||||
function(vertex) {
|
|
||||||
geometry.vertices.push(
|
|
||||||
new THREE.Vector3(
|
|
||||||
vertex.position.x,
|
|
||||||
vertex.position.y,
|
|
||||||
vertex.position.z
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
geometry.verticesNeedUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies face data information to the geometry
|
|
||||||
* @param geometry
|
|
||||||
*/
|
|
||||||
GameLib.D3.Mesh.prototype.applyFaceDataToGeometry = function(geometry) {
|
|
||||||
|
|
||||||
for (var f = 0; f < this.faces.length; f++) {
|
|
||||||
|
|
||||||
var face = new this.graphics.instance.Face3(
|
|
||||||
this.faces[f].v0,
|
|
||||||
this.faces[f].v1,
|
|
||||||
this.faces[f].v2,
|
|
||||||
new this.graphics.instance.Vector3(
|
|
||||||
this.faces[f].normal.x,
|
|
||||||
this.faces[f].normal.y,
|
|
||||||
this.faces[f].normal.z
|
|
||||||
),
|
|
||||||
new this.graphics.instance.Color(
|
|
||||||
this.faces[f].color.r,
|
|
||||||
this.faces[f].color.g,
|
|
||||||
this.faces[f].color.b
|
|
||||||
),
|
|
||||||
this.faces[f].materialIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
face.vertexColors = [
|
|
||||||
new this.graphics.instance.Color(
|
|
||||||
this.faces[f].vertexColors[0].r,
|
|
||||||
this.faces[f].vertexColors[0].g,
|
|
||||||
this.faces[f].vertexColors[0].b
|
|
||||||
),
|
|
||||||
new this.graphics.instance.Color(
|
|
||||||
this.faces[f].vertexColors[1].r,
|
|
||||||
this.faces[f].vertexColors[1].g,
|
|
||||||
this.faces[f].vertexColors[1].b
|
|
||||||
),
|
|
||||||
new this.graphics.instance.Color(
|
|
||||||
this.faces[f].vertexColors[2].r,
|
|
||||||
this.faces[f].vertexColors[2].g,
|
|
||||||
this.faces[f].vertexColors[2].b
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
face.normal = new this.graphics.instance.Vector3(
|
|
||||||
this.faces[f].normal.x,
|
|
||||||
this.faces[f].normal.y,
|
|
||||||
this.faces[f].normal.z
|
|
||||||
);
|
|
||||||
|
|
||||||
face.vertexNormals = [
|
|
||||||
new this.graphics.instance.Vector3(
|
|
||||||
this.faces[f].vertexNormals[0].x,
|
|
||||||
this.faces[f].vertexNormals[0].y,
|
|
||||||
this.faces[f].vertexNormals[0].z
|
|
||||||
),
|
|
||||||
new this.graphics.instance.Vector3(
|
|
||||||
this.faces[f].vertexNormals[1].x,
|
|
||||||
this.faces[f].vertexNormals[1].y,
|
|
||||||
this.faces[f].vertexNormals[1].z
|
|
||||||
),
|
|
||||||
new this.graphics.instance.Vector3(
|
|
||||||
this.faces[f].vertexNormals[2].x,
|
|
||||||
this.faces[f].vertexNormals[2].y,
|
|
||||||
this.faces[f].vertexNormals[2].z
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
geometry.faces.push(face);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply UV data to geometry instance
|
|
||||||
* @param geometry
|
|
||||||
*/
|
|
||||||
GameLib.D3.Mesh.prototype.applyUVDataToGeometry = function(geometry) {
|
|
||||||
|
|
||||||
geometry.faceVertexUvs = [];
|
|
||||||
|
|
||||||
for (var fm = 0; fm < this.faceVertexUvs.length; fm++) {
|
|
||||||
|
|
||||||
var faceMaterialVertexUvs = this.faceVertexUvs[fm];
|
|
||||||
|
|
||||||
geometry.faceVertexUvs[fm] = [];
|
|
||||||
|
|
||||||
for (var fuv = 0; fuv < faceMaterialVertexUvs.length; fuv++) {
|
|
||||||
geometry.faceVertexUvs[fm][fuv] = [];
|
|
||||||
geometry.faceVertexUvs[fm][fuv].push(
|
|
||||||
new this.graphics.instance.Vector2(
|
|
||||||
faceMaterialVertexUvs[fuv][0].x,
|
|
||||||
faceMaterialVertexUvs[fuv][0].y
|
|
||||||
),
|
|
||||||
new this.graphics.instance.Vector2(
|
|
||||||
faceMaterialVertexUvs[fuv][1].x,
|
|
||||||
faceMaterialVertexUvs[fuv][1].y
|
|
||||||
),
|
|
||||||
new this.graphics.instance.Vector2(
|
|
||||||
faceMaterialVertexUvs[fuv][2].x,
|
|
||||||
faceMaterialVertexUvs[fuv][2].y
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.applyBones = function(geometry) {
|
GameLib.D3.Mesh.prototype.applyBones = function(geometry) {
|
||||||
|
|
||||||
|
@ -412,19 +284,48 @@ GameLib.D3.Mesh.prototype.createInstanceDefaults = function(instance) {
|
||||||
instance.rotateZ(this.localRotation.z);
|
instance.rotateZ(this.localRotation.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.materials.length === 1 && this.materials[0].instance) {
|
|
||||||
instance.material = this.materials[0].instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.renderOrder = this.renderOrder;
|
instance.renderOrder = this.renderOrder;
|
||||||
|
|
||||||
this.subscribe(
|
this.subscribe(
|
||||||
GameLib.Event.MATERIAL_TYPE_CHANGED,
|
GameLib.Event.MATERIAL_TYPE_CHANGED,
|
||||||
function (data) {
|
function (data) {
|
||||||
if (this.materials[0] === data.material) {
|
|
||||||
this.instance.material = data.material.instance;
|
/**
|
||||||
|
* Check if this material is in use by the mesh
|
||||||
|
*/
|
||||||
|
|
||||||
|
var inUse = this.materials.reduce(
|
||||||
|
function(result, material) {
|
||||||
|
if (material === data.material) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the material is in use, assign all the new material instances to the mesh instance, and update
|
||||||
|
* geometry uvs
|
||||||
|
*/
|
||||||
|
if (inUse) {
|
||||||
|
|
||||||
|
this.instance.material = this.materials.map(
|
||||||
|
function(material){
|
||||||
|
return material.instance;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.instance.geometry.uvsNeedUpdate = true;
|
this.instance.geometry.uvsNeedUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if (this.materials[0] === data.material) {
|
||||||
|
// this.instance.material = data.material.instance;
|
||||||
|
// this.instance.geometry.uvsNeedUpdate = true;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -434,27 +335,201 @@ GameLib.D3.Mesh.prototype.createInstanceDefaults = function(instance) {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.prototype.createInstance = function() {
|
GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
|
|
||||||
var geometry = new THREE.Geometry();
|
console.log('mesh create instance');
|
||||||
|
|
||||||
|
function disposeArray() {
|
||||||
|
// this.array = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var geometry = new THREE.BufferGeometry();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup vertices
|
* Setup face indexes - first we sort according to the material index, because later we will create
|
||||||
|
* groups for each vertice group
|
||||||
*/
|
*/
|
||||||
this.applyVertexDataToInstance(geometry);
|
this.faces.sort(function(a, b){
|
||||||
|
|
||||||
|
if (a.materialIndex < b.materialIndex) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.materialIndex > b.materialIndex) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup faces
|
* Setup mesh vertices positions
|
||||||
|
* @type {Float32Array}
|
||||||
*/
|
*/
|
||||||
this.applyFaceDataToGeometry(geometry);
|
var vertices = new Float32Array(
|
||||||
|
|
||||||
|
this.faces.reduce(
|
||||||
|
function(result, face){
|
||||||
|
result.push(this.vertices[face.v0].position.x);
|
||||||
|
result.push(this.vertices[face.v0].position.y);
|
||||||
|
result.push(this.vertices[face.v0].position.z);
|
||||||
|
result.push(this.vertices[face.v1].position.x);
|
||||||
|
result.push(this.vertices[face.v1].position.y);
|
||||||
|
result.push(this.vertices[face.v1].position.z);
|
||||||
|
result.push(this.vertices[face.v2].position.x);
|
||||||
|
result.push(this.vertices[face.v2].position.y);
|
||||||
|
result.push(this.vertices[face.v2].position.z);
|
||||||
|
return result;
|
||||||
|
}.bind(this),
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
// this.vertices.reduce(
|
||||||
|
// function(result, vertex) {
|
||||||
|
// result.push(vertex.position.x);
|
||||||
|
// result.push(vertex.position.y);
|
||||||
|
// result.push(vertex.position.z);
|
||||||
|
// return result;
|
||||||
|
// },
|
||||||
|
// []
|
||||||
|
// )
|
||||||
|
);
|
||||||
|
geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3).onUpload( disposeArray ));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setyp mesh vertices colors
|
||||||
|
*/
|
||||||
|
var colors = Float32Array.from(
|
||||||
|
this.faces.reduce(
|
||||||
|
function(result, face){
|
||||||
|
result.push(1,1,1,1,1,1,1,1,1);
|
||||||
|
// result.push(face.color.r);
|
||||||
|
// result.push(face.color.g);
|
||||||
|
// result.push(face.color.b);
|
||||||
|
// result.push(face.color.r);
|
||||||
|
// result.push(face.color.g);
|
||||||
|
// result.push(face.color.b);
|
||||||
|
// result.push(face.color.r);
|
||||||
|
// result.push(face.color.g);
|
||||||
|
// result.push(face.color.b);
|
||||||
|
return result;
|
||||||
|
}.bind(this),
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3, true).onUpload( disposeArray ));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup face UVs
|
* Setup face UVs
|
||||||
*/
|
*/
|
||||||
this.applyUVDataToGeometry(geometry);
|
var uvs = Float32Array.from(
|
||||||
|
this.faceVertexUvs[0].reduce(
|
||||||
|
function(result, uv) {
|
||||||
|
result.push(uv[0].x);
|
||||||
|
result.push(uv[0].y);
|
||||||
|
result.push(uv[1].x);
|
||||||
|
result.push(uv[1].y);
|
||||||
|
result.push(uv[2].x);
|
||||||
|
result.push(uv[2].y);
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
geometry.addAttribute('uv', new THREE.BufferAttribute(uvs, 2).onUpload( disposeArray ));
|
||||||
|
|
||||||
|
|
||||||
|
// geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).onUpload( disposeArray ) );
|
||||||
|
// geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).onUpload( disposeArray ) );
|
||||||
|
// geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).onUpload( disposeArray ) );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now we create the face indices
|
||||||
|
*/
|
||||||
|
// var faceIndices = Uint32Array.from(
|
||||||
|
// this.faces.reduce(
|
||||||
|
// function(result, face) {
|
||||||
|
// result.push(face.v0);
|
||||||
|
// result.push(face.v1);
|
||||||
|
// result.push(face.v2);
|
||||||
|
// return result;
|
||||||
|
// },
|
||||||
|
// []
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// geometry.setIndex(new THREE.BufferAttribute(faceIndices, 1));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup material groups - this means creating a new group for each material index change
|
||||||
|
* We know faces are sorted according to material index
|
||||||
|
*/
|
||||||
|
var groupIndexCounts = this.faces.reduce(
|
||||||
|
function(result, face) {
|
||||||
|
|
||||||
|
var currentGroup = result.pop();
|
||||||
|
|
||||||
|
if (currentGroup.index !== face.materialIndex) {
|
||||||
|
/**
|
||||||
|
* We have a new group
|
||||||
|
*/
|
||||||
|
result.push(currentGroup);
|
||||||
|
result.push({
|
||||||
|
index: face.materialIndex,
|
||||||
|
count: 3
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
currentGroup.count += 3;
|
||||||
|
result.push(currentGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
[
|
||||||
|
{
|
||||||
|
index : 0,
|
||||||
|
count : 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
groupIndexCounts.reduce(
|
||||||
|
function(start, group) {
|
||||||
|
geometry.addGroup(start, group.count, group.index);
|
||||||
|
return start + group.count;
|
||||||
|
},
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
//geometry.addGroup(0, vertices.length, this.materials.length - 1);
|
||||||
|
//
|
||||||
|
// for (var fm = 0; fm < this.faceVertexUvs.length; fm++) {
|
||||||
|
//
|
||||||
|
// var faceMaterialVertexUvs = this.faceVertexUvs[fm];
|
||||||
|
//
|
||||||
|
// geometry.faceVertexUvs[fm] = [];
|
||||||
|
//
|
||||||
|
// for (var fuv = 0; fuv < faceMaterialVertexUvs.length; fuv++) {
|
||||||
|
// geometry.faceVertexUvs[fm][fuv] = [];
|
||||||
|
// geometry.faceVertexUvs[fm][fuv].push(
|
||||||
|
// new this.graphics.instance.Vector2(
|
||||||
|
// faceMaterialVertexUvs[fuv][0].x,
|
||||||
|
// faceMaterialVertexUvs[fuv][0].y
|
||||||
|
// ),
|
||||||
|
// new this.graphics.instance.Vector2(
|
||||||
|
// faceMaterialVertexUvs[fuv][1].x,
|
||||||
|
// faceMaterialVertexUvs[fuv][1].y
|
||||||
|
// ),
|
||||||
|
// new this.graphics.instance.Vector2(
|
||||||
|
// faceMaterialVertexUvs[fuv][2].x,
|
||||||
|
// faceMaterialVertexUvs[fuv][2].y
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply skin indices
|
* Apply skin indices
|
||||||
*/
|
*/
|
||||||
this.applyBones(geometry);
|
// this.applyBones(geometry);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-compute normals
|
* Re-compute normals
|
||||||
|
@ -464,15 +539,32 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
var instanceMaterials = function(result, material){
|
||||||
|
result.push(material.instance);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
if (this.skeleton) {
|
if (this.skeleton) {
|
||||||
instance = new THREE.SkinnedMesh(geometry);
|
instance = new THREE.SkinnedMesh(
|
||||||
|
geometry,
|
||||||
|
this.materials.reduce(
|
||||||
|
instanceMaterials,
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
);
|
||||||
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(geometry);
|
instance = new THREE.Mesh(
|
||||||
|
geometry,
|
||||||
|
this.materials.reduce(
|
||||||
|
instanceMaterials,
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createInstanceDefaults(instance);
|
//this.createInstanceDefaults(instance);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
@ -482,6 +574,8 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.prototype.updateInstance = function() {
|
GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
|
|
||||||
|
console.log('mesh update instance');
|
||||||
|
|
||||||
if (this.parentMesh && this.parentMesh.loaded) {
|
if (this.parentMesh && this.parentMesh.loaded) {
|
||||||
|
|
||||||
if (this.instance.parent !== this.parentMesh.instance) {
|
if (this.instance.parent !== this.parentMesh.instance) {
|
||||||
|
@ -655,3 +749,43 @@ GameLib.D3.Mesh.prototype.centerAroundOrigin = function() {
|
||||||
|
|
||||||
this.updateInstance();
|
this.updateInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies position, rotation and scale to the object vertice data, resets scale, rotation and sets position to origin.
|
||||||
|
*/
|
||||||
|
GameLib.D3.Mesh.prototype.applyLocalPositionRotationScale = function() {
|
||||||
|
|
||||||
|
this.instance.updateMatrix();
|
||||||
|
|
||||||
|
this.instance.geometry.applyMatrix(this.instance.matrix);
|
||||||
|
|
||||||
|
this.instance.position.set(0,0,0);
|
||||||
|
this.instance.rotation.set(0,0,0);
|
||||||
|
this.instance.scale.set(1,1,1);
|
||||||
|
|
||||||
|
this.instance.updateMatrix();
|
||||||
|
|
||||||
|
this.localPosition.x = this.instance.position.x;
|
||||||
|
this.localPosition.y = this.instance.position.y;
|
||||||
|
this.localPosition.z = this.instance.position.z;
|
||||||
|
|
||||||
|
this.localScale.x = this.instance.scale.x;
|
||||||
|
this.localScale.y = this.instance.scale.y;
|
||||||
|
this.localScale.z = this.instance.scale.z;
|
||||||
|
|
||||||
|
this.localRotation.x = this.instance.rotation.x;
|
||||||
|
this.localRotation.y = this.instance.rotation.y;
|
||||||
|
this.localRotation.z = this.instance.rotation.z;
|
||||||
|
|
||||||
|
console.log('TODO: update vertices from vertex array - we store them indexed but they live non-indexed');
|
||||||
|
// var vertices = this.instance.geometry.getAttribute('position').array;
|
||||||
|
//
|
||||||
|
// for (var v = 0; v < vertices.length; v+=3) {
|
||||||
|
//
|
||||||
|
// this.vertices[v/3].position.x = vertices[v+0];
|
||||||
|
// this.vertices[v/3].position.y = vertices[v+1];
|
||||||
|
// this.vertices[v/3].position.z = vertices[v+2];
|
||||||
|
// }
|
||||||
|
|
||||||
|
this.updateInstance();
|
||||||
|
};
|
|
@ -149,42 +149,49 @@ GameLib.D3.Raycaster.prototype.setPosition = function(
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) {
|
GameLib.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) {
|
||||||
|
|
||||||
var meshInstances = meshes.reduce(
|
return meshes.reduce(
|
||||||
function (result, mesh) {
|
function (result, mesh) {
|
||||||
|
|
||||||
if (mesh.instance) {
|
var intersects = this.instance.intersectObject(mesh.instance);
|
||||||
result.push(mesh.instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
if (intersects.length > 0) {
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
var intersects = this.instance.intersectObjects(meshInstances);
|
|
||||||
|
|
||||||
return intersects.reduce(
|
|
||||||
|
|
||||||
function (result, intersect) {
|
|
||||||
|
|
||||||
meshes.map(
|
|
||||||
function(mesh){
|
|
||||||
if (mesh.instance === intersect.object){
|
|
||||||
result.push(
|
result.push(
|
||||||
{
|
{
|
||||||
mesh : mesh,
|
mesh: mesh,
|
||||||
distance : intersect.distance
|
distance : intersects[0].distance
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
}.bind(this),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// var intersects = this.instance.intersectObjects(meshInstances);
|
||||||
|
//
|
||||||
|
// return intersects.reduce(
|
||||||
|
//
|
||||||
|
// function (result, intersect) {
|
||||||
|
//
|
||||||
|
// meshes.map(
|
||||||
|
// function(mesh){
|
||||||
|
// if (mesh.instance === intersect.object){
|
||||||
|
// result.push(
|
||||||
|
// {
|
||||||
|
// mesh : mesh,
|
||||||
|
// distance : intersect.distance
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
// },
|
||||||
|
// []
|
||||||
|
// );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,8 @@ GameLib.D3.Texture.TEXTURE_TYPE_CUBE = 0x2;
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.createInstance = function() {
|
GameLib.D3.Texture.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
console.log('texture create instance');
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) {
|
if (this.typeId === GameLib.D3.Texture.TEXTURE_TYPE_CUBE) {
|
||||||
|
@ -197,18 +199,18 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
||||||
this.mapping = GameLib.D3.Texture.TYPE_UV_MAPPING;
|
this.mapping = GameLib.D3.Texture.TYPE_UV_MAPPING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//
|
||||||
instance.name = this.name;
|
// instance.name = this.name;
|
||||||
instance.flipY = this.flipY;
|
// instance.flipY = this.flipY;
|
||||||
instance.encoding = this.encoding;
|
// instance.encoding = this.encoding;
|
||||||
instance.offset.x = this.offset.x;
|
// instance.offset.x = this.offset.x;
|
||||||
instance.offset.y = this.offset.y;
|
// instance.offset.y = this.offset.y;
|
||||||
instance.repeat.x = this.repeat.x;
|
// instance.repeat.x = this.repeat.x;
|
||||||
instance.repeat.y = this.repeat.y;
|
// instance.repeat.y = this.repeat.y;
|
||||||
instance.mapping = this.mapping;
|
// instance.mapping = this.mapping;
|
||||||
instance.format = this.format;
|
// instance.format = this.format;
|
||||||
instance.wrapS = this.wrapS;
|
// instance.wrapS = this.wrapS;
|
||||||
instance.wrapT = this.wrapT;
|
// instance.wrapT = this.wrapT;
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
@ -218,6 +220,8 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.updateInstance = function() {
|
GameLib.D3.Texture.prototype.updateInstance = function() {
|
||||||
|
|
||||||
|
console.log('texture update instance');
|
||||||
|
|
||||||
if (!this.instance) {
|
if (!this.instance) {
|
||||||
console.error('no texture instance');
|
console.error('no texture instance');
|
||||||
return;
|
return;
|
||||||
|
@ -251,17 +255,17 @@ GameLib.D3.Texture.prototype.updateInstance = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance.name = this.name;
|
// this.instance.name = this.name;
|
||||||
this.instance.flipY = this.flipY;
|
// this.instance.flipY = this.flipY;
|
||||||
this.instance.encoding = this.encoding;
|
// this.instance.encoding = this.encoding;
|
||||||
this.instance.offset.x = this.offset.x;
|
// this.instance.offset.x = this.offset.x;
|
||||||
this.instance.offset.y = this.offset.y;
|
// this.instance.offset.y = this.offset.y;
|
||||||
this.instance.repeat.x = this.repeat.x;
|
// this.instance.repeat.x = this.repeat.x;
|
||||||
this.instance.repeat.y = this.repeat.y;
|
// this.instance.repeat.y = this.repeat.y;
|
||||||
this.instance.mapping = this.mapping;
|
// this.instance.mapping = this.mapping;
|
||||||
this.instance.format = this.format;
|
// this.instance.format = this.format;
|
||||||
this.instance.wrapS = this.wrapS;
|
// this.instance.wrapS = this.wrapS;
|
||||||
this.instance.wrapT = this.wrapT;
|
// this.instance.wrapT = this.wrapT;
|
||||||
this.instance.needsUpdate = true;
|
this.instance.needsUpdate = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,39 +21,6 @@ GameLib.GUI = function(
|
||||||
}
|
}
|
||||||
this.gui = gui;
|
this.gui = gui;
|
||||||
|
|
||||||
/**
|
|
||||||
* Add some GUI behaviour
|
|
||||||
*/
|
|
||||||
this.gui.prototype.removeEmtpyFolders = function() {
|
|
||||||
for (var property in this.__folders) {
|
|
||||||
if (this.__folders.hasOwnProperty(property)){
|
|
||||||
|
|
||||||
var folder = this.__folders[property];
|
|
||||||
|
|
||||||
if (folder.__listening.length === 0) {
|
|
||||||
folder.close();
|
|
||||||
this.__ul.removeChild(folder.domElement.parentNode);
|
|
||||||
delete this.__folders[property];
|
|
||||||
this.onResize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.gui.prototype.removeAllFolders = function() {
|
|
||||||
for (var property in this.__folders) {
|
|
||||||
if (this.__folders.hasOwnProperty(property)){
|
|
||||||
|
|
||||||
var folder = this.__folders[property];
|
|
||||||
|
|
||||||
folder.close();
|
|
||||||
this.__ul.removeChild(folder.domElement.parentNode);
|
|
||||||
delete this.__folders[property];
|
|
||||||
this.onResize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
|
@ -92,13 +59,6 @@ GameLib.GUI = function(
|
||||||
GameLib.GUI.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.GUI.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.GUI.prototype.constructor = GameLib.GUI;
|
GameLib.GUI.prototype.constructor = GameLib.GUI;
|
||||||
|
|
||||||
/**
|
|
||||||
* Resize function
|
|
||||||
*/
|
|
||||||
GameLib.GUI.prototype.resize = function() {
|
|
||||||
console.log('override me per implementation');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a helper instance
|
* Creates a helper instance
|
||||||
*/
|
*/
|
||||||
|
@ -779,10 +739,14 @@ GameLib.GUI.prototype.buildControl = function(folder, object, property, entityMa
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, dimension) {
|
GameLib.GUI.prototype.buildVectorControl = function(folder, templateObject, property, dimension) {
|
||||||
|
|
||||||
var step = 0.1;
|
var step = 0.1;
|
||||||
|
|
||||||
|
var object = templateObject.template;
|
||||||
|
|
||||||
|
var affected = templateObject.affected;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
property === 'localRotation' ||
|
property === 'localRotation' ||
|
||||||
property === 'localPosition'
|
property === 'localPosition'
|
||||||
|
@ -795,10 +759,14 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
||||||
object[property],
|
object[property],
|
||||||
'w',
|
'w',
|
||||||
-100,
|
-100,
|
||||||
100
|
100,
|
||||||
).name(property + '.w').listen().step(step).onChange(
|
step
|
||||||
function() {
|
).name(property + '.w').listen().onChange(
|
||||||
object.updateInstance();
|
function(value) {
|
||||||
|
affected.map(function(component){
|
||||||
|
component[property].w = value;
|
||||||
|
component.updateInstance();
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -807,10 +775,14 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
||||||
object[property],
|
object[property],
|
||||||
'x',
|
'x',
|
||||||
-100,
|
-100,
|
||||||
100
|
100,
|
||||||
).name(property + '.x').listen().step(step).onChange(
|
step
|
||||||
function() {
|
).name(property + '.x').listen().onChange(
|
||||||
object.updateInstance();
|
function(value) {
|
||||||
|
affected.map(function(component){
|
||||||
|
component[property].x = value;
|
||||||
|
component.updateInstance();
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -818,10 +790,14 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
||||||
object[property],
|
object[property],
|
||||||
'y',
|
'y',
|
||||||
-100,
|
-100,
|
||||||
100
|
100,
|
||||||
).name(property + '.y').listen().step(step).onChange(
|
step
|
||||||
function() {
|
).name(property + '.y').listen().onChange(
|
||||||
object.updateInstance();
|
function(value) {
|
||||||
|
affected.map(function(component){
|
||||||
|
component[property].y = value;
|
||||||
|
component.updateInstance();
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -833,10 +809,14 @@ GameLib.GUI.prototype.buildVectorControl = function(folder, object, property, di
|
||||||
object[property],
|
object[property],
|
||||||
'z',
|
'z',
|
||||||
-100,
|
-100,
|
||||||
100
|
100,
|
||||||
).name(property + '.z').listen().step(step).onChange(
|
step
|
||||||
function() {
|
).name(property + '.z').listen().onChange(
|
||||||
object.updateInstance();
|
function(value) {
|
||||||
|
affected.map(function(component){
|
||||||
|
component[property].z = value;
|
||||||
|
component.updateInstance();
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1031,130 +1011,28 @@ GameLib.GUI.prototype.buildEntitySelectionControlFromArray = function(
|
||||||
}(this, entityManager));
|
}(this, entityManager));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.GUI.prototype.removeEmtpyFolders = function() {
|
||||||
|
this.instance.removeEmptyFolders();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.GUI.prototype.removeAllFolders = function() {
|
||||||
|
this.instance.removeAllFolders();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.GUI.prototype.addFolder = function(folderName) {
|
||||||
|
try {
|
||||||
|
return this.instance.addFolder(folderName);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the GUI
|
* Builds the GUI
|
||||||
*/
|
*/
|
||||||
GameLib.GUI.prototype.build = function(entityManager) {
|
GameLib.GUI.prototype.build = function(entityManager) {
|
||||||
|
|
||||||
this.instance.removeAllFolders();
|
console.log('hi');
|
||||||
|
|
||||||
this.objects.sort(
|
|
||||||
function(a, b) {
|
|
||||||
if (a.name > b.name) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.name < b.name) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
//
|
|
||||||
// var discoveredObjects = [];
|
|
||||||
//
|
|
||||||
// var parentObject = this.objects[0];
|
|
||||||
//
|
|
||||||
// this.objects.map(
|
|
||||||
//
|
|
||||||
// function(object) {
|
|
||||||
//
|
|
||||||
// if (object.idToObject) {
|
|
||||||
// for (var property in object.idToObject) {
|
|
||||||
// if (object.idToObject.hasOwnProperty(property)) {
|
|
||||||
// if (discoveredObjects.indexOf(object.idToObject[property]) === -1) {
|
|
||||||
// discoveredObjects.push(object.idToObject[property]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }.bind(this)
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// discoveredObjects
|
|
||||||
// );
|
|
||||||
|
|
||||||
this.objects.map(
|
|
||||||
|
|
||||||
function(object) {
|
|
||||||
|
|
||||||
var apiObject = object.toApiObject();
|
|
||||||
|
|
||||||
if (typeof(apiObject) === 'string') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var folder = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
folder = this.instance.addFolder(apiObject.name);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e.message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!folder) {
|
|
||||||
throw new Error('Could not create folder');
|
|
||||||
}
|
|
||||||
|
|
||||||
var property;
|
|
||||||
|
|
||||||
for (property in apiObject) {
|
|
||||||
if (
|
|
||||||
apiObject.hasOwnProperty(property) &&
|
|
||||||
object.hasOwnProperty(property)
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
object.linkedObjects &&
|
|
||||||
object.linkedObjects[property]
|
|
||||||
) {
|
|
||||||
if (property === 'parentEntity') {
|
|
||||||
this.buildEntitySelectionControlFromArray(
|
|
||||||
folder,
|
|
||||||
object,
|
|
||||||
property,
|
|
||||||
entityManager
|
|
||||||
)
|
|
||||||
} else if (object.linkedObjects[property] instanceof Array) {
|
|
||||||
this.buildArrayManager(
|
|
||||||
folder,
|
|
||||||
object,
|
|
||||||
property,
|
|
||||||
object.linkedObjects[property],
|
|
||||||
entityManager
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this.buildSelectControl(folder, object, property, entityManager, object.linkedObjects[property]);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (typeof (object[property]) === 'object') {
|
|
||||||
|
|
||||||
if (this.isColor(object[property])) {
|
|
||||||
this.buildControl(folder, object, property);
|
|
||||||
} else if (object[property] instanceof GameLib.Vector2) {
|
|
||||||
this.buildVectorControl(folder, object, property, 2);
|
|
||||||
} else if (object[property] instanceof GameLib.Vector3) {
|
|
||||||
this.buildVectorControl(folder, object, property, 3);
|
|
||||||
} else if (object[property] instanceof GameLib.Vector4) {
|
|
||||||
this.buildVectorControl(folder, object, property, 4);
|
|
||||||
} else {
|
|
||||||
console.log('ignored: ' + property);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.buildControl(folder, object, property, entityManager);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (property in object) {
|
|
||||||
if (typeof (object[property]) === 'function') {
|
|
||||||
folder.add(object, property);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.bind(this)
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -13,6 +13,8 @@ GameLib.System.GUI = function(
|
||||||
|
|
||||||
this.guis = [];
|
this.guis = [];
|
||||||
|
|
||||||
|
this.selected = [];
|
||||||
|
|
||||||
this.buildGUISubscription = null;
|
this.buildGUISubscription = null;
|
||||||
|
|
||||||
this.meshDeletedSubscription = null;
|
this.meshDeletedSubscription = null;
|
||||||
|
@ -34,6 +36,39 @@ GameLib.System.GUI.prototype.start = function() {
|
||||||
|
|
||||||
this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
|
this.guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add some GUI behaviour
|
||||||
|
*/
|
||||||
|
dat.GUI.prototype.removeEmtpyFolders = function() {
|
||||||
|
for (var property in this.__folders) {
|
||||||
|
if (this.__folders.hasOwnProperty(property)){
|
||||||
|
|
||||||
|
var folder = this.__folders[property];
|
||||||
|
|
||||||
|
if (folder.__listening.length === 0) {
|
||||||
|
folder.close();
|
||||||
|
this.__ul.removeChild(folder.domElement.parentNode);
|
||||||
|
delete this.__folders[property];
|
||||||
|
this.onResize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dat.GUI.prototype.removeAllFolders = function() {
|
||||||
|
for (var property in this.__folders) {
|
||||||
|
if (this.__folders.hasOwnProperty(property)){
|
||||||
|
|
||||||
|
var folder = this.__folders[property];
|
||||||
|
|
||||||
|
folder.close();
|
||||||
|
this.__ul.removeChild(folder.domElement.parentNode);
|
||||||
|
delete this.__folders[property];
|
||||||
|
this.onResize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.guis.map(function(gui){
|
this.guis.map(function(gui){
|
||||||
gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
|
gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
|
||||||
});
|
});
|
||||||
|
@ -50,12 +85,12 @@ GameLib.System.GUI.prototype.start = function() {
|
||||||
|
|
||||||
this.meshSelectedSubscription = this.subscribe(
|
this.meshSelectedSubscription = this.subscribe(
|
||||||
GameLib.Event.MESH_SELECTED,
|
GameLib.Event.MESH_SELECTED,
|
||||||
this.meshSelected
|
this.meshSelectionChange
|
||||||
);
|
);
|
||||||
|
|
||||||
this.meshDeselectedSubscription = this.subscribe(
|
this.meshDeselectedSubscription = this.subscribe(
|
||||||
GameLib.Event.MESH_DESELECTED,
|
GameLib.Event.MESH_DESELECTED,
|
||||||
this.meshDeslected
|
this.meshSelectionChange
|
||||||
);
|
);
|
||||||
|
|
||||||
this.newEntitySubscription = this.subscribe(
|
this.newEntitySubscription = this.subscribe(
|
||||||
|
@ -66,19 +101,263 @@ GameLib.System.GUI.prototype.start = function() {
|
||||||
|
|
||||||
GameLib.System.GUI.prototype.buildGUI = function(data) {
|
GameLib.System.GUI.prototype.buildGUI = function(data) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.guis.map(function(gui){
|
this.guis.map(function(gui){
|
||||||
gui.objects = [];
|
|
||||||
|
|
||||||
if (
|
/**
|
||||||
data.components &&
|
* Check if we have data
|
||||||
data.components.length > 0
|
*/
|
||||||
) {
|
if (GameLib.Utils.UndefinedOrNull(data.components)) {
|
||||||
gui.objects = data.components;
|
console.log('no data components');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.build(GameLib.EntityManager.Instance);
|
if (GameLib.Utils.UndefinedOrNull(data.components.length) || data.components.length === 0) {
|
||||||
|
console.log('no components selected');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First, start fresh - remove all folders
|
||||||
|
*/
|
||||||
|
gui.removeAllFolders();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort the components by component type
|
||||||
|
*/
|
||||||
|
data.components.sort(
|
||||||
|
|
||||||
|
function(a, b) {
|
||||||
|
|
||||||
|
if (a.componentType > b.componentType) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.componentType < b.componentType) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split the components into groups of componentType
|
||||||
|
*/
|
||||||
|
var componentGroups = data.components.reduce(
|
||||||
|
function(result, component) {
|
||||||
|
|
||||||
|
var componentData = result.pop();
|
||||||
|
|
||||||
|
if (component.componentType === componentData.componentType) {
|
||||||
|
/**
|
||||||
|
* This is the first component
|
||||||
|
*/
|
||||||
|
componentData.components.push(component);
|
||||||
|
result.push(componentData);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component.componentType !== componentData.componentType) {
|
||||||
|
result.push(componentData);
|
||||||
|
result.push({
|
||||||
|
componentType : component.componentType,
|
||||||
|
components:[component]
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
[
|
||||||
|
{
|
||||||
|
componentType : data.components[0].componentType,
|
||||||
|
components : []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
componentGroups.map(
|
||||||
|
|
||||||
|
function(componentGroup){
|
||||||
|
|
||||||
|
if (componentGroup.components.length < 1) {
|
||||||
|
console.warn('invalid number of components');
|
||||||
|
}
|
||||||
|
|
||||||
|
var templateObject = {
|
||||||
|
template : {
|
||||||
|
/**
|
||||||
|
* Doing this here is just to put parentEntity at the top of the gui
|
||||||
|
*/
|
||||||
|
'parentEntity' : componentGroup.components[0].parentEntity
|
||||||
|
},
|
||||||
|
affected : [componentGroup.components[0]],
|
||||||
|
componentType : componentGroup.componentType
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var property in componentGroup.components[0]) {
|
||||||
|
if (
|
||||||
|
componentGroup.components[0].hasOwnProperty(property) ||
|
||||||
|
typeof componentGroup.components[0][property] === 'function'
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (typeof componentGroup.components[0][property] === 'function') {
|
||||||
|
|
||||||
|
templateObject.template[property] = function(__property) {
|
||||||
|
|
||||||
|
return function() {
|
||||||
|
|
||||||
|
this.affected.map(
|
||||||
|
function(component) {
|
||||||
|
component[__property].bind(component)();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}.bind(templateObject);
|
||||||
|
|
||||||
|
}(property);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
templateObject.template[property] = componentGroup.components[0][property];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var componentTemplate = componentGroup.components.reduce(
|
||||||
|
|
||||||
|
function(result, component) {
|
||||||
|
|
||||||
|
if (component === componentGroup.components[0]) {
|
||||||
|
/**
|
||||||
|
* This is the first component, just return
|
||||||
|
*/
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now start to filter out the properties
|
||||||
|
*/
|
||||||
|
for (var property in component) {
|
||||||
|
if (
|
||||||
|
component.hasOwnProperty(property)
|
||||||
|
) {
|
||||||
|
if (!result.template.hasOwnProperty(property)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
result.template[property] instanceof GameLib.Vector2 ||
|
||||||
|
result.template[property] instanceof GameLib.Vector3 ||
|
||||||
|
result.template[property] instanceof GameLib.Vector4
|
||||||
|
) {
|
||||||
|
if (!result.template[property].equals(component[property])) {
|
||||||
|
delete result.template[property];
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.template[property] !== component[property]) {
|
||||||
|
delete result.template[property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the affected component
|
||||||
|
*/
|
||||||
|
result.affected.push(component);
|
||||||
|
return result;
|
||||||
|
|
||||||
|
},
|
||||||
|
templateObject
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* componentTemplate now contains for this particular component type group - all
|
||||||
|
* the properties which are modifiable, and also the objects affected by this property changes
|
||||||
|
*/
|
||||||
|
var name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(componentTemplate.template.name)) {
|
||||||
|
name = GameLib.Component.GetComponentName(componentTemplate.componentType);
|
||||||
|
} else {
|
||||||
|
name = componentTemplate.template.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
var folder = gui.addFolder(name);
|
||||||
|
|
||||||
|
if (!folder) {
|
||||||
|
throw new Error('Could not create folder');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var templateProperty in componentTemplate.template) {
|
||||||
|
|
||||||
|
if (
|
||||||
|
componentTemplate.template.hasOwnProperty(templateProperty) ||
|
||||||
|
typeof (componentTemplate.template[templateProperty]) === 'function'
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (typeof (componentTemplate.template[templateProperty]) === 'function') {
|
||||||
|
folder.add(componentTemplate.template, templateProperty);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (componentTemplate.template[templateProperty] instanceof GameLib.Vector2) {
|
||||||
|
gui.buildVectorControl(folder, componentTemplate, templateProperty, 2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (componentTemplate.template[templateProperty] instanceof GameLib.Vector3) {
|
||||||
|
gui.buildVectorControl(folder, componentTemplate, templateProperty, 3);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (componentTemplate.template[templateProperty] instanceof GameLib.Vector4) {
|
||||||
|
gui.buildVectorControl(folder, componentTemplate, templateProperty, 4);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (
|
||||||
|
// component.linkedObjects &&
|
||||||
|
// component.linkedObjects[property]
|
||||||
|
// ) {
|
||||||
|
// if (property === 'parentEntity') {
|
||||||
|
// this.buildEntitySelectionControlFromArray(
|
||||||
|
// folder,
|
||||||
|
// component,
|
||||||
|
// property,
|
||||||
|
// entityManager
|
||||||
|
// )
|
||||||
|
// } else if (component.linkedObjects[property] instanceof Array) {
|
||||||
|
// this.buildArrayManager(
|
||||||
|
// folder,
|
||||||
|
// component,
|
||||||
|
// property,
|
||||||
|
// component.linkedObjects[property],
|
||||||
|
// entityManager
|
||||||
|
// )
|
||||||
|
// } else {
|
||||||
|
// this.buildSelectControl(folder, component, property, entityManager, component.linkedObjects[property]);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// } else if (typeof (component[property]) === 'object') {
|
||||||
|
//
|
||||||
|
// if (this.isColor(component[property])) {
|
||||||
|
// this.buildControl(folder, component, property);
|
||||||
|
// } else {
|
||||||
|
// //console.log('ignored: ' + property);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// this.buildControl(folder, component, property, entityManager);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -87,23 +366,29 @@ GameLib.System.GUI.prototype.meshDeleted = function(data) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.GUI.prototype.meshSelected = function(data) {
|
GameLib.System.GUI.prototype.meshSelectionChange = function(data) {
|
||||||
|
|
||||||
var mesh = data.mesh;
|
var meshes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Mesh);
|
||||||
|
|
||||||
var objectsToAdd = [];
|
var components = [];
|
||||||
|
|
||||||
this.guis.map(
|
meshes.map(function(mesh){
|
||||||
function(gui) {
|
|
||||||
if (mesh.parentEntity) {
|
if (!mesh.selected) {
|
||||||
GameLib.Utils.PushUnique(objectsToAdd, mesh.parentEntity);
|
return;
|
||||||
}
|
}
|
||||||
objectsToAdd.push(mesh);
|
|
||||||
|
if (mesh.parentEntity) {
|
||||||
|
GameLib.Utils.PushUnique(components, mesh.parentEntity);
|
||||||
|
}
|
||||||
|
components.push(mesh);
|
||||||
|
|
||||||
mesh.materials.map(
|
mesh.materials.map(
|
||||||
function(material){
|
function(material){
|
||||||
GameLib.Utils.PushUnique(objectsToAdd, material);
|
GameLib.Utils.PushUnique(components, material);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
mesh.materials.map(
|
mesh.materials.map(
|
||||||
function(material){
|
function(material){
|
||||||
for (var property in material.linkedObjects) {
|
for (var property in material.linkedObjects) {
|
||||||
|
@ -114,7 +399,7 @@ GameLib.System.GUI.prototype.meshSelected = function(data) {
|
||||||
property !== 'parentEntity'
|
property !== 'parentEntity'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
GameLib.Utils.PushUnique(objectsToAdd, material[property]);
|
GameLib.Utils.PushUnique(components, material[property]);
|
||||||
for (var tProperty in material[property].linkedObjects) {
|
for (var tProperty in material[property].linkedObjects) {
|
||||||
if (
|
if (
|
||||||
material[property].linkedObjects.hasOwnProperty(tProperty) &&
|
material[property].linkedObjects.hasOwnProperty(tProperty) &&
|
||||||
|
@ -122,44 +407,31 @@ GameLib.System.GUI.prototype.meshSelected = function(data) {
|
||||||
material[property][tProperty] &&
|
material[property][tProperty] &&
|
||||||
tProperty !== 'parentEntity'
|
tProperty !== 'parentEntity'
|
||||||
) {
|
) {
|
||||||
GameLib.Utils.PushUnique(objectsToAdd, material[property][tProperty]);
|
GameLib.Utils.PushUnique(components, material[property][tProperty]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.guis.map(function(gui){
|
|
||||||
objectsToAdd.map(function(object){
|
|
||||||
gui.addObject(object);
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
gui.build(GameLib.EntityManager.Instance);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.meshSelectionObjects[mesh.id] = objectsToAdd;
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.BUILD_GUI,
|
||||||
|
{
|
||||||
|
components : components
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.System.GUI.prototype.meshSelected = function(data) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.GUI.prototype.meshDeslected = function(data) {
|
GameLib.System.GUI.prototype.meshDeslected = function(data) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.meshSelectionObjects[data.mesh.id])) {
|
|
||||||
console.warn('selected mesh data not available');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.guis.map(
|
|
||||||
function(gui) {
|
|
||||||
this.meshSelectionObjects[data.mesh.id].map(function(object){
|
|
||||||
gui.removeObject(object);
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
gui.build(GameLib.EntityManager.Instance);
|
|
||||||
}.bind(this)
|
|
||||||
)
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.GUI.prototype.newEntity = function(data) {
|
GameLib.System.GUI.prototype.newEntity = function(data) {
|
||||||
|
@ -172,6 +444,10 @@ GameLib.System.GUI.prototype.stop = function() {
|
||||||
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement);
|
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
delete dat.GUI.removeEmtpyFolders;
|
||||||
|
|
||||||
|
delete dat.GUI.removeAllFolders;
|
||||||
|
|
||||||
this.buildGUISubscription.remove();
|
this.buildGUISubscription.remove();
|
||||||
|
|
||||||
this.meshDeletedSubscription.remove();
|
this.meshDeletedSubscription.remove();
|
||||||
|
|
|
@ -146,6 +146,17 @@ GameLib.System.Linking.prototype.resolveDependencies = function(component) {
|
||||||
this.resolved.push(component);
|
this.resolved.push(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First check if the dependencies have already been met
|
||||||
|
*/
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentComponent.dependencies)) {
|
||||||
|
/**
|
||||||
|
* These dependencies have already been met - it is time to update the instance
|
||||||
|
*/
|
||||||
|
parentComponent.updateInstance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the actual dependency
|
* Remove the actual dependency
|
||||||
*/
|
*/
|
||||||
|
@ -304,7 +315,13 @@ GameLib.System.Linking.prototype.componentCreated = function(data) {
|
||||||
GameLib.System.Linking.prototype.imageNotFound = function(data) {
|
GameLib.System.Linking.prototype.imageNotFound = function(data) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For blender files (and others) - we need to create the textures without images
|
* OK - here we do not have an image.
|
||||||
|
* The right thing to do - is to simply create a MeshBasicMaterial - we completely
|
||||||
|
* ignore the dependencies - because we want to resolve them still later.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For blender files (and others) - we create Basic Material Instances
|
||||||
*/
|
*/
|
||||||
var textures = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Texture);
|
var textures = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Texture);
|
||||||
|
|
||||||
|
@ -315,26 +332,46 @@ GameLib.System.Linking.prototype.imageNotFound = function(data) {
|
||||||
*/
|
*/
|
||||||
if (texture.image === data.image.id) {
|
if (texture.image === data.image.id) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(texture.dependencies)) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This texture will never load because the image does not exist - so create
|
* The texture instance has already been created, we need to update the instance
|
||||||
* its instance (without the image)
|
|
||||||
*/
|
*/
|
||||||
|
if (texture && texture.instance) {
|
||||||
|
texture.updateInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove this image as a dependency
|
||||||
|
*/
|
||||||
|
var index = texture.dependencies.indexOf(data.image.id);
|
||||||
|
if (index !== -1) {
|
||||||
|
texture.dependencies.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If all dependencies have been met - create the instance and notify other listeners.
|
||||||
|
*/
|
||||||
|
if (texture.dependencies.length === 0) {
|
||||||
|
delete texture.dependencies;
|
||||||
|
|
||||||
texture.instance = texture.createInstance();
|
texture.instance = texture.createInstance();
|
||||||
|
|
||||||
/**
|
if (texture.instance) {
|
||||||
* We override the 'loaded' value - we say its loaded because it will be just with defaults
|
|
||||||
* @type {boolean}
|
|
||||||
*/
|
|
||||||
texture.loaded = true;
|
texture.loaded = true;
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
this.resolveDependencies(texture);
|
||||||
GameLib.Event.TEXTURE_INSTANCE_CREATED,
|
|
||||||
{
|
texture.buildIdToObject();
|
||||||
texture: texture
|
|
||||||
|
GameLib.Event.EmitInstanceEvents(texture);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -407,7 +444,44 @@ GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
|
GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
|
||||||
|
/**
|
||||||
|
* We resolve the dependencies
|
||||||
|
*/
|
||||||
this.resolveDependencies(data.image);
|
this.resolveDependencies(data.image);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* At this point - updateInstance on the texture will have been called - we need to update the material
|
||||||
|
*/
|
||||||
|
var textures = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Texture]);
|
||||||
|
|
||||||
|
var materials = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Material]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For each material that uses this texture
|
||||||
|
*/
|
||||||
|
textures.map(function(texture){
|
||||||
|
|
||||||
|
materials.map(function(material){
|
||||||
|
|
||||||
|
var materialNeedsUpdate = false;
|
||||||
|
|
||||||
|
for (var property in material) {
|
||||||
|
if (material.hasOwnProperty(property) &&
|
||||||
|
material[property] === texture) {
|
||||||
|
materialNeedsUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (materialNeedsUpdate) {
|
||||||
|
material.updateInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Linking.prototype.textureInstanceCreated = function(data) {
|
GameLib.System.Linking.prototype.textureInstanceCreated = function(data) {
|
||||||
|
|
Loading…
Reference in New Issue