fonts, text meshes, lines, input system refactorings
parent
79b809996d
commit
c3475ccef7
|
@ -99,6 +99,10 @@ GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
|
|||
GameLib.Event.ANIMATION_MESH_REMOVED = 0x52;
|
||||
GameLib.Event.GET_SCENE = 0x53;
|
||||
GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54;
|
||||
GameLib.Event.LOAD_FONT = 0x55;
|
||||
GameLib.Event.FONT_NOT_FOUND = 0x56;
|
||||
GameLib.Event.FONT_INSTANCE_CREATED = 0x57;
|
||||
GameLib.Event.REGISTER_DEPENDENCIES = 0x58;
|
||||
|
||||
/**
|
||||
* Returns string name of event ID
|
||||
|
@ -193,6 +197,10 @@ GameLib.Event.GetEventName = function(number) {
|
|||
case 0x52 : return 'animation_mesh_removed';
|
||||
case 0x53 : return 'get_scene';
|
||||
case 0x54 : return 'custom_code_window_resize';
|
||||
case 0x55 : return 'load_font';
|
||||
case 0x56 : return 'font_not_found';
|
||||
case 0x57 : return 'font_instance_created';
|
||||
case 0x58 : return 'register_dependencies';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,13 @@ GameLib.Component = function(
|
|||
}
|
||||
);
|
||||
|
||||
// GameLib.Event.Emit(
|
||||
// GameLib.Event.COMPONENT_CREATED,
|
||||
// {
|
||||
// component : this
|
||||
// }
|
||||
// );
|
||||
|
||||
if (this.dependencies.length === 0) {
|
||||
|
||||
delete this.dependencies;
|
||||
|
@ -48,6 +55,13 @@ GameLib.Component = function(
|
|||
this.buildIdToObject();
|
||||
GameLib.Event.EmitInstanceEvents(this);
|
||||
}
|
||||
} else {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.REGISTER_DEPENDENCIES,
|
||||
{
|
||||
component : this
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,16 +90,33 @@ GameLib.Component.prototype.getDependencies = function() {
|
|||
this.hasOwnProperty(property)
|
||||
){
|
||||
if (typeof this[property] === 'string') {
|
||||
dependencies.push(this[property]);
|
||||
GameLib.Utils.PushUnique(dependencies, this[property]);
|
||||
}
|
||||
|
||||
if (this[property] instanceof Array) {
|
||||
this[property].map(function(arrayProperty){
|
||||
if (typeof arrayProperty === 'string') {
|
||||
dependencies.push(arrayProperty);
|
||||
|
||||
if (typeof arrayProperty === 'string') {
|
||||
GameLib.Utils.PushUnique(dependencies, arrayProperty);
|
||||
}
|
||||
|
||||
if (arrayProperty &&
|
||||
typeof arrayProperty === 'object' &&
|
||||
arrayProperty.hasOwnProperty('loaded') &&
|
||||
arrayProperty.loaded === false
|
||||
) {
|
||||
GameLib.Utils.PushUnique(dependencies, arrayProperty.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this[property] &&
|
||||
typeof this[property] === 'object' &&
|
||||
this[property].hasOwnProperty('loaded') &&
|
||||
this[property].loaded === false
|
||||
) {
|
||||
GameLib.Utils.PushUnique(dependencies, this[property].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,6 +185,8 @@ GameLib.Component.COMPONENT_CLOCK = 0x37;
|
|||
GameLib.Component.COMPONENT_ANIMATION = 0x38;
|
||||
GameLib.Component.COMPONENT_CONTROLS_KEYBOARD = 0x39;
|
||||
GameLib.Component.COMPONENT_CONTROLS_MOUSE = 0x3a;
|
||||
GameLib.Component.COMPONENT_MESH_TEXT = 0x3b;
|
||||
GameLib.Component.COMPONENT_FONT = 0x3c;
|
||||
|
||||
/**
|
||||
* Returns string name for component number
|
||||
|
@ -221,6 +254,8 @@ GameLib.Component.GetComponentName = function(number) {
|
|||
case 0x38 : return 'GameLib.D3.Animation';
|
||||
case 0x39 : return 'GameLib.D3.Controls.Keyboard';
|
||||
case 0x3a : return 'GameLib.D3.Controls.Mouse';
|
||||
case 0x3b : return 'GameLib.D3.Mesh.Text';
|
||||
case 0x3c : return 'GameLib.D3.Font';
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Raw Font API object - should always correspond with the Font Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param url
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Font = function(
|
||||
id,
|
||||
name,
|
||||
url,
|
||||
parentEntity
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Font (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(url)) {
|
||||
url = '/apiRelative/path/to/font';
|
||||
}
|
||||
this.url = url;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)){
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Font.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.API.Font.prototype.constructor = GameLib.D3.API.Font;
|
||||
|
||||
/**
|
||||
* Returns an API light from an Object light
|
||||
* @param objectFont
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Font.FromObject = function(objectFont) {
|
||||
return new GameLib.D3.API.Font(
|
||||
objectFont.id,
|
||||
objectFont.name,
|
||||
objectFont.url,
|
||||
objectFont.parentEntity
|
||||
);
|
||||
};
|
|
@ -81,7 +81,7 @@ GameLib.D3.API.Light = function(
|
|||
this.intensity = intensity;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3(0,10,0);
|
||||
position = new GameLib.API.Vector3(10,10,10);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
|
|
|
@ -3,15 +3,10 @@
|
|||
* @param id String
|
||||
* @param name String
|
||||
* @param meshes [GameLib.D3.API.Mesh]
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param quaternion GameLib.API.Quaternion
|
||||
* @param scale GameLib.API.Vector3
|
||||
* @param parentGameId
|
||||
* @param lights [GameLib.D3.API.Light]
|
||||
* @param textures [GameLib.D3.API.Texture]
|
||||
* @param materials [GameLib.D3.API.Material]
|
||||
* @param images
|
||||
* @param activeCamera [GameLib.D3.Camera]
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -19,15 +14,10 @@ GameLib.D3.API.Scene = function(
|
|||
id,
|
||||
name,
|
||||
meshes,
|
||||
position,
|
||||
quaternion,
|
||||
scale,
|
||||
parentGameId,
|
||||
lights,
|
||||
textures,
|
||||
materials,
|
||||
images,
|
||||
activeCamera,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
|
@ -46,26 +36,6 @@ GameLib.D3.API.Scene = function(
|
|||
}
|
||||
this.meshes = meshes;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3();
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentGameId)) {
|
||||
parentGameId = null;
|
||||
}
|
||||
this.parentGameId = parentGameId;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(lights)) {
|
||||
lights = [];
|
||||
}
|
||||
|
@ -86,11 +56,6 @@ GameLib.D3.API.Scene = function(
|
|||
}
|
||||
this.images = images;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(activeCamera)) {
|
||||
activeCamera = null;
|
||||
}
|
||||
this.activeCamera = activeCamera;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
|
@ -114,12 +79,6 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
|
|||
var apiMaterials = [];
|
||||
var apiImages = [];
|
||||
|
||||
var apiPosition = new GameLib.API.Vector3();
|
||||
var apiQuaternion = new GameLib.API.Quaternion();
|
||||
var apiScale = new GameLib.API.Vector3(1,1,1);
|
||||
|
||||
var apiActiveCamera = null;
|
||||
|
||||
if (objectScene.meshes) {
|
||||
apiMeshes = objectScene.meshes.map(
|
||||
function(objectMesh) {
|
||||
|
@ -180,35 +139,14 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
|
|||
)
|
||||
}
|
||||
|
||||
if (objectScene.position) {
|
||||
apiPosition = GameLib.API.Vector3.FromObject(objectScene.position);
|
||||
}
|
||||
|
||||
if (objectScene.quaternion) {
|
||||
apiQuaternion = GameLib.API.Quaternion.FromObject(objectScene.quaternion);
|
||||
}
|
||||
|
||||
if (objectScene.scale) {
|
||||
apiScale = GameLib.API.Vector3.FromObject(objectScene.scale);
|
||||
}
|
||||
|
||||
if (objectScene.activeCamera) {
|
||||
apiActiveCamera = objectScene.activeCamera;
|
||||
}
|
||||
|
||||
return new GameLib.D3.API.Scene(
|
||||
objectScene.id,
|
||||
objectScene.name,
|
||||
apiMeshes,
|
||||
apiPosition,
|
||||
apiQuaternion,
|
||||
apiScale,
|
||||
objectScene.parentGameId,
|
||||
apiLights,
|
||||
apiTextures,
|
||||
apiMaterials,
|
||||
apiImages,
|
||||
apiActiveCamera,
|
||||
objectScene.parentEntity
|
||||
);
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ GameLib.D3.Controls = function (
|
|||
|
||||
componentType = GameLib.Component.COMPONENT_CONTROLS_EDITOR;
|
||||
|
||||
linkedObjects.raycaster = GameLib.D3.Raycaster;
|
||||
linkedObjects.renderer = GameLib.D3.Renderer;
|
||||
linkedObjects.raycaster = GameLib.D3.Raycaster;
|
||||
linkedObjects.camera = GameLib.D3.Camera;
|
||||
}
|
||||
|
||||
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_TOUCH) {
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiControls GameLib.D3.API.Controls
|
||||
* @param raycaster
|
||||
* @param renderer
|
||||
* @param camera
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Controls.Editor = function (
|
||||
graphics,
|
||||
apiControls,
|
||||
raycaster,
|
||||
renderer
|
||||
camera
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
|
@ -21,10 +21,10 @@ GameLib.D3.Controls.Editor = function (
|
|||
}
|
||||
this.raycaster = raycaster;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderer)) {
|
||||
renderer = null;
|
||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.renderer = renderer;
|
||||
this.camera = camera;
|
||||
|
||||
if (this.raycaster instanceof GameLib.D3.API.Raycaster) {
|
||||
this.raycaster = new GameLib.D3.Raycaster(
|
||||
|
@ -33,10 +33,10 @@ GameLib.D3.Controls.Editor = function (
|
|||
);
|
||||
}
|
||||
|
||||
if (this.renderer instanceof GameLib.D3.API.Renderer) {
|
||||
this.renderer = new GameLib.D3.Renderer(
|
||||
if (this.camera instanceof GameLib.D3.API.Camera) {
|
||||
this.camera = new GameLib.D3.Camera(
|
||||
this.graphics,
|
||||
this.renderer
|
||||
this.camera
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -66,29 +66,17 @@ GameLib.D3.Controls.Editor.prototype.delayedInstance = function() {
|
|||
|
||||
console.log('GameLib.D3.Controls.Editor.delayedInstance() called');
|
||||
|
||||
if (!this.renderer) {
|
||||
throw new Error('No renderer at time of creating instance');
|
||||
}
|
||||
|
||||
if (!this.renderer.camera) {
|
||||
if (!this.camera || !this.camera.instance) {
|
||||
throw new Error('No camera at time of instance');
|
||||
}
|
||||
|
||||
if (!this.renderer.domElement) {
|
||||
if (!this.domElement || !this.domElement.instance) {
|
||||
throw new Error('No dom element at time of instance');
|
||||
}
|
||||
|
||||
if (!this.renderer.camera.instance) {
|
||||
throw new Error('No camera instance at time of instance');
|
||||
}
|
||||
|
||||
if (!this.renderer.domElement.instance) {
|
||||
throw new Error('No dom element instance at time of instance');
|
||||
}
|
||||
|
||||
var instance = new THREE.EditorControls(
|
||||
this.renderer.camera.instance,
|
||||
this.renderer.domElement.instance
|
||||
this.camera.instance,
|
||||
this.domElement.instance
|
||||
);
|
||||
|
||||
return instance;
|
||||
|
@ -119,8 +107,8 @@ GameLib.D3.Controls.Editor.prototype.toApiObject = function() {
|
|||
|
||||
var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this);
|
||||
|
||||
apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster);
|
||||
apiControls.renderer = GameLib.Utils.IdOrNull(this.renderer);
|
||||
apiControls.raycaster = GameLib.Utils.IdOrNull(this.raycaster);
|
||||
apiControls.camera = GameLib.Utils.IdOrNull(this.camera);
|
||||
|
||||
return apiControls;
|
||||
};
|
||||
|
@ -136,12 +124,11 @@ GameLib.D3.Controls.Editor.FromObject = function(graphics, objectControls) {
|
|||
|
||||
var apiControls = GameLib.D3.API.Controls.FromObject(objectControls);
|
||||
|
||||
apiControls.renderer = objectControls.renderer;
|
||||
apiControls.raycaster = objectControls.raycaster;
|
||||
|
||||
return new GameLib.D3.Controls.Editor(
|
||||
graphics,
|
||||
apiControls
|
||||
apiControls,
|
||||
apiControls.raycaster,
|
||||
apiControls.camera
|
||||
);
|
||||
|
||||
};
|
|
@ -0,0 +1,93 @@
|
|||
/**
|
||||
* Font Superset - The apiFont properties get moved into the Font object itself, and then the instance is created
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiFont GameLib.D3.API.Font
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Font = function(
|
||||
graphics,
|
||||
apiFont
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiFont)) {
|
||||
apiFont = {};
|
||||
}
|
||||
|
||||
if (apiFont instanceof GameLib.D3.Font) {
|
||||
return apiFont;
|
||||
}
|
||||
|
||||
GameLib.D3.API.Font.call(
|
||||
this,
|
||||
apiFont.id,
|
||||
apiFont.name,
|
||||
apiFont.url,
|
||||
apiFont.parentEntity
|
||||
);
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_FONT
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Font.prototype = Object.create(GameLib.D3.API.Font.prototype);
|
||||
GameLib.D3.Font.prototype.constructor = GameLib.D3.Font;
|
||||
|
||||
/**
|
||||
* Creates a light instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Font.prototype.createInstance = function() {
|
||||
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.LOAD_FONT,
|
||||
{
|
||||
font : this
|
||||
}
|
||||
);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
GameLib.D3.Font.prototype.updateInstance = function() {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.LOAD_FONT,
|
||||
{
|
||||
font : this
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Font to a GameLib.D3.API.Font
|
||||
* @returns {GameLib.D3.API.Font}
|
||||
*/
|
||||
GameLib.D3.Font.prototype.toApiObject = function() {
|
||||
return new GameLib.D3.API.Font(
|
||||
this.id,
|
||||
this.name,
|
||||
this.url,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a new GameLib.D3.Font from a GameLib.D3.API.Font
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param objectFont GameLib.D3.API.Font
|
||||
* @returns {GameLib.D3.Font}
|
||||
*/
|
||||
GameLib.D3.Font.FromObject = function(graphics, objectFont) {
|
||||
|
||||
return new GameLib.D3.Font(
|
||||
graphics,
|
||||
GameLib.D3.API.Font.FromObject(objectFont)
|
||||
);
|
||||
|
||||
};
|
|
@ -36,6 +36,7 @@ GameLib.D3.Light = function(
|
|||
apiLight.power,
|
||||
apiLight.angle,
|
||||
apiLight.penumbra,
|
||||
apiLight.parentScene,
|
||||
apiLight.parentEntity
|
||||
);
|
||||
|
||||
|
@ -295,6 +296,7 @@ GameLib.D3.Light.prototype.toApiObject = function() {
|
|||
this.power,
|
||||
this.angle,
|
||||
this.penumbra,
|
||||
GameLib.Utils.IdOrNull(this.parentScene),
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -339,6 +339,14 @@ GameLib.D3.Material.MATERIAL_TYPE_STANDARD = 0x8;
|
|||
GameLib.D3.Material.MATERIAL_TYPE_POINTS = 0x9;
|
||||
GameLib.D3.Material.MATERIAL_TYPE_SPRITE = 0xa;
|
||||
|
||||
GameLib.D3.Material.LINE_CAP_BUTT = 0x1;//'butt';
|
||||
GameLib.D3.Material.LINE_CAP_ROUND = 0x2;//'round';
|
||||
GameLib.D3.Material.LINE_CAP_SQUARE = 0x3;//'square';
|
||||
|
||||
GameLib.D3.Material.LINE_JOIN_ROUND = 0x1;//'round';
|
||||
GameLib.D3.Material.LINE_JOIN_BEVEL = 0x2;//'bevel';
|
||||
GameLib.D3.Material.LINE_JOIN_MITER = 0x3;//'miter';
|
||||
|
||||
GameLib.D3.Material.prototype.createStandardMaterialInstance = function() {
|
||||
return new THREE.MeshStandardMaterial({
|
||||
name: this.name,
|
||||
|
@ -413,6 +421,57 @@ GameLib.D3.Material.prototype.createPointsMaterialInstance = function() {
|
|||
});
|
||||
};
|
||||
|
||||
GameLib.D3.Material.prototype.createLineBasicMaterialInstance = function() {
|
||||
|
||||
var linecap = 'round';
|
||||
|
||||
if (this.lineCap === GameLib.D3.Material.LINE_CAP_BUTT) {
|
||||
linecap = 'butt';
|
||||
}
|
||||
|
||||
if (this.lineCap === GameLib.D3.Material.LINE_CAP_SQUARE) {
|
||||
linecap = 'square';
|
||||
}
|
||||
|
||||
var linejoin = 'round';
|
||||
|
||||
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_BEVEL) {
|
||||
linejoin = 'bevel';
|
||||
}
|
||||
|
||||
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_MITER) {
|
||||
linejoin = 'miter';
|
||||
}
|
||||
|
||||
return new THREE.LineBasicMaterial({
|
||||
name: this.name,
|
||||
opacity: this.opacity,
|
||||
transparent: this.transparent,
|
||||
// blending: this.blending,
|
||||
// blendSrc: this.blendSrc,
|
||||
// blendDst: this.blendDst,
|
||||
// blendEquation: this.blendEquation,
|
||||
depthTest: this.depthTest,
|
||||
depthFunc: this.depthFunc,
|
||||
depthWrite: this.depthWrite,
|
||||
// polygonOffset: this.polygonOffset,
|
||||
// polygonOffsetFactor: this.polygonOffsetFactor,
|
||||
// polygonOffsetUnits: this.polygonOffsetUnits,
|
||||
// alphaTest: this.alphaTest,
|
||||
// clippingPlanes: this.clippingPlanes,
|
||||
// clipShadows: this.clipShadows,
|
||||
// overdraw: this.overdraw,
|
||||
visible: this.visible,
|
||||
side: this.side,
|
||||
color: this.color.instance,
|
||||
linewidth: this.lineWidth,
|
||||
linecap: linecap,
|
||||
linejoin: linejoin
|
||||
// vertexColors: GameLib.D3.Material.TYPE_VERTEX_COLORS,
|
||||
// fog: this.fog
|
||||
});
|
||||
};
|
||||
|
||||
GameLib.D3.Material.prototype.createPhongMaterialInstance = function() {
|
||||
return new THREE.MeshPhongMaterial({
|
||||
name: this.name,
|
||||
|
@ -644,6 +703,58 @@ GameLib.D3.Material.prototype.updatePointsMaterialInstance = function() {
|
|||
//this.instance.fog = this.fog;
|
||||
};
|
||||
|
||||
GameLib.D3.Material.prototype.updateLineBasicMaterialInstance = function() {
|
||||
|
||||
var linecap = 'round';
|
||||
|
||||
if (this.lineCap === GameLib.D3.Material.LINE_CAP_BUTT) {
|
||||
linecap = 'butt';
|
||||
}
|
||||
|
||||
if (this.lineCap === GameLib.D3.Material.LINE_CAP_SQUARE) {
|
||||
linecap = 'square';
|
||||
}
|
||||
|
||||
var linejoin = 'round';
|
||||
|
||||
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_BEVEL) {
|
||||
linejoin = 'bevel';
|
||||
}
|
||||
|
||||
if (this.lineJoin === GameLib.D3.Material.LINE_JOIN_MITER) {
|
||||
linejoin = 'miter';
|
||||
}
|
||||
|
||||
this.instance.name = this.name;
|
||||
this.instance.opacity = this.opacity;
|
||||
this.instance.transparent = this.transparent;
|
||||
// this.instance.blending = this.blending;
|
||||
// this.instance.blendSrc = this.blendSrc;
|
||||
// this.instance.blendDst = this.blendDst;
|
||||
// this.instance.blendEquation = this.blendEquation;
|
||||
// this.instance.depthTest = this.depthTest;
|
||||
this.instance.depthFunc = this.depthFunc;
|
||||
this.instance.depthWrite = this.depthWrite;
|
||||
// this.instance.polygonOffset = this.polygonOffset;
|
||||
// this.instance.polygonOffsetFactor = this.polygonOffsetFactor;
|
||||
// this.instance.polygonOffsetUnits = this.polygonOffsetUnits;
|
||||
// this.instance.alphaTest = this.alphaTest;
|
||||
// this.instance.clippingPlanes = this.clippingPlanes;
|
||||
// this.instance.clipShadows = this.clipShadows;
|
||||
// this.instance.overdraw = this.overdraw;
|
||||
this.instance.visible = this.visible;
|
||||
this.instance.side = this.side;
|
||||
this.instance.color = this.color.instance;
|
||||
|
||||
this.instance.linewidth = this.lineWidth;
|
||||
this.instance.linecap = linecap;
|
||||
this.instance.linejoin = linejoin;
|
||||
|
||||
//this.instance.vertexColors = GameLib.D3.Material.TYPE_VERTEX_COLORS;
|
||||
//this.instance.fog = this.fog;
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Material.prototype.updatePhongMaterialInstance = function() {
|
||||
this.instance.name = this.name;
|
||||
this.instance.opacity = this.opacity;
|
||||
|
@ -740,6 +851,10 @@ GameLib.D3.Material.prototype.createInstance = function() {
|
|||
|
||||
instance = this.createMeshBasicMaterialInstance();
|
||||
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC) {
|
||||
|
||||
instance = this.createLineBasicMaterialInstance();
|
||||
|
||||
} else {
|
||||
console.warn("material type is not implemented yet: " + this.materialType);
|
||||
}
|
||||
|
@ -761,7 +876,7 @@ GameLib.D3.Material.prototype.updateInstance = function() {
|
|||
// console.log('material update instance');
|
||||
|
||||
if (!this.instance) {
|
||||
console.warn('Attempt to update a non-existent instance');
|
||||
//console.warn('Attempt to update a non-existent instance');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -795,6 +910,13 @@ GameLib.D3.Material.prototype.updateInstance = function() {
|
|||
} else {
|
||||
this.updateMeshBasicMaterialInstance();
|
||||
}
|
||||
} else if (this.materialType === GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC) {
|
||||
if (!(this.instance instanceof THREE.LineBasicMaterial)) {
|
||||
this.instance = this.createLineBasicMaterialInstance();
|
||||
typeChange = true;
|
||||
} else {
|
||||
this.updateLineBasicMaterialInstance();
|
||||
}
|
||||
} else {
|
||||
console.warn('not yet implemented (material type = ' + this.materialType + ')');
|
||||
}
|
||||
|
|
|
@ -122,12 +122,19 @@ GameLib.D3.Mesh = function (
|
|||
this
|
||||
);
|
||||
|
||||
this.size = new GameLib.Vector3(
|
||||
this.dimensions = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
new GameLib.API.Vector3(),
|
||||
this
|
||||
);
|
||||
|
||||
var linkedObjects = {
|
||||
'parentMesh' : GameLib.D3.Mesh,
|
||||
'parentScene' : GameLib.D3.Scene,
|
||||
'materials' : [GameLib.D3.Material],
|
||||
'skeleton' : GameLib.D3.Skeleton
|
||||
};
|
||||
|
||||
var componentType = GameLib.Component.COMPONENT_MESH;
|
||||
|
||||
if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_PLANE) {
|
||||
|
@ -138,6 +145,11 @@ GameLib.D3.Mesh = function (
|
|||
componentType = GameLib.Component.COMPONENT_MESH_SPHERE
|
||||
}
|
||||
|
||||
if (this.meshType === GameLib.D3.Mesh.MESH_TYPE_TEXT) {
|
||||
componentType = GameLib.Component.COMPONENT_MESH_TEXT;
|
||||
linkedObjects.font = GameLib.D3.Font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime meshes have helpers too
|
||||
* @type {null}
|
||||
|
@ -149,12 +161,7 @@ GameLib.D3.Mesh = function (
|
|||
GameLib.Component.call(
|
||||
this,
|
||||
componentType,
|
||||
{
|
||||
'parentMesh' : GameLib.D3.Mesh,
|
||||
'parentScene' : GameLib.D3.Scene,
|
||||
'materials' : [GameLib.D3.Material],
|
||||
'skeleton' : GameLib.D3.Skeleton
|
||||
}
|
||||
linkedObjects
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -172,6 +179,7 @@ GameLib.D3.Mesh.MESH_TYPE_SPHERE = 0x3;
|
|||
GameLib.D3.Mesh.MESH_TYPE_PLANE = 0x4;
|
||||
GameLib.D3.Mesh.MESH_TYPE_BOX = 0x5;
|
||||
GameLib.D3.Mesh.MESH_TYPE_CYLINDER = 0x6;
|
||||
GameLib.D3.Mesh.MESH_TYPE_TEXT = 0x7;
|
||||
|
||||
GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) {
|
||||
|
||||
|
@ -1353,7 +1361,11 @@ GameLib.D3.Mesh.prototype.addMaterial = function(material) {
|
|||
if (this.materials.length === 1) {
|
||||
this.instance.material = material.instance;
|
||||
} else {
|
||||
this.instance.material.push(material.instance);
|
||||
this.instance.material = this.materials.map(
|
||||
function(material) {
|
||||
return material.instance;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1397,7 +1409,7 @@ GameLib.D3.Mesh.prototype.computeBoundingBox = function(geometry) {
|
|||
}
|
||||
|
||||
geometry.computeBoundingBox();
|
||||
this.size.x = geometry.boundingBox.getSize().x;
|
||||
this.size.y = geometry.boundingBox.getSize().y;
|
||||
this.size.z = geometry.boundingBox.getSize().z;
|
||||
this.dimensions.x = geometry.boundingBox.getSize().x;
|
||||
this.dimensions.y = geometry.boundingBox.getSize().y;
|
||||
this.dimensions.z = geometry.boundingBox.getSize().z;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,219 @@
|
|||
/**
|
||||
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiMesh GameLib.D3.API.Mesh
|
||||
* @param font
|
||||
* @param size
|
||||
* @param height
|
||||
* @param curveSegments
|
||||
* @param bevelEnabled
|
||||
* @param bevelThickness
|
||||
* @param bevelSize
|
||||
* @param bevelSegments
|
||||
* @param text
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Mesh.Text = function (
|
||||
graphics,
|
||||
apiMesh,
|
||||
text,
|
||||
font,
|
||||
size,
|
||||
height,
|
||||
curveSegments,
|
||||
bevelEnabled,
|
||||
bevelThickness,
|
||||
bevelSize,
|
||||
bevelSegments
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(text)) {
|
||||
text = '-=<yb4f310';
|
||||
}
|
||||
this.text = text;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(font)) {
|
||||
font = new GameLib.D3.Font(
|
||||
this.graphics
|
||||
);
|
||||
}
|
||||
this.font = font;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(size)) {
|
||||
size = 100;
|
||||
}
|
||||
this.size = size;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||
height = 50;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(curveSegments)) {
|
||||
curveSegments = 12;
|
||||
}
|
||||
this.curveSegments = curveSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bevelEnabled)) {
|
||||
bevelEnabled = false;
|
||||
}
|
||||
this.bevelEnabled = bevelEnabled;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bevelThickness)) {
|
||||
bevelThickness = 10;
|
||||
}
|
||||
this.bevelThickness = bevelThickness;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bevelSize)) {
|
||||
bevelSize = 8;
|
||||
}
|
||||
this.bevelSize = bevelSize;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(bevelSegments)) {
|
||||
bevelSegments = 3;
|
||||
}
|
||||
this.bevelSegments = bevelSegments;
|
||||
|
||||
GameLib.D3.Mesh.call(
|
||||
this,
|
||||
this.graphics,
|
||||
apiMesh
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.Text.prototype = Object.create(GameLib.D3.Mesh.prototype);
|
||||
GameLib.D3.Mesh.Text.prototype.constructor = GameLib.D3.Mesh.Text;
|
||||
|
||||
GameLib.D3.Mesh.Text.prototype.createInstance = function() {
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (this.vertices.length === 0) {
|
||||
|
||||
geometry = new THREE.TextGeometry(
|
||||
this.text,
|
||||
{
|
||||
font: this.font.instance,
|
||||
size: this.size,
|
||||
height: this.height,
|
||||
curveSegments: this.curveSegments,
|
||||
bevelEnabled: this.bevelEnabled,
|
||||
bevelThickness: this.bevelThickness,
|
||||
bevelSize: this.bevelSize,
|
||||
bevelSegments: this.bevelSegments
|
||||
}
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
var instance = GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
instance.userData.font = this.font;
|
||||
instance.userData.size = this.size;
|
||||
instance.userData.height = this.height;
|
||||
instance.userData.curveSegments = this.curveSegments;
|
||||
instance.userData.bevelEnabled = this.bevelEnabled;
|
||||
instance.userData.bevelThickness = this.bevelThickness;
|
||||
instance.userData.bevelSize = this.bevelSize;
|
||||
instance.userData.bevelSegments = this.bevelSegments;
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.Text.prototype.updateInstance = function() {
|
||||
|
||||
if (
|
||||
this.instance.userData.text !== this.text ||
|
||||
this.instance.userData.font !== this.font ||
|
||||
this.instance.userData.size !== this.size ||
|
||||
this.instance.userData.height !== this.height ||
|
||||
this.instance.userData.curveSegments !== this.curveSegments ||
|
||||
this.instance.userData.bevelEnabled !== this.bevelEnabled ||
|
||||
this.instance.userData.bevelThickness !== this.bevelThickness ||
|
||||
this.instance.userData.bevelSize !== this.bevelSize ||
|
||||
this.instance.userData.bevelSegments !== this.bevelSegments
|
||||
) {
|
||||
this.instance.userData.text = this.text;
|
||||
this.instance.userData.font = this.font;
|
||||
this.instance.userData.size = this.size;
|
||||
this.instance.userData.height = this.height;
|
||||
this.instance.userData.curveSegments = this.curveSegments;
|
||||
this.instance.userData.bevelEnabled = this.bevelEnabled;
|
||||
this.instance.userData.bevelThickness = this.bevelThickness;
|
||||
this.instance.userData.bevelSize = this.bevelSize;
|
||||
this.instance.userData.bevelSegments = this.bevelSegments;
|
||||
|
||||
var geometry = new THREE.TextGeometry(
|
||||
this.text,
|
||||
{
|
||||
font: this.font.instance,
|
||||
size: this.size,
|
||||
height: this.height,
|
||||
curveSegments: this.curveSegments,
|
||||
bevelEnabled: this.bevelEnabled,
|
||||
bevelThickness: this.bevelThickness,
|
||||
bevelSize: this.bevelSize,
|
||||
bevelSegments: this.bevelSegments
|
||||
}
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
geometry = this.createInstanceGeometry();
|
||||
|
||||
this.instance.geometry = geometry;
|
||||
}
|
||||
|
||||
GameLib.D3.Mesh.prototype.updateInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
|
||||
* @returns {GameLib.D3.API.Mesh}
|
||||
*/
|
||||
GameLib.D3.Mesh.Text.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
apiMesh.text = this.text;
|
||||
apiMesh.font = GameLib.Utils.IdOrNull(this.font);
|
||||
apiMesh.size = this.size;
|
||||
apiMesh.height = this.height;
|
||||
apiMesh.curveSegments = this.curveSegments;
|
||||
apiMesh.bevelEnabled = this.bevelEnabled;
|
||||
apiMesh.bevelThickness = this.bevelThickness;
|
||||
apiMesh.bevelSize = this.bevelSize;
|
||||
apiMesh.bevelSegments = this.bevelSegments;
|
||||
|
||||
return apiMesh;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a standard object mesh to a GameLib.D3.Mesh
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param objectMesh {Object}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Mesh.Text.FromObject = function(graphics, objectMesh) {
|
||||
|
||||
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);
|
||||
|
||||
return new GameLib.D3.Mesh.Text(
|
||||
graphics,
|
||||
apiMesh,
|
||||
objectMesh.text,
|
||||
objectMesh.font,
|
||||
objectMesh.size,
|
||||
objectMesh.height,
|
||||
objectMesh.curveSegments,
|
||||
objectMesh.bevelEnabled,
|
||||
objectMesh.bevelThickness,
|
||||
objectMesh.bevelSize,
|
||||
objectMesh.bevelSegments
|
||||
);
|
||||
|
||||
};
|
|
@ -108,10 +108,6 @@ GameLib.D3.Renderer = function (
|
|||
}
|
||||
this.statistics = statistics;
|
||||
|
||||
this.mouse = new GameLib.Mouse(
|
||||
this.graphics
|
||||
);
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.Component.COMPONENT_RENDERER,
|
||||
|
|
|
@ -22,19 +22,14 @@ GameLib.D3.Scene = function (
|
|||
|
||||
GameLib.D3.API.Scene.call(
|
||||
this,
|
||||
apiScene.id,
|
||||
apiScene.name,
|
||||
apiScene.id,
|
||||
apiScene.name,
|
||||
apiScene.meshes,
|
||||
apiScene.position,
|
||||
apiScene.quaternion,
|
||||
apiScene.scale,
|
||||
apiScene.parentGameId,
|
||||
apiScene.lights,
|
||||
apiScene.textures,
|
||||
apiScene.materials,
|
||||
apiScene.images,
|
||||
apiScene.activeCamera,
|
||||
apiScene.parentEntity
|
||||
apiScene.materials,
|
||||
apiScene.images,
|
||||
apiScene.parentEntity
|
||||
);
|
||||
|
||||
this.meshes = this.meshes.map(
|
||||
|
@ -56,24 +51,6 @@ GameLib.D3.Scene = function (
|
|||
}.bind(this)
|
||||
);
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.scale = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.scale,
|
||||
this
|
||||
);
|
||||
|
||||
this.lights = this.lights.map(
|
||||
function(apiLight) {
|
||||
|
||||
|
@ -146,13 +123,6 @@ GameLib.D3.Scene = function (
|
|||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.activeCamera instanceof GameLib.D3.API.Camera) {
|
||||
this.activeCamera = new GameLib.D3.Camera(
|
||||
this.graphics,
|
||||
this.activeCamera
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime scenes have helpers (just used to store which helper belongs to which scene)
|
||||
* @type {Array}
|
||||
|
@ -167,8 +137,7 @@ GameLib.D3.Scene = function (
|
|||
'lights' : [GameLib.D3.Light],
|
||||
'textures' : [GameLib.D3.Texture],
|
||||
'materials' : [GameLib.D3.Material],
|
||||
'images' : [GameLib.D3.Image],
|
||||
'activeCamera' : GameLib.D3.Camera
|
||||
'images' : [GameLib.D3.Image]
|
||||
}
|
||||
);
|
||||
};
|
||||
|
@ -186,15 +155,82 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
|||
|
||||
instance.name = this.name;
|
||||
|
||||
instance.position = this.position.instance;
|
||||
this.meshes.map(
|
||||
function(mesh) {
|
||||
instance.add(mesh.instance);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
instance.scale = this.scale.instance;
|
||||
|
||||
instance.quaternion = this.quaternion.instance;
|
||||
this.lights.map(
|
||||
function(light) {
|
||||
instance.add(light.instance);
|
||||
}
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
GameLib.D3.Scene.prototype.updateInstance = function() {
|
||||
|
||||
this.instance.name = this.name;
|
||||
|
||||
/**
|
||||
* Add missing meshes
|
||||
*/
|
||||
this.meshes.map(
|
||||
function(mesh) {
|
||||
if (this.instance.children.indexOf(mesh.instance === -1)) {
|
||||
this.instance.add(mesh.instance);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
/**
|
||||
* Add missing lights
|
||||
*/
|
||||
this.lights.map(
|
||||
function(light) {
|
||||
if (this.instance.children.indexOf(light.instance) === -1) {
|
||||
this.instance.add(light.instance);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
/**
|
||||
* Remove extra meshes and lights
|
||||
*/
|
||||
this.instance.children.map(
|
||||
function(instanceObject) {
|
||||
|
||||
var instanceMeshes = this.meshes.map(
|
||||
function(mesh) {
|
||||
return mesh.instance;
|
||||
}
|
||||
);
|
||||
|
||||
var instanceLights = this.lights.map(
|
||||
function(light) {
|
||||
return light.instance;
|
||||
}
|
||||
);
|
||||
|
||||
if (
|
||||
(
|
||||
instanceObject instanceof THREE.Mesh ||
|
||||
instanceObject instanceof THREE.Light
|
||||
) &&
|
||||
(
|
||||
instanceLights.indexOf(instanceObject) === -1 &&
|
||||
instanceMeshes.indexOf(instanceObject) === -1
|
||||
)
|
||||
) {
|
||||
this.instance.remove(instanceObject);
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
)
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Scene to a GameLib.D3.API.Scene
|
||||
* @returns {GameLib.D3.API.Scene}
|
||||
|
@ -203,25 +239,31 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
|
|||
|
||||
var apiMeshes = this.meshes.map(
|
||||
function(mesh) {
|
||||
return mesh.id;
|
||||
return GameLib.Utils.IdOrNull(mesh);
|
||||
}
|
||||
);
|
||||
|
||||
var apiLights = this.lights.map(
|
||||
function(light) {
|
||||
return light.id;
|
||||
return GameLib.Utils.IdOrNull(light);
|
||||
}
|
||||
);
|
||||
|
||||
var apiTextures = this.textures.map(
|
||||
function(texture) {
|
||||
return texture.id;
|
||||
return GameLib.Utils.IdOrNull(texture);
|
||||
}
|
||||
);
|
||||
|
||||
var apiMaterials = this.materials.map(
|
||||
function(material) {
|
||||
return material.id;
|
||||
return GameLib.Utils.IdOrNull(material);
|
||||
}
|
||||
);
|
||||
|
||||
var apiImages = this.images.map(
|
||||
function(image) {
|
||||
return GameLib.Utils.IdOrNull(image);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -229,14 +271,10 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
|
|||
this.id,
|
||||
this.name,
|
||||
apiMeshes,
|
||||
this.position.toApiObject(),
|
||||
this.quaternion.toApiObject(),
|
||||
this.scale.toApiObject(),
|
||||
this.parentGameId,
|
||||
apiLights,
|
||||
apiTextures,
|
||||
apiMaterials,
|
||||
GameLib.Utils.IdOrNull(this.activeCamera),
|
||||
apiImages,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -77,9 +77,9 @@ GameLib.D3.Shape.ConvexHull.Cylinder.prototype.updateInstance = function() {
|
|||
};
|
||||
|
||||
GameLib.D3.Shape.ConvexHull.Cylinder.prototype.setFromMesh = function() {
|
||||
this.radiusTop = this.parentMesh.size.x / 2;
|
||||
this.radiusBottom = this.parentMesh.size.x / 2;
|
||||
this.height = this.parentMesh.size.z;
|
||||
this.radiusTop = this.parentMesh.dimensions.x / 2;
|
||||
this.radiusBottom = this.parentMesh.dimensions.x / 2;
|
||||
this.height = this.parentMesh.dimensions.z;
|
||||
};
|
||||
|
||||
GameLib.D3.Shape.ConvexHull.Cylinder.prototype.toApiObject = function() {
|
||||
|
|
|
@ -383,6 +383,10 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp
|
|||
constructor = GameLib.D3.PhysicsWorld;
|
||||
}
|
||||
|
||||
if (property === 'parentScene') {
|
||||
constructor = GameLib.D3.Scene;
|
||||
}
|
||||
|
||||
var options = GameLib.EntityManager.Instance.queryComponents(constructor).reduce(
|
||||
function(result, object) {
|
||||
result[object.name] = object;
|
||||
|
@ -434,6 +438,16 @@ GameLib.System.GUI.prototype.buildParentSelectionControl = function(folder, comp
|
|||
)
|
||||
}
|
||||
|
||||
if (property === 'parentScene') {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.PARENT_SCENE_CHANGE,
|
||||
{
|
||||
originalScene: this.initialValue,
|
||||
newScene: newComponent,
|
||||
object: component
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
@ -557,10 +571,12 @@ GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTempl
|
|||
|
||||
var object = componentTemplate.template;
|
||||
|
||||
var tempObject = {
|
||||
hexColor : object[property].toHex()
|
||||
};
|
||||
|
||||
folder.addColor(
|
||||
{
|
||||
hexColor : object[property].toHex()
|
||||
},
|
||||
tempObject,
|
||||
'hexColor'
|
||||
).name(property).listen().onChange(
|
||||
function(value) {
|
||||
|
@ -573,6 +589,20 @@ GameLib.System.GUI.prototype.buildColorControl = function(folder, componentTempl
|
|||
}
|
||||
);
|
||||
|
||||
folder.add(
|
||||
tempObject,
|
||||
'hexColor'
|
||||
).name(property).listen().onChange(
|
||||
function(value) {
|
||||
componentTemplate.affected.map(
|
||||
function(component) {
|
||||
component[property].fromHex(value);
|
||||
component[property].updateInstance();
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemplate, property) {
|
||||
|
@ -617,8 +647,6 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp
|
|||
|
||||
var newComponent = null;
|
||||
|
||||
var originalComponent = this.initialValue;
|
||||
|
||||
if (value !== 'null') {
|
||||
newComponent = idToObject[value];
|
||||
}
|
||||
|
@ -627,28 +655,6 @@ GameLib.System.GUI.prototype.buildSelectControl = function(folder, componentTemp
|
|||
function(component) {
|
||||
component[property] = newComponent;
|
||||
component.updateInstance();
|
||||
|
||||
if (property === 'parentScene') {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.PARENT_SCENE_CHANGE,
|
||||
{
|
||||
originalScene: originalComponent,
|
||||
newScene: newComponent,
|
||||
object: component
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (property === 'parentWorld') {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.PARENT_WORLD_CHANGE,
|
||||
{
|
||||
originalWorld : originalComponent,
|
||||
newWorld : newComponent,
|
||||
object : component
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -743,7 +749,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
'plane' : GameLib.D3.Mesh.MESH_TYPE_PLANE,
|
||||
'sphere' : GameLib.D3.Mesh.MESH_TYPE_SPHERE,
|
||||
'box' : GameLib.D3.Mesh.MESH_TYPE_BOX,
|
||||
'cylinder' : GameLib.D3.Mesh.MESH_TYPE_CYLINDER
|
||||
'cylinder' : GameLib.D3.Mesh.MESH_TYPE_CYLINDER,
|
||||
'text' : GameLib.D3.Mesh.MESH_TYPE_TEXT
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -767,7 +774,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
'standard': GameLib.D3.Material.MATERIAL_TYPE_STANDARD,
|
||||
'basic': GameLib.D3.Material.MATERIAL_TYPE_BASIC,
|
||||
'phong': GameLib.D3.Material.MATERIAL_TYPE_PHONG,
|
||||
'points': GameLib.D3.Material.MATERIAL_TYPE_POINTS
|
||||
'points': GameLib.D3.Material.MATERIAL_TYPE_POINTS,
|
||||
'line basic' : GameLib.D3.Material.MATERIAL_TYPE_LINE_BASIC
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -1084,14 +1092,18 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
controllers.push(folder.add(object, property, -255, 255, 1));
|
||||
} else if (
|
||||
property === 'aspect' ||
|
||||
property === 'wireframeLineWidth'
|
||||
property === 'wireframeLineWidth' ||
|
||||
property === 'lineWidth'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, 0, 5, 0.001));
|
||||
} else if (
|
||||
property === 'bumpScale' ||
|
||||
property === 'normalScale' ||
|
||||
property === 'displacementScale' ||
|
||||
property === 'heightMapScale' ||
|
||||
property === 'intensity'
|
||||
) {
|
||||
controllers.push(folder.add(object, property, 0, 10, 0.001));
|
||||
controllers.push(folder.add(object, property, -10, 10, 0.001));
|
||||
} else if (
|
||||
property === 'minX' ||
|
||||
property === 'minY' ||
|
||||
|
@ -1596,7 +1608,8 @@ GameLib.System.GUI.prototype.buildGUI = function(data) {
|
|||
if (
|
||||
templateProperty === 'parentEntity' ||
|
||||
templateProperty === 'parentWorld' ||
|
||||
templateProperty === 'parentMesh'
|
||||
templateProperty === 'parentMesh' ||
|
||||
templateProperty === 'parentScene'
|
||||
) {
|
||||
this.buildParentSelectionControl(folder, componentTemplate, templateProperty);
|
||||
continue;
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/**
|
||||
* System takes care of updating all the entities (based on their component data)
|
||||
* @param apiSystem GameLib.API.System
|
||||
* @param graphics
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.System.Input = function(
|
||||
apiSystem
|
||||
apiSystem,
|
||||
graphics
|
||||
) {
|
||||
GameLib.System.call(
|
||||
this,
|
||||
apiSystem
|
||||
);
|
||||
|
||||
// this.meshMoveMode = false;
|
||||
// this.meshMoveXMode = false;
|
||||
// this.meshMoveYMode = false;
|
||||
// this.meshMoveZMode = false;
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
/**
|
||||
* We need new function pointers with scope bound to this so we can remove the
|
||||
|
@ -39,14 +39,25 @@ GameLib.System.Input = function(
|
|||
this.keyboardControls = [];
|
||||
this.mouseControls = [];
|
||||
|
||||
this.touchStart = this.onTouchStart.bind(this);
|
||||
this.touchMove = this.onTouchMove.bind(this);
|
||||
this.touchEnd = this.onTouchEnd.bind(this);
|
||||
this.touchCancel = this.onTouchCancel.bind(this);
|
||||
this.touchStart = this.onTouchStart.bind(this);
|
||||
this.touchMove = this.onTouchMove.bind(this);
|
||||
this.touchEnd = this.onTouchEnd.bind(this);
|
||||
this.touchCancel = this.onTouchCancel.bind(this);
|
||||
|
||||
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
|
||||
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
|
||||
this.keyboardKeyUp = this.onKeyboardKeyUp.bind(this);
|
||||
this.keyboardKeyDown = this.onKeyboardKeyDown.bind(this);
|
||||
|
||||
this.mouseDown = this.onMouseDown.bind(this);
|
||||
this.mouseMove = this.onMouseMove.bind(this);
|
||||
this.mouseWheel = this.onMouseWheel.bind(this);
|
||||
this.mouseUp = this.onMouseUp.bind(this);
|
||||
|
||||
this.keyDown = this.onKeyDown.bind(this);
|
||||
this.keyUp = this.onKeyUp.bind(this);
|
||||
|
||||
this.mouse = new GameLib.Mouse(
|
||||
graphics
|
||||
)
|
||||
};
|
||||
|
||||
GameLib.System.Input.prototype = Object.create(GameLib.System.prototype);
|
||||
|
@ -59,13 +70,13 @@ GameLib.System.Input.prototype.start = function() {
|
|||
|
||||
GameLib.System.prototype.start.call(this);
|
||||
|
||||
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor);
|
||||
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor);
|
||||
|
||||
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Touch);
|
||||
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Touch);
|
||||
|
||||
this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Keyboard);
|
||||
this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Keyboard);
|
||||
|
||||
this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse);
|
||||
this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse);
|
||||
|
||||
/**
|
||||
* If we have touch controls - inject them first so we can override editor controls if necessary
|
||||
|
@ -103,7 +114,6 @@ GameLib.System.Input.prototype.start = function() {
|
|||
this.touchCancel,
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,75 +138,47 @@ GameLib.System.Input.prototype.start = function() {
|
|||
}
|
||||
|
||||
if (this.editorControls.length > 0) {
|
||||
|
||||
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer);
|
||||
|
||||
this.renderers.map(
|
||||
|
||||
function(renderer) {
|
||||
|
||||
renderer.controls = this.editorControls.reduce(
|
||||
function(result, editorControl) {
|
||||
if (editorControl.renderer === renderer) {
|
||||
result = editorControl;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
renderer.mouseDown = this.onMouseDown(renderer, renderer.controls).bind(this);
|
||||
renderer.domElement.instance.addEventListener(
|
||||
this.editorControls.map(
|
||||
function(editorControl) {
|
||||
editorControl.domElement.instance.addEventListener(
|
||||
'mousedown',
|
||||
renderer.mouseDown,
|
||||
this.mouseDown,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.mouseMove = this.onMouseMove.bind(this);
|
||||
renderer.domElement.instance.addEventListener(
|
||||
editorControl.domElement.instance.addEventListener(
|
||||
'mousemove',
|
||||
renderer.mouseMove,
|
||||
this.mouseMove,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.keyDown = this.onKeyDown.bind(this);
|
||||
renderer.domElement.instance.addEventListener(
|
||||
editorControl.domElement.instance.addEventListener(
|
||||
'keydown',
|
||||
renderer.keyDown,
|
||||
this.keyDown,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.keyUp = this.onKeyUp.bind(this);
|
||||
renderer.domElement.instance.addEventListener(
|
||||
editorControl.domElement.instance.addEventListener(
|
||||
'keyup',
|
||||
renderer.keyUp,
|
||||
this.keyUp,
|
||||
false
|
||||
);
|
||||
|
||||
if (renderer.controls) {
|
||||
/**
|
||||
* Create the delayed instance here - it affects the order of event listeners attached to DOM
|
||||
*/
|
||||
renderer.controls.instance = renderer.controls.delayedInstance();
|
||||
} else {
|
||||
console.warn('no third party controls for renderer : ' + renderer.name);
|
||||
}
|
||||
editorControl.instance = editorControl.delayedInstance();
|
||||
|
||||
renderer.mouseWheel = this.onMouseWheel(renderer.camera).bind(this);
|
||||
renderer.domElement.instance.addEventListener(
|
||||
editorControl.domElement.instance.addEventListener(
|
||||
'mousewheel',
|
||||
renderer.mouseWheel,
|
||||
this.mouseWheel,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.mouseUp = this.onMouseUp(renderer.camera, renderer.controls).bind(this);
|
||||
renderer.domElement.instance.addEventListener(
|
||||
editorControl.domElement.instance.addEventListener(
|
||||
'mouseup',
|
||||
renderer.mouseUp,
|
||||
this.mouseUp,
|
||||
false
|
||||
);
|
||||
}.bind(this)
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -293,7 +275,7 @@ GameLib.System.Input.prototype.onTouchMove = function (event) {
|
|||
this.touches[id].pageX = event.changedTouches[t].pageX;
|
||||
this.touches[id].pageY = event.changedTouches[t].pageY;
|
||||
|
||||
console.log(this.touches[id]);
|
||||
//console.log(this.touches[id]);
|
||||
}
|
||||
|
||||
this.touches.event = event;
|
||||
|
@ -424,89 +406,92 @@ GameLib.System.Input.prototype.onKeyUp = function(event) {
|
|||
}
|
||||
};
|
||||
|
||||
GameLib.System.Input.prototype.onMouseDown = function(renderer, controls) {
|
||||
GameLib.System.Input.prototype.onMouseDown = function(event) {
|
||||
|
||||
return function(event) {
|
||||
if (event.button === 2) {
|
||||
|
||||
if (event.button === 2) {
|
||||
this.editorControls.map(
|
||||
|
||||
if (this.controlLeft) {
|
||||
return;
|
||||
}
|
||||
function(editorControl) {
|
||||
|
||||
renderer.mouse.x = (event.offsetX / renderer.instance.domElement.width) * 2 - 1;
|
||||
renderer.mouse.y = -(event.offsetY / renderer.instance.domElement.height) * 2 + 1;
|
||||
if (this.controlLeft) {
|
||||
return;
|
||||
}
|
||||
|
||||
var scenes = renderer.scenes;
|
||||
this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1;
|
||||
this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1;
|
||||
|
||||
var intersects = scenes.reduce(
|
||||
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene);
|
||||
|
||||
function(result, scene) {
|
||||
var intersects = scenes.reduce(
|
||||
|
||||
controls.raycaster.instance.setFromCamera(
|
||||
renderer.mouse,
|
||||
renderer.camera.instance
|
||||
);
|
||||
function (result, scene) {
|
||||
|
||||
intersects = controls.raycaster.getIntersectedObjects(scene.meshes);
|
||||
editorControl.raycaster.instance.setFromCamera(
|
||||
this.mouse,
|
||||
editorControl.camera.instance
|
||||
);
|
||||
|
||||
intersects.map(function(intersect){
|
||||
result.push(intersect);
|
||||
});
|
||||
intersects = editorControl.raycaster.getIntersectedObjects(scene.meshes);
|
||||
|
||||
return result;
|
||||
}.bind(this),
|
||||
[]
|
||||
);
|
||||
intersects.map(function (intersect) {
|
||||
result.push(intersect);
|
||||
});
|
||||
|
||||
intersects.sort(
|
||||
function(a, b) {
|
||||
if (a.distance < b.distance) {
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}.bind(this),
|
||||
[]
|
||||
);
|
||||
|
||||
if (a.distance > b.distance) {
|
||||
return 1;
|
||||
}
|
||||
intersects.sort(
|
||||
function (a, b) {
|
||||
if (a.distance < b.distance) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
if (a.distance > b.distance) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
var meshes = intersects.map(function(intersect){
|
||||
return intersect.mesh;
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
var mesh = meshes[0];
|
||||
var meshes = intersects.map(function (intersect) {
|
||||
return intersect.mesh;
|
||||
});
|
||||
|
||||
if (mesh) {
|
||||
var mesh = meshes[0];
|
||||
|
||||
/**
|
||||
* Prevent default action (like context menu or whatever)
|
||||
*/
|
||||
event.preventDefault();
|
||||
if (mesh) {
|
||||
|
||||
/**
|
||||
* Prevent other event listeners for 'mousedown' from executing their actions
|
||||
*/
|
||||
event.stopImmediatePropagation();
|
||||
/**
|
||||
* Prevent default action (like context menu or whatever)
|
||||
*/
|
||||
event.preventDefault();
|
||||
|
||||
if (mesh.selected) {
|
||||
this.deSelectMesh(mesh);
|
||||
} else {
|
||||
this.selectMesh(mesh);
|
||||
}
|
||||
/**
|
||||
* Prevent other event listeners for 'mousedown' from executing their actions
|
||||
*/
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
/**
|
||||
* Notify our GUI system to build a GUI
|
||||
*/
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.BUILD_GUI,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}.bind(this);
|
||||
if (mesh.selected) {
|
||||
this.deSelectMesh(mesh);
|
||||
} else {
|
||||
this.selectMesh(mesh);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify our GUI system to build a GUI
|
||||
*/
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.BUILD_GUI,
|
||||
null
|
||||
)
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -519,41 +504,42 @@ GameLib.System.Input.prototype.onMouseMove = function(event) {
|
|||
|
||||
/**
|
||||
* Update the camera position etc. after mouse up
|
||||
* @param __camera
|
||||
* @param __controls
|
||||
* @returns {Function}
|
||||
* @param event
|
||||
*/
|
||||
GameLib.System.Input.prototype.onMouseUp = function(__camera, __controls) {
|
||||
return function(event) {
|
||||
GameLib.System.Input.prototype.onMouseUp = function(event) {
|
||||
this.editorControls.map(
|
||||
function(editorControl) {
|
||||
editorControl.camera.position.x = editorControl.camera.instance.position.x;
|
||||
editorControl.camera.position.y = editorControl.camera.instance.position.y;
|
||||
editorControl.camera.position.z = editorControl.camera.instance.position.z;
|
||||
|
||||
__camera.position.x = __camera.instance.position.x;
|
||||
__camera.position.y = __camera.instance.position.y;
|
||||
__camera.position.z = __camera.instance.position.z;
|
||||
editorControl.camera.quaternion.x = editorControl.camera.instance.quaternion.x;
|
||||
editorControl.camera.quaternion.y = editorControl.camera.instance.quaternion.y;
|
||||
editorControl.camera.quaternion.z = editorControl.camera.instance.quaternion.z;
|
||||
editorControl.camera.quaternion.w = editorControl.camera.instance.quaternion.w;
|
||||
|
||||
__camera.quaternion.x = __camera.instance.quaternion.x;
|
||||
__camera.quaternion.y = __camera.instance.quaternion.y;
|
||||
__camera.quaternion.z = __camera.instance.quaternion.z;
|
||||
__camera.quaternion.w = __camera.instance.quaternion.w;
|
||||
|
||||
__camera.lookAt.x = __controls.instance.center.x;
|
||||
__camera.lookAt.y = __controls.instance.center.y;
|
||||
__camera.lookAt.z = __controls.instance.center.z;
|
||||
|
||||
__camera.lookAt.instance.copy(__controls.instance.center);
|
||||
};
|
||||
editorControl.camera.lookAt.x = editorControl.instance.center.x;
|
||||
editorControl.camera.lookAt.y = editorControl.instance.center.y;
|
||||
editorControl.camera.lookAt.z = editorControl.instance.center.z;
|
||||
editorControl.camera.lookAt.instance.copy(editorControl.instance.center);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update our camera position after moving the mouse wheel
|
||||
* @param __camera
|
||||
* @returns {Function}
|
||||
* @param event
|
||||
*/
|
||||
GameLib.System.Input.prototype.onMouseWheel = function(__camera) {
|
||||
return function(event) {
|
||||
__camera.position.x = __camera.instance.position.x;
|
||||
__camera.position.y = __camera.instance.position.y;
|
||||
__camera.position.z = __camera.instance.position.z;
|
||||
}
|
||||
GameLib.System.Input.prototype.onMouseWheel = function(event) {
|
||||
this.editorControls.map(
|
||||
function(editorControl) {
|
||||
editorControl.camera.position.x = editorControl.camera.instance.position.x;
|
||||
editorControl.camera.position.y = editorControl.camera.instance.position.y;
|
||||
editorControl.camera.position.z = editorControl.camera.instance.position.z;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.System.Input.prototype.selectMesh = function(mesh) {
|
||||
|
@ -606,56 +592,49 @@ GameLib.System.Input.prototype.stop = function() {
|
|||
/**
|
||||
* Now remove all input capabilities
|
||||
*/
|
||||
this.renderers.map(
|
||||
|
||||
function(renderer) {
|
||||
|
||||
renderer.domElement.instance.removeEventListener(
|
||||
this.editorControls.map(
|
||||
function(editorControl) {
|
||||
editorControl.domElement.instance.removeEventListener(
|
||||
'mousedown',
|
||||
renderer.mouseDown,
|
||||
this.mouseDown,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.domElement.instance.removeEventListener(
|
||||
editorControl.domElement.instance.removeEventListener(
|
||||
'mousemove',
|
||||
renderer.mouseMove,
|
||||
this.mouseMove,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.domElement.instance.removeEventListener(
|
||||
editorControl.domElement.instance.removeEventListener(
|
||||
'keydown',
|
||||
renderer.keyDown,
|
||||
this.keyDown,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.domElement.instance.removeEventListener(
|
||||
editorControl.domElement.instance.removeEventListener(
|
||||
'keyup',
|
||||
renderer.keyUp,
|
||||
this.keyUp,
|
||||
false
|
||||
);
|
||||
|
||||
if (renderer.controls && renderer.controls.instance) {
|
||||
renderer.controls.instance.dispose();
|
||||
} else {
|
||||
console.warn('no third party controls to stop for renderer : ' + renderer.name);
|
||||
}
|
||||
editorControl.instance.dispose();
|
||||
|
||||
renderer.domElement.instance.removeEventListener(
|
||||
editorControl.domElement.instance.removeEventListener(
|
||||
'mousewheel',
|
||||
renderer.mouseWheel,
|
||||
this.mouseWheel,
|
||||
false
|
||||
);
|
||||
|
||||
renderer.domElement.instance.removeEventListener(
|
||||
editorControl.domElement.instance.removeEventListener(
|
||||
'mouseup',
|
||||
renderer.mouseUp,
|
||||
this.mouseUp,
|
||||
false
|
||||
);
|
||||
}.bind(this)
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
if (this.touchControls.length > 0) {
|
||||
|
||||
this.touchControls.map(
|
||||
|
|
|
@ -33,6 +33,7 @@ GameLib.System.Linking = function(
|
|||
this.lightInstanceCreatedSubscription = null;
|
||||
this.sceneInstanceCreatedSubscription = null;
|
||||
this.imageInstanceCreatedSubscription = null;
|
||||
this.fontInstanceCreatedSubscription = null;
|
||||
this.textureInstanceCreatedSubscription = null;
|
||||
this.materialInstanceCreatedSubscription = null;
|
||||
this.meshDeletedSubscription = null;
|
||||
|
@ -42,6 +43,7 @@ GameLib.System.Linking = function(
|
|||
this.instanceCreatedSubscription = null;
|
||||
this.shapeInstanceCreatedSubscription = null;
|
||||
this.solverInstanceCreatedSubscription = null;
|
||||
this.registerDependenciesSubscription = null;
|
||||
|
||||
};
|
||||
|
||||
|
@ -92,6 +94,11 @@ GameLib.System.Linking.prototype.start = function() {
|
|||
this.imageInstanceCreated
|
||||
);
|
||||
|
||||
this.fontInstanceCreatedSubscription = this.subscribe(
|
||||
GameLib.Event.FONT_INSTANCE_CREATED,
|
||||
this.fontInstanceCreated
|
||||
);
|
||||
|
||||
this.textureInstanceCreatedSubscription = this.subscribe(
|
||||
GameLib.Event.TEXTURE_INSTANCE_CREATED,
|
||||
this.textureInstanceCreated
|
||||
|
@ -152,6 +159,15 @@ GameLib.System.Linking.prototype.start = function() {
|
|||
this.instanceCreated
|
||||
);
|
||||
|
||||
this.registerDependenciesSubscription = this.subscribe(
|
||||
GameLib.Event.REGISTER_DEPENDENCIES,
|
||||
this.registerDependenciesDirect
|
||||
)
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.registerDependenciesDirect = function(data) {
|
||||
this.registerDependencies(data.component);
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.link = function(component, data) {
|
||||
|
@ -560,8 +576,8 @@ GameLib.System.Linking.prototype.meshInstanceCreated = function(data) {
|
|||
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Scene);
|
||||
|
||||
scenes.map(function(scene){
|
||||
if (data.mesh.parentScene === scene) {
|
||||
scene.addObject(data.mesh);
|
||||
if (data.mesh.parentScene === scene.id) {
|
||||
data.mesh.parentScene = scene;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -627,6 +643,8 @@ GameLib.System.Linking.prototype.lightInstanceCreated = function(data) {
|
|||
scenes.map(function(scene){
|
||||
if (data.light.parentScene === scene) {
|
||||
scene.addObject(data.light);
|
||||
|
||||
//scene.updateInstance();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -642,12 +660,21 @@ GameLib.System.Linking.prototype.sceneInstanceCreated = function(data) {
|
|||
var objects = GameLib.EntityManager.Instance.queryComponents([GameLib.D3.Mesh,GameLib.D3.Light]);
|
||||
objects.map(function(object){
|
||||
if (
|
||||
object.parentScene === data.scene
|
||||
object.parentScene === data.scene.id
|
||||
) {
|
||||
data.scene.addObject(object);
|
||||
object.parentScene = data.scene;
|
||||
}
|
||||
});
|
||||
|
||||
//data.scene.updateInstance();
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.fontInstanceCreated = function(data) {
|
||||
/**
|
||||
* We resolve the dependencies
|
||||
*/
|
||||
this.resolveDependencies(data.font);
|
||||
};
|
||||
|
||||
GameLib.System.Linking.prototype.imageInstanceCreated = function(data) {
|
||||
|
@ -1017,6 +1044,7 @@ GameLib.System.Linking.prototype.stop = function() {
|
|||
this.lightInstanceCreatedSubscription.remove();
|
||||
this.sceneInstanceCreatedSubscription.remove();
|
||||
this.imageInstanceCreatedSubscription.remove();
|
||||
this.fontInstanceCreatedSubscription.remove();
|
||||
this.textureInstanceCreatedSubscription.remove();
|
||||
this.materialInstanceCreatedSubscription.remove();
|
||||
this.meshDeletedSubscription.remove();
|
||||
|
@ -1027,5 +1055,6 @@ GameLib.System.Linking.prototype.stop = function() {
|
|||
this.physicsWorldInstanceCreatedSubscription.remove();
|
||||
this.shapeInstanceCreatedSubscription.remove();
|
||||
this.solverInstanceCreatedSubscription.remove();
|
||||
this.registerDependenciesSubscription.remove();
|
||||
};
|
||||
|
||||
|
|
|
@ -128,6 +128,11 @@ GameLib.System.Storage.prototype.start = function() {
|
|||
this.loadImage
|
||||
);
|
||||
|
||||
this.loadFontSubscription = this.subscribe(
|
||||
GameLib.Event.LOAD_FONT,
|
||||
this.loadFont
|
||||
);
|
||||
|
||||
this.blenderDataSubscription = this.subscribe(
|
||||
GameLib.Event.BLENDER_DATA_RECEIVED,
|
||||
this.processBlenderData
|
||||
|
@ -855,6 +860,53 @@ GameLib.System.Storage.prototype.processBlenderData = function(data) {
|
|||
*/
|
||||
};
|
||||
|
||||
GameLib.System.Storage.prototype.loadFont = function(data) {
|
||||
|
||||
console.log('loading font : ' + data.font.name);
|
||||
|
||||
this.publish(
|
||||
GameLib.Event.GET_API_URL,
|
||||
null,
|
||||
function(urlData) {
|
||||
|
||||
var url = urlData.apiUrl + '/fonts/' + data.font.url + '?ts=' + Date.now();
|
||||
|
||||
var loader = new THREE.FontLoader();
|
||||
|
||||
loader.load(
|
||||
url,
|
||||
function ( font ) {
|
||||
|
||||
if (GameLib.Utils.IsEmpty(font.data)) {
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.FONT_NOT_FOUND,
|
||||
{
|
||||
font: data.font
|
||||
}
|
||||
);
|
||||
} else {
|
||||
data.font.instance = font;
|
||||
data.font.loaded = true;
|
||||
GameLib.Event.Emit(
|
||||
GameLib.Event.FONT_INSTANCE_CREATED,
|
||||
{
|
||||
font: data.font
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}.bind(this),
|
||||
function(error) {
|
||||
console.error(error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
};
|
||||
|
||||
GameLib.System.Storage.prototype.loadImage = function(data) {
|
||||
|
||||
console.log('loading image : ' + data.image.name);
|
||||
|
@ -1006,6 +1058,7 @@ GameLib.System.Storage.prototype.stop = function() {
|
|||
this.loadSubscription.remove();
|
||||
this.saveSubscription.remove();
|
||||
this.loadImageSubscription.remove();
|
||||
this.loadFontSubscription.remove();
|
||||
this.blenderDataSubscription.remove();
|
||||
this.imageUploadCompleteSubscription.remove();
|
||||
this.deleteSubscription.remove();
|
||||
|
|
Loading…
Reference in New Issue