selected objects start
parent
b5cdce22ab
commit
0aa539b6cf
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param object
|
||||||
|
* @param helper
|
||||||
|
* @param lastUpdate
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.SelectedObject = function (
|
||||||
|
object,
|
||||||
|
helper,
|
||||||
|
lastUpdate
|
||||||
|
) {
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(object)) {
|
||||||
|
console.warn('Cannot select no object');
|
||||||
|
throw new Error('Cannot select no object');
|
||||||
|
}
|
||||||
|
this.object = object;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(helper)) {
|
||||||
|
helper = null;
|
||||||
|
}
|
||||||
|
this.helper = helper;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(lastUpdate)) {
|
||||||
|
lastUpdate = Date.now();
|
||||||
|
}
|
||||||
|
this.lastUpdate = lastUpdate;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.SelectedObject
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.API.SelectedObject}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.SelectedObject.FromObjectSelectedObject = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.SelectedObject(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.object,
|
||||||
|
objectComponent.helper,
|
||||||
|
objectComponent.lastUpdate
|
||||||
|
);
|
||||||
|
};
|
|
@ -45,6 +45,8 @@ GameLib.Component.COMPONENT_INPUT_EDITOR = 0x11;
|
||||||
GameLib.Component.COMPONENT_EDITOR = 0x12;
|
GameLib.Component.COMPONENT_EDITOR = 0x12;
|
||||||
GameLib.Component.COMPONENT_VIEWPORT = 0x13;
|
GameLib.Component.COMPONENT_VIEWPORT = 0x13;
|
||||||
GameLib.Component.COMPONENT_SYSTEM = 0x14;
|
GameLib.Component.COMPONENT_SYSTEM = 0x14;
|
||||||
|
GameLib.Component.COMPONENT_GRAPHICS = 0x15;
|
||||||
|
GameLib.Component.COMPONENT_HELPER = 0x16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Components are linked at runtime - for storing, we just store the ID
|
* Components are linked at runtime - for storing, we just store the ID
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
* Graphics API
|
||||||
|
* @param id String
|
||||||
|
* @param name
|
||||||
|
* @param graphicsType
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Graphics = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
graphicsType,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_GRAPHICS,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Graphics (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(graphicsType)) {
|
||||||
|
graphicsType = GameLib.D3.Graphics.GRAPHICS_TYPE_THREE;
|
||||||
|
}
|
||||||
|
this.graphicsType = graphicsType;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Graphics.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Graphics.prototype.constructor = GameLib.D3.API.Graphics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Graphics
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Graphics.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Graphics(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.graphicsType,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,87 @@
|
||||||
|
/**
|
||||||
|
* This component renders a scene
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param helperType
|
||||||
|
* @param object
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Helper = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
helperType,
|
||||||
|
object,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_PASS,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Helper (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(object)) {
|
||||||
|
console.warn('Cannot create a helper for an Object which does not exist');
|
||||||
|
throw new Error('Cannot create a helper for an Object which does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(helperType)) {
|
||||||
|
if (
|
||||||
|
object instanceof GameLib.D3.Mesh &&
|
||||||
|
object.meshType != GameLib.D3.Mesh.TYPE_CURVE
|
||||||
|
) {
|
||||||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_WIREFRAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object instanceof GameLib.D3.Light) {
|
||||||
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||||||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT) {
|
||||||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object instanceof GameLib.D3.Skeleton) {
|
||||||
|
helperType = GameLib.D3.Helper.HELPER_TYPE_SKELETON;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.helperType = helperType;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Helper.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Helper.prototype.constructor = GameLib.D3.API.Helper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Helper
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Helper.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Helper(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.helperType,
|
||||||
|
objectComponent.object,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
|
@ -50,7 +50,7 @@ GameLib.D3.API.Input.Drive = function (
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = this.constructor.name;
|
name = 'Input.Drive (' + this.id + ')';
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
|
|
@ -2,24 +2,36 @@
|
||||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
* @param id String
|
* @param id String
|
||||||
* @param name String
|
* @param name String
|
||||||
|
* @param domElementId
|
||||||
|
* @param domContainerId
|
||||||
* @param editor GameLib.D3.API.Editor
|
* @param editor GameLib.D3.API.Editor
|
||||||
* @param camera
|
* @param camera
|
||||||
|
* @param widthOffset
|
||||||
|
* @param heightOffset
|
||||||
|
* @param containerWidthOffset
|
||||||
|
* @param containerHeightOffset
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Input.Editor = function (
|
GameLib.D3.API.Input.Editor = function (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
|
domElementId,
|
||||||
|
domContainerId,
|
||||||
editor,
|
editor,
|
||||||
camera,
|
camera,
|
||||||
|
widthOffset,
|
||||||
|
heightOffset,
|
||||||
|
containerWidthOffset,
|
||||||
|
containerHeightOffset,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_INPUT_EDITOR,
|
GameLib.Component.COMPONENT_INPUT_EDITOR,
|
||||||
{
|
{
|
||||||
'camera' : GameLib.D3.Camera,
|
'editor' : GameLib.D3.Editor,
|
||||||
'editor' : GameLib.D3.Editor
|
'camera' : GameLib.D3.Camera
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
@ -45,10 +57,35 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
}
|
}
|
||||||
this.domElementId = domElementId;
|
this.domElementId = domElementId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(domContainerId)) {
|
||||||
|
domContainerId = 'divContainer';
|
||||||
|
}
|
||||||
|
this.domContainerId = domContainerId;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
camera = null;
|
camera = null;
|
||||||
}
|
}
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(widthOffset)) {
|
||||||
|
widthOffset = 400;
|
||||||
|
}
|
||||||
|
this.widthOffset = widthOffset;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(heightOffset)) {
|
||||||
|
heightOffset = 0;
|
||||||
|
}
|
||||||
|
this.heightOffset = heightOffset;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(containerWidthOffset)) {
|
||||||
|
containerWidthOffset = 0;
|
||||||
|
}
|
||||||
|
this.containerWidthOffset = containerWidthOffset;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(containerHeightOffset)) {
|
||||||
|
containerHeightOffset = 80;
|
||||||
|
}
|
||||||
|
this.containerHeightOffset = containerHeightOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
@ -65,7 +102,13 @@ GameLib.D3.API.Input.Editor.FromObjectComponent = function(objectComponent) {
|
||||||
objectComponent.id,
|
objectComponent.id,
|
||||||
objectComponent.name,
|
objectComponent.name,
|
||||||
objectComponent.domElementId,
|
objectComponent.domElementId,
|
||||||
|
objectComponent.domContainerId,
|
||||||
|
objectComponent.editor,
|
||||||
objectComponent.camera,
|
objectComponent.camera,
|
||||||
|
objectComponent.widthOffset,
|
||||||
|
objectComponent.heightOffset,
|
||||||
|
objectComponent.containerWidthOffset,
|
||||||
|
objectComponent.containerHeightOffset,
|
||||||
objectComponent.parentEntity
|
objectComponent.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,12 +36,7 @@ GameLib.D3.API.Pass = function (
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = 'Render Pass (' + id + ')';
|
name = 'Pass (' + id + ')';
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'Render Pass (' + id + ')';
|
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* @param magFilter
|
* @param magFilter
|
||||||
* @param format
|
* @param format
|
||||||
* @param stencilBuffer
|
* @param stencilBuffer
|
||||||
|
* @param texture
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -20,13 +21,16 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
magFilter,
|
magFilter,
|
||||||
format,
|
format,
|
||||||
stencilBuffer,
|
stencilBuffer,
|
||||||
|
texture,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_RENDER_TARGET,
|
GameLib.Component.COMPONENT_RENDER_TARGET,
|
||||||
null,
|
{
|
||||||
|
texture : GameLib.D3.Texture
|
||||||
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
);
|
);
|
||||||
|
@ -71,6 +75,11 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
}
|
}
|
||||||
this.stencilBuffer = stencilBuffer;
|
this.stencilBuffer = stencilBuffer;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(texture)) {
|
||||||
|
texture = null;
|
||||||
|
}
|
||||||
|
this.texture = texture;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.RenderTarget.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.RenderTarget.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
@ -91,6 +100,7 @@ GameLib.D3.API.RenderTarget.FromObjectComponent = function(objectComponent) {
|
||||||
objectComponent.magFilter,
|
objectComponent.magFilter,
|
||||||
objectComponent.format,
|
objectComponent.format,
|
||||||
objectComponent.stencilBuffer,
|
objectComponent.stencilBuffer,
|
||||||
|
objectComponent.texture,
|
||||||
objectComponent.parentEntity
|
objectComponent.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.BoneWeight = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiBoneWeight)) {
|
||||||
|
apiBoneWeight = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.BoneWeight.call(
|
GameLib.D3.API.BoneWeight.call(
|
||||||
this,
|
this,
|
||||||
apiBoneWeight.boneIndex,
|
apiBoneWeight.boneIndex,
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Bone = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiBone)) {
|
||||||
|
apiBone = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Bone.call(
|
GameLib.D3.API.Bone.call(
|
||||||
this,
|
this,
|
||||||
apiBone.id,
|
apiBone.id,
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Camera = function(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
|
||||||
|
apiCamera = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Camera.call(
|
GameLib.D3.API.Camera.call(
|
||||||
this,
|
this,
|
||||||
apiCamera.id,
|
apiCamera.id,
|
||||||
|
@ -112,7 +116,10 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
instance.maxZ = this.maxZ;
|
instance.maxZ = this.maxZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE) {
|
if (
|
||||||
|
this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE ||
|
||||||
|
this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO
|
||||||
|
) {
|
||||||
instance.fov = this.fov;
|
instance.fov = this.fov;
|
||||||
instance.aspect = this.aspect;
|
instance.aspect = this.aspect;
|
||||||
instance.near = this.near;
|
instance.near = this.near;
|
||||||
|
@ -122,8 +129,7 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
||||||
instance.eyeSeparation = this.eyeSeparation;
|
instance.eyeSeparation = this.eyeSeparation;
|
||||||
instance.focalLength = this.focalLength;
|
instance.focalLength = this.focalLength;
|
||||||
|
instance.update(instance);
|
||||||
instance.update(this.camera.instance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Composer = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiComposer)) {
|
||||||
|
apiComposer = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Composer.call(
|
GameLib.D3.API.Composer.call(
|
||||||
this,
|
this,
|
||||||
apiComposer.id,
|
apiComposer.id,
|
||||||
|
|
|
@ -6,12 +6,17 @@
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Editor = function(
|
GameLib.D3.Editor = function(
|
||||||
graphics,
|
graphics,
|
||||||
apiEditor
|
apiEditor,
|
||||||
|
onSelectionChange
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiEditor)) {
|
||||||
|
apiEditor = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Editor.call(
|
GameLib.D3.API.Editor.call(
|
||||||
this,
|
this,
|
||||||
apiEditor.id,
|
apiEditor.id,
|
||||||
|
@ -22,18 +27,43 @@ GameLib.D3.Editor = function(
|
||||||
apiEditor.viewports,
|
apiEditor.viewports,
|
||||||
apiEditor.parentEntity
|
apiEditor.parentEntity
|
||||||
);
|
);
|
||||||
//
|
|
||||||
//if (GameLib.Utils.UndefinedOrNull(document)) {
|
this.games = this.games.map(
|
||||||
// console.warn('Cannot create an Editor Object without reference to the DOM document');
|
function(apiGame) {
|
||||||
// throw new Error('Cannot create an Editor Object without reference to the DOM document');
|
|
||||||
//}
|
if (apiGame instanceof GameLib.D3.API.Game) {
|
||||||
//this.document = document;
|
return GameLib.D3.Game(
|
||||||
//
|
this.graphics,
|
||||||
//if (GameLib.Utils.UndefinedOrNull(window)) {
|
apiGame
|
||||||
// console.warn('Cannot create an Editor Object without reference to the DOM window');
|
)
|
||||||
// throw new Error('Cannot create an Editor Object without reference to the DOM window');
|
} else {
|
||||||
//}
|
console.warn('Game not of type API.Game');
|
||||||
//this.window = window;
|
throw new Error('Game not of type API.Game');
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.viewports = this.viewports.map(
|
||||||
|
function(apiViewport) {
|
||||||
|
|
||||||
|
if (apiViewport instanceof GameLib.D3.API.Viewport) {
|
||||||
|
return GameLib.D3.Viewport(
|
||||||
|
this.graphics,
|
||||||
|
apiViewport
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
console.warn('Viewport not of type API.Viewport');
|
||||||
|
throw new Error('Viewport not of type API.Viewport');
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(onSelectionChange)) {
|
||||||
|
onSelectionChange = null;
|
||||||
|
}
|
||||||
|
this.onSelectionChange = onSelectionChange;
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
@ -88,7 +118,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
|
||||||
apiViewports = this.viewports.map(
|
apiViewports = this.viewports.map(
|
||||||
function(viewport) {
|
function(viewport) {
|
||||||
if (viewport instanceof GameLib.D3.Viewport) {
|
if (viewport instanceof GameLib.D3.Viewport) {
|
||||||
return viewport.toApiViewport();
|
return viewport.toApiComponent();
|
||||||
} else {
|
} else {
|
||||||
console.warn('Viewport not an instance of Viewport');
|
console.warn('Viewport not an instance of Viewport');
|
||||||
throw new Error('Viewport not an instance of Viewport');
|
throw new Error('Viewport not an instance of Viewport');
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Follow = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiFollow)) {
|
||||||
|
apiFollow = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Follow.call(
|
GameLib.D3.API.Follow.call(
|
||||||
this,
|
this,
|
||||||
apiFollow.id,
|
apiFollow.id,
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Game = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiGame)) {
|
||||||
|
apiGame = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Game.call(
|
GameLib.D3.API.Game.call(
|
||||||
this,
|
this,
|
||||||
apiGame.id,
|
apiGame.id,
|
||||||
|
@ -182,6 +186,29 @@ GameLib.D3.Game.prototype.createInstance = function(update) {
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Game.prototype.setSize = function(width, height) {
|
||||||
|
|
||||||
|
// var w = 0;
|
||||||
|
// var h = 0;
|
||||||
|
|
||||||
|
this.viewports.map(
|
||||||
|
function(viewport) {
|
||||||
|
// w = viewport.width;
|
||||||
|
// h = viewport.height;
|
||||||
|
//
|
||||||
|
// //TODO : calculate width and height decrease or increase ratio and adjust viewport x and y offset according
|
||||||
|
// var wx = width / w;
|
||||||
|
// var hx = height / h;
|
||||||
|
|
||||||
|
viewport.width = width;
|
||||||
|
viewport.height = height;
|
||||||
|
|
||||||
|
viewport.updateInstance();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the instance with the current state
|
* Updates the instance with the current state
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,15 +1,88 @@
|
||||||
/**
|
/**
|
||||||
* Graphics Superset
|
* Graphics Superset
|
||||||
* @param graphicsType
|
* @param apiGraphics
|
||||||
* @param instance {THREE}
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Graphics = function Graphics(
|
GameLib.D3.Graphics = function Graphics(
|
||||||
graphicsType,
|
apiGraphics
|
||||||
instance
|
|
||||||
) {
|
) {
|
||||||
this.graphicsType = graphicsType;
|
|
||||||
this.instance = instance;
|
if (GameLib.Utils.UndefinedOrNull(apiGraphics)) {
|
||||||
|
apiGraphics = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Graphics.call(
|
||||||
|
this,
|
||||||
|
apiGraphics.id,
|
||||||
|
apiGraphics.name,
|
||||||
|
apiGraphics.graphicsType,
|
||||||
|
apiGraphics.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Graphics.prototype = Object.create(GameLib.D3.API.Graphics.prototype);
|
||||||
|
GameLib.D3.Graphics.prototype.constructor = GameLib.D3.Graphics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameLib.D3.Graphics Types
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Graphics.GRAPHICS_TYPE_THREE = 0x1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {THREE.Graphics}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Graphics.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
} else {
|
||||||
|
instance = THREE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Graphics.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Graphics to a new GameLib.D3.API.Graphics
|
||||||
|
* @returns {GameLib.D3.API.Graphics}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Graphics.prototype.toApiGraphics = function() {
|
||||||
|
return new GameLib.D3.API.Graphics(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.graphicsType,
|
||||||
|
this.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Graphics to a GameLib.D3.Graphics
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param objectGraphics Object
|
||||||
|
* @returns {GameLib.D3.Graphics}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Graphics.FromObjectGraphics = function(graphics, objectGraphics) {
|
||||||
|
|
||||||
|
var apiGraphics = GameLib.D3.API.Graphics.FromObjectComponent(objectGraphics);
|
||||||
|
|
||||||
|
return new GameLib.D3.Graphics(
|
||||||
|
graphics,
|
||||||
|
apiGraphics
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,9 +102,3 @@ GameLib.D3.Graphics.prototype.isNotThreeThrow = function() {
|
||||||
throw new Error('Only THREE supported for this function');
|
throw new Error('Only THREE supported for this function');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Physics GameLib.D3.Graphics Types
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Graphics.GRAPHICS_TYPE_THREE = 0x1;
|
|
|
@ -1,45 +1,35 @@
|
||||||
/**
|
/**
|
||||||
* Helpers for displaying outlines or making 'invisible' scene objects visible
|
* Helpers for displaying outlines or making 'invisible' scene objects visible
|
||||||
* @param id
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param object GameLib.D3.Object
|
* @param apiHelper GameLib.D3.API.Helper
|
||||||
* @param name
|
|
||||||
* @param graphics
|
|
||||||
* @param helperType
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Helper = function Helper(
|
GameLib.D3.Helper = function Helper(
|
||||||
id,
|
graphics,
|
||||||
object,
|
apiHelper
|
||||||
helperType,
|
|
||||||
name,
|
|
||||||
graphics
|
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
||||||
id = GameLib.Utils.RandomId();
|
|
||||||
}
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(object)) {
|
|
||||||
throw new Error('Cannot create helpers for unknown objects');
|
|
||||||
}
|
|
||||||
this.object = object;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(helperType)) {
|
|
||||||
helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES;
|
|
||||||
}
|
|
||||||
this.helperType = helperType;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'Helper (' + this.helperType + ')';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiHelper)) {
|
||||||
|
apiHelper = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.Helper.call(
|
||||||
|
this,
|
||||||
|
apiHelper.id,
|
||||||
|
apiHelper.name,
|
||||||
|
apiHelper.helperType,
|
||||||
|
apiHelper.object,
|
||||||
|
apiHelper.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Helper.prototype = Object.create(GameLib.D3.API.Helper.prototype);
|
||||||
|
GameLib.D3.Helper.prototype.constructor = GameLib.D3.Helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper types
|
* Helper types
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
@ -60,6 +50,10 @@ GameLib.D3.Helper.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_EDGES) {
|
||||||
instance = new THREE.WireframeHelper(this.object.instance, 0x007700);
|
instance = new THREE.WireframeHelper(this.object.instance, 0x007700);
|
||||||
}
|
}
|
||||||
|
@ -81,16 +75,53 @@ GameLib.D3.Helper.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SKELETON) {
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SKELETON) {
|
||||||
instance = new THREE.SkeletonHelper(this.object.skeleton.instance);
|
instance = new THREE.SkeletonHelper(this.object.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
throw new Error('Unsupported helper type: ' + this.helperType);
|
throw new Error('Unsupported helper type: ' + this.helperType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
|
||||||
this.instance = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Helper.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Helper to a new GameLib.D3.API.Helper
|
||||||
|
* @returns {GameLib.D3.API.Helper}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Helper.prototype.toApiHelper = function() {
|
||||||
|
|
||||||
|
return new GameLib.D3.API.Helper(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.helperType,
|
||||||
|
GameLib.Utils.IdOrNull(this.object),
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Helper to a GameLib.D3.Helper
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param objectHelper Object
|
||||||
|
* @returns {GameLib.D3.Helper}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Helper.FromObjectHelper = function(graphics, objectHelper) {
|
||||||
|
|
||||||
|
var apiHelper = GameLib.D3.API.Helper.FromObjectHelper(objectHelper);
|
||||||
|
|
||||||
|
return new GameLib.D3.Helper(
|
||||||
|
graphics,
|
||||||
|
apiHelper
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
|
@ -2,16 +2,22 @@
|
||||||
* Input parent class
|
* Input parent class
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiInputDrive GameLib.D3.API.Input.Drive
|
* @param apiInputDrive GameLib.D3.API.Input.Drive
|
||||||
|
* @param dom GameLib.Dom
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Input.Drive = function (
|
GameLib.D3.Input.Drive = function (
|
||||||
graphics,
|
graphics,
|
||||||
apiInputDrive
|
apiInputDrive,
|
||||||
|
dom
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiInputDrive)) {
|
||||||
|
apiInputDrive = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Input.Drive.call(
|
GameLib.D3.API.Input.Drive.call(
|
||||||
this,
|
this,
|
||||||
apiInputDrive.id,
|
apiInputDrive.id,
|
||||||
|
@ -29,6 +35,12 @@ GameLib.D3.Input.Drive = function (
|
||||||
apiInputDrive.rotationFactor
|
apiInputDrive.rotationFactor
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(dom)) {
|
||||||
|
console.warn('Cannot create Input without an handle to the DOM');
|
||||||
|
throw new Error('Cannot create Input without an handle to the DOM');
|
||||||
|
}
|
||||||
|
this.dom = dom;
|
||||||
|
|
||||||
this.keyLeft = false;
|
this.keyLeft = false;
|
||||||
|
|
||||||
this.keyRight = false;
|
this.keyRight = false;
|
||||||
|
@ -45,7 +57,7 @@ GameLib.D3.Input.Drive.prototype.createInstance = function(update) {
|
||||||
return this.instance;
|
return this.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance = document.getElementById(this.domElementId);
|
var instance = this.dom.document.getElementById(this.domElementId);
|
||||||
|
|
||||||
instance.addEventListener(
|
instance.addEventListener(
|
||||||
'keydown',
|
'keydown',
|
||||||
|
|
|
@ -2,24 +2,56 @@
|
||||||
* Input parent class
|
* Input parent class
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiInputEditor GameLib.D3.API.Input.Editor
|
* @param apiInputEditor GameLib.D3.API.Input.Editor
|
||||||
|
* @param dom GameLib.DOM
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Input.Editor = function (
|
GameLib.D3.Input.Editor = function (
|
||||||
graphics,
|
graphics,
|
||||||
apiInputEditor
|
apiInputEditor,
|
||||||
|
dom
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiInputEditor)) {
|
||||||
|
apiInputEditor = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Input.Editor.call(
|
GameLib.D3.API.Input.Editor.call(
|
||||||
this,
|
this,
|
||||||
apiInputEditor.id,
|
apiInputEditor.id,
|
||||||
apiInputEditor.name,
|
apiInputEditor.name,
|
||||||
|
apiInputEditor.domElementId,
|
||||||
|
apiInputEditor.domContainerId,
|
||||||
|
apiInputEditor.editor,
|
||||||
apiInputEditor.camera,
|
apiInputEditor.camera,
|
||||||
|
apiInputEditor.widthOffset,
|
||||||
|
apiInputEditor.heightOffset,
|
||||||
|
apiInputEditor.containerWidthOffset,
|
||||||
|
apiInputEditor.containerHeightOffset,
|
||||||
apiInputEditor.parentEntity
|
apiInputEditor.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(dom)) {
|
||||||
|
console.warn('Cannot create Input without an handle to the DOM');
|
||||||
|
throw new Error('Cannot create Input without an handle to the DOM');
|
||||||
|
}
|
||||||
|
this.dom = dom;
|
||||||
|
|
||||||
|
this.element = null;
|
||||||
|
this.container = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We need new function pointers with scope bound to this so we can remove the
|
||||||
|
* window event handlers when we need to
|
||||||
|
* @type {function()}
|
||||||
|
*/
|
||||||
|
this.resize = this.onWindowResize.bind(this);
|
||||||
|
this.mouseMove = this.onMouseMove.bind(this);
|
||||||
|
this.mouseDown = this.onMouseDown.bind(this);
|
||||||
|
this.keyPress = this.onKeyPress.bind(this);
|
||||||
|
this.contextMenu = this.onContextMenu.bind(this);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
@ -29,36 +61,58 @@ GameLib.D3.Input.Editor.prototype.constructor = GameLib.D3.Input.Editor;
|
||||||
|
|
||||||
GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
|
GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
return this.instance;
|
instance = this.instance;
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance = document.getElementById(this.domElementId);
|
instance = this.dom.document.getElementById(this.domElementId);
|
||||||
|
|
||||||
this.resize = this.onWindowResize.bind(this);
|
if (!instance) {
|
||||||
|
console.warn('Could not locate DOM element with ID: ' + this.domElementId);
|
||||||
window.addEventListener('resize', this.resize, false );
|
throw new Error('Could not locate DOM element with ID: ' + this.domElementId);
|
||||||
|
|
||||||
// this.clearScene();
|
|
||||||
this.boundMouseMove = this.mouseMove.bind(this);
|
|
||||||
|
|
||||||
instance.addEventListener('contextmenu', function(event){
|
|
||||||
|
|
||||||
if (event.stopPropagation) {
|
|
||||||
event.stopPropagation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.preventDefault) {
|
this.element = instance;
|
||||||
event.preventDefault();
|
|
||||||
|
this.container = this.dom.document.getElementById(this.domContainerId);
|
||||||
|
|
||||||
|
if (!this.container) {
|
||||||
|
console.warn('Could not locate DOM container with ID: ' + this.domContainerId);
|
||||||
|
throw new Error('Could not locate DOM container with ID: ' + this.domContainerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
event.cancelBubble = true;
|
instance.addEventListener(
|
||||||
return false;
|
'mousemove',
|
||||||
}, false);
|
this.mouseMove,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
instance.addEventListener('mousedown', this.mouseDown.bind(this), false);
|
instance.addEventListener(
|
||||||
instance.addEventListener('keydown', this.keypress.bind(this), false);
|
'contextmenu',
|
||||||
instance.addEventListener('mousemove', this.boundMouseMove, false);
|
this.contextMenu,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
instance.addEventListener(
|
||||||
|
'mousedown',
|
||||||
|
this.mouseDown,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
instance.addEventListener(
|
||||||
|
'keydown',
|
||||||
|
this.keyPress,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
this.dom.window.addEventListener(
|
||||||
|
'resize',
|
||||||
|
this.resize,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
@ -77,16 +131,9 @@ GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.domElementId,
|
this.domElementId,
|
||||||
GameLib.Utils.IdOrNull(this.pathFollowingComponent),
|
GameLib.Utils.IdOrNull(this.editor),
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
GameLib.Utils.IdOrNull(this.camera),
|
||||||
GameLib.Utils.IdOrNull(this.wheelFL),
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
GameLib.Utils.IdOrNull(this.wheelFR),
|
|
||||||
GameLib.Utils.IdOrNull(this.wheelRL),
|
|
||||||
GameLib.Utils.IdOrNull(this.wheelRR),
|
|
||||||
this.heightOffset,
|
|
||||||
this.distance,
|
|
||||||
this.distanceGrain,
|
|
||||||
this.rotationFactor
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiInputEditor;
|
return apiInputEditor;
|
||||||
|
@ -102,6 +149,243 @@ GameLib.D3.Input.Editor.FromObjectComponent = function(graphics, objectComponent
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.onWindowResize = function() {
|
||||||
|
|
||||||
|
this.container.style.height = (this.window.innerHeight - this.containerHeightOffset) + 'px';
|
||||||
|
this.container.style.width = (this.window.innerWidth - this.containerWidthOffset) + 'px';
|
||||||
|
|
||||||
|
this.games.map(
|
||||||
|
function(width, height) {
|
||||||
|
return function(game) {
|
||||||
|
game.width = width;
|
||||||
|
game.height = height;
|
||||||
|
game.updateInstance();
|
||||||
|
}
|
||||||
|
}(this.window.innerWidth - this.widthOffset, this.window.innerHeight - this.heightOffset)
|
||||||
|
);
|
||||||
|
//
|
||||||
|
// this.scene.cameras[this.scene.activeCameraIndex].aspect = () / window.innerHeight;
|
||||||
|
// this.scene.cameras[this.scene.activeCameraIndex].updateInstance();
|
||||||
|
//
|
||||||
|
// this.scene.renderers[this.scene.activeRendererIndex].width = window.innerWidth - 400;
|
||||||
|
// this.scene.renderers[this.scene.activeRendererIndex].height = window.innerHeight;
|
||||||
|
// this.scene.renderers[this.scene.activeRendererIndex].updateInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keypress events
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
|
||||||
|
|
||||||
|
if (event.code == "KeyQ") {
|
||||||
|
|
||||||
|
this.editor.allSelected = !this.editor.allSelected;
|
||||||
|
|
||||||
|
if (this.editor.allSelected) {
|
||||||
|
|
||||||
|
this.editor.games.map(
|
||||||
|
function(game) {
|
||||||
|
|
||||||
|
for (var property in game.idToObject) {
|
||||||
|
if (game.idToObject.hasOwnProperty(property)) {
|
||||||
|
this.editor.selectedObjects.push(
|
||||||
|
new GameLib.D3.SelectedObject(
|
||||||
|
this.graphics,
|
||||||
|
game.idToObject(property)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.editor.selectedObjects = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.editor.onSelectionChange) {
|
||||||
|
this.editor.onSelectionChange(this.editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.code == 'KeyG') {
|
||||||
|
if (!this.meshMoveMode) {
|
||||||
|
console.log('move mode');
|
||||||
|
this.meshMoveMode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.code == 'KeyX') {
|
||||||
|
if (this.meshMoveMode) {
|
||||||
|
console.log('move along x');
|
||||||
|
this.meshMoveXMode = true;
|
||||||
|
this.meshMoveYMode = false;
|
||||||
|
this.meshMoveZMode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.code == 'KeyY') {
|
||||||
|
if (this.meshMoveMode) {
|
||||||
|
console.log('move along y');
|
||||||
|
this.meshMoveXMode = false;
|
||||||
|
this.meshMoveYMode = true;
|
||||||
|
this.meshMoveZMode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.code == 'KeyZ') {
|
||||||
|
if (this.meshMoveMode) {
|
||||||
|
console.log('move along z');
|
||||||
|
this.meshMoveXMode = false;
|
||||||
|
this.meshMoveYMode = false;
|
||||||
|
this.meshMoveZMode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.code == 'Escape') {
|
||||||
|
if (this.meshMoveMode) {
|
||||||
|
this.meshMoveMode = false;
|
||||||
|
console.log('TODO: implement restore positions');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.code == 'Enter') {
|
||||||
|
if (this.meshMoveMode) {
|
||||||
|
this.meshMoveMode = false;
|
||||||
|
console.log('TODO: implement apply positions');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mouse click events
|
||||||
|
* @param event
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
|
||||||
|
|
||||||
|
if (event.button == 2) {
|
||||||
|
|
||||||
|
event.cancelBubble = true;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (event.stopPropagation) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
var meshInstances = [];
|
||||||
|
|
||||||
|
for (var m = 0; m < this.scene.meshes.length; m++) {
|
||||||
|
meshInstances.push(this.scene.meshes[m].instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
var intersects = this.scene.raycaster.instance.intersectObjects(meshInstances);
|
||||||
|
|
||||||
|
if (intersects.length > 0) {
|
||||||
|
|
||||||
|
var index = -1;
|
||||||
|
|
||||||
|
for (var s = 0; s < this.selectedObjects.length; s++) {
|
||||||
|
if (this.selectedObjects[s].object.instance == intersects[0].object) {
|
||||||
|
index = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index == -1) {
|
||||||
|
/**
|
||||||
|
* The object is not selected, select it
|
||||||
|
*/
|
||||||
|
this.selectObject(intersects[0].object.gameLibObject);
|
||||||
|
|
||||||
|
this.buildSelectedObjects();
|
||||||
|
|
||||||
|
this.buildGUI();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/**
|
||||||
|
* De-select the objec
|
||||||
|
*/
|
||||||
|
var delta = Date.now() - this.selectedObjects[index].lastUpdate;
|
||||||
|
if (delta > 300) {
|
||||||
|
|
||||||
|
this.unselectObject(intersects[0].object.gameLibObject);
|
||||||
|
|
||||||
|
this.buildSelectedObjects();
|
||||||
|
|
||||||
|
this.buildGUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.button == 0) {
|
||||||
|
if (this.meshMoveMode) {
|
||||||
|
this.meshMoveMode = false;
|
||||||
|
this.meshMoveXMode = false;
|
||||||
|
this.meshMoveYMode = false;
|
||||||
|
this.meshMoveZMode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mouse move events
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Editor.prototype.onMouseMove = function(event) {
|
||||||
|
var clientX = event.clientX - 400;
|
||||||
|
|
||||||
|
this.scene.mouse.x = ((clientX/ (window.innerWidth - 400))) * 2 - 1;
|
||||||
|
this.scene.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||||
|
|
||||||
|
this.scene.raycaster.instance.setFromCamera(
|
||||||
|
this.scene.mouse,
|
||||||
|
this.scene.cameras[this.scene.activeCameraIndex].instance
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.meshMoveMode) {
|
||||||
|
|
||||||
|
var units = event.movementY;
|
||||||
|
|
||||||
|
if (this.meshMoveXMode) {
|
||||||
|
this.moveSelectedObjects('x', units);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.meshMoveYMode) {
|
||||||
|
this.moveSelectedObjects('y', units);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.meshMoveZMode) {
|
||||||
|
this.moveSelectedObjects('z', units);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent Context Menu creation
|
||||||
|
* @param event
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Editor.prototype.onContextMenu = function(event){
|
||||||
|
|
||||||
|
if (event.stopPropagation) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.preventDefault) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.cancelBubble = true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.D3.Input.Editor.prototype.update = function(deltaTime) {
|
GameLib.D3.Input.Editor.prototype.update = function(deltaTime) {
|
||||||
if (this.pathFollowingComponent) {
|
if (this.pathFollowingComponent) {
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,8 @@ GameLib.D3.RenderTarget = function (
|
||||||
apiRenderTarget.minFilter,
|
apiRenderTarget.minFilter,
|
||||||
apiRenderTarget.magFilter,
|
apiRenderTarget.magFilter,
|
||||||
apiRenderTarget.format,
|
apiRenderTarget.format,
|
||||||
apiRenderTarget.stencilBuffer
|
apiRenderTarget.stencilBuffer,
|
||||||
|
apiRenderTarget.texture
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
@ -55,6 +56,8 @@ GameLib.D3.RenderTarget.prototype.createInstance = function(update) {
|
||||||
instance.magFilter = this.magFilter;
|
instance.magFilter = this.magFilter;
|
||||||
instance.format = this.format;
|
instance.format = this.format;
|
||||||
instance.stencilBuffer = this.stencilBuffer;
|
instance.stencilBuffer = this.stencilBuffer;
|
||||||
|
instance.texture = this.texture.instance;
|
||||||
|
instance.texture.needsUpdate = true;
|
||||||
} else {
|
} else {
|
||||||
instance = new THREE.WebGLRenderTarget(
|
instance = new THREE.WebGLRenderTarget(
|
||||||
this.width,
|
this.width,
|
||||||
|
@ -66,6 +69,10 @@ GameLib.D3.RenderTarget.prototype.createInstance = function(update) {
|
||||||
stencilBuffer : this.stencilBuffer
|
stencilBuffer : this.stencilBuffer
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.texture instanceof GameLib.D3.Texture && this.texture.instance) {
|
||||||
|
instance.texture = this.texture.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -93,6 +100,7 @@ GameLib.D3.RenderTarget.prototype.toApiComponent = function() {
|
||||||
this.magFilter,
|
this.magFilter,
|
||||||
this.format,
|
this.format,
|
||||||
this.stencilBuffer,
|
this.stencilBuffer,
|
||||||
|
GameLib.Utils.IdOrNull(this.texture),
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* Selected Objects
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param object
|
||||||
|
* @param helper
|
||||||
|
* @param lastUpdate
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.SelectedObject = function SelectedObject(
|
||||||
|
graphics,
|
||||||
|
object,
|
||||||
|
helper,
|
||||||
|
lastUpdate
|
||||||
|
) {
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(object)) {
|
||||||
|
console.warn('Cannot select no object');
|
||||||
|
throw new Error('Cannot select no object');
|
||||||
|
}
|
||||||
|
this.object = object;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(helper)) {
|
||||||
|
helper = new GameLib.D3.Helper(
|
||||||
|
graphics,
|
||||||
|
new GameLib.D3.API.Helper(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
object
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.helper = helper;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(lastUpdate)) {
|
||||||
|
lastUpdate = Date.now();
|
||||||
|
}
|
||||||
|
this.lastUpdate = lastUpdate;
|
||||||
|
};
|
|
@ -74,8 +74,8 @@ GameLib.D3.Viewport.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.renderer) {
|
if (this.renderer) {
|
||||||
this.renderer.width = this.width;
|
this.renderer.width = this.width - this.x;
|
||||||
this.renderer.height = this.height;
|
this.renderer.height = this.height - this.y;
|
||||||
this.renderer.updateInstance();
|
this.renderer.updateInstance();
|
||||||
|
|
||||||
this.renderer.instance.setViewport(
|
this.renderer.instance.setViewport(
|
||||||
|
@ -85,8 +85,8 @@ GameLib.D3.Viewport.prototype.createInstance = function(update) {
|
||||||
this.height
|
this.height
|
||||||
);
|
);
|
||||||
} else if (this.composer) {
|
} else if (this.composer) {
|
||||||
this.composer.renderer.width = this.width;
|
this.composer.renderer.width = this.width - this.x;
|
||||||
this.composer.renderer.height = this.height;
|
this.composer.renderer.height = this.height - this.y;
|
||||||
this.composer.renderer.updateInstance();
|
this.composer.renderer.updateInstance();
|
||||||
|
|
||||||
this.composer.renderer.instance.setViewport(
|
this.composer.renderer.instance.setViewport(
|
||||||
|
@ -94,9 +94,23 @@ GameLib.D3.Viewport.prototype.createInstance = function(update) {
|
||||||
this.y,
|
this.y,
|
||||||
this.width,
|
this.width,
|
||||||
this.height
|
this.height
|
||||||
|
);
|
||||||
|
|
||||||
|
this.composer.passes.map(
|
||||||
|
function(pass) {
|
||||||
|
if (pass.camera instanceof GameLib.D3.Camera) {
|
||||||
|
pass.camera.aspect = (this.width - this.x) / (this.height / this.y);
|
||||||
|
pass.camera.updateInstance();
|
||||||
|
}
|
||||||
|
}.bind(this)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.camera) {
|
||||||
|
this.camera.aspect = (this.width - this.x) / (this.height / this.y);
|
||||||
|
this.camera.updateInstance();
|
||||||
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/**
|
||||||
|
* Runtime Dom
|
||||||
|
* @constructor
|
||||||
|
* @param document DOM Document
|
||||||
|
* @param window DOM Window
|
||||||
|
*/
|
||||||
|
GameLib.Dom = function(
|
||||||
|
document,
|
||||||
|
window
|
||||||
|
) {
|
||||||
|
this.document = document;
|
||||||
|
this.window = window;
|
||||||
|
};
|
|
@ -37,8 +37,8 @@ GameLib.System.prototype.constructor = GameLib.System;
|
||||||
|
|
||||||
GameLib.System.SYSTEM_TYPE_RENDER = 0x1;
|
GameLib.System.SYSTEM_TYPE_RENDER = 0x1;
|
||||||
GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2;
|
GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2;
|
||||||
GameLib.System.SYSTEM_TYPE_INPUT = 0x3;
|
GameLib.System.SYSTEM_TYPE_INPUT = 0x4;
|
||||||
GameLib.System.SYSTEM_TYPE_ALL = 0x4;
|
GameLib.System.SYSTEM_TYPE_ALL = 0x7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback
|
* @callback
|
||||||
|
|
Loading…
Reference in New Issue