Everything can be anything

beta.r3js.org
Theunis J. Botha 2017-01-19 17:50:11 +01:00
parent db4e225227
commit ba1aa215b7
41 changed files with 434 additions and 256 deletions

View File

@ -39,7 +39,7 @@ GameLib.API.Component = function(
GameLib.API.Component.FromObjectComponent = function(objectComponent) {
if (objectComponent instanceof Object) {
if (objectComponent.componentType == GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING) {
if (objectComponent.componentType == GameLib.Component.COMPONENT_PATH_FOLLOWING) {
return GameLib.D3.API.PathFollowing.FromObjectComponent(objectComponent);
}

View File

@ -20,13 +20,15 @@ GameLib.Component = function(
parentEntity
);
this.idToObject = {};
this.linkedObjects.parentEntity = GameLib.Entity;
};
GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.Component.prototype.constructor = GameLib.Component;
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING = 0x1;
GameLib.Component.COMPONENT_PATH_FOLLOWING = 0x1;
GameLib.Component.COMPONENT_MATERIAL = 0x2;
GameLib.Component.COMPONENT_RENDERER = 0x3;
GameLib.Component.COMPONENT_LOOK_AT = 0x5;
@ -48,6 +50,10 @@ GameLib.Component.COMPONENT_SYSTEM = 0x14;
GameLib.Component.COMPONENT_GRAPHICS = 0x15;
GameLib.Component.COMPONENT_HELPER = 0x16;
GameLib.Component.COMPONENT_CUSTOM_CODE = 0x17;
GameLib.Component.COMPONENT_MOUSE = 0x18;
GameLib.Component.COMPONENT_SKELETON = 0x19;
GameLib.Component.COMPONENT_TEXTURE = 0x1a;
GameLib.Component.COMPONENT_ENTITY_MANAGER = 0x1b;
/**
* Components are linked at runtime - for storing, we just store the ID
@ -55,4 +61,24 @@ GameLib.Component.COMPONENT_CUSTOM_CODE = 0x17;
*/
GameLib.Component.prototype.toApiComponent = function() {
return this.id;
};
};
GameLib.Component.prototype.buildIdToObject = function() {
this.idToObject = {};
for (var property in this.linkedObjects) {
if (
this.linkedObjects.hasOwnProperty(property) &&
this.hasOwnProperty(property)
) {
if (this.linkedObjects[property] instanceof Array) {
this.idToObject = GameLib.Utils.LoadIdsFromArrayToIdObject(this[property], this.idToObject);
} else {
this.idToObject = GameLib.Utils.LoadIdsFromObjectToIdObject(this[property], this.idToObject);
}
}
}
this.idToObject[this.id] = this;
};

View File

@ -1,17 +1,46 @@
/**
* Entity API Object (for storing / loading entities to and from API)
* @constructor
* @param id
* @param name
* @param entities GameLib.API.Entity[]
* @param parentEntity
*/
GameLib.API.EntityManager = function(
entities
id,
name,
entities,
parentEntity
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_ENTITY_MANAGER,
{
'entities' : [GameLib.Entity]
},
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Entity Manager (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(entities)) {
entities = [];
}
this.entities = entities;
};
GameLib.API.EntityManager.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.EntityManager.prototype.constructor = GameLib.API.EntityManager;
/**
* Creates an API entity manager from an Object entity manager
* @param objectEntityManager
@ -26,6 +55,9 @@ GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager
);
return new GameLib.API.EntityManager(
apiEntities
objectEntityManager.id,
objectEntityManager.name,
apiEntities,
objectEntityManager.parentEntity
);
};

View File

@ -16,7 +16,7 @@ GameLib.API.Entity = function(
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = this.constructor.name;
name = 'Entity (' + this.id + ')';
}
this.name = name;

View File

@ -4,15 +4,30 @@
* @param name
* @param x
* @param y
* @param parentEntity
* @constructor
*/
GameLib.API.Mouse = function(
id,
name,
x,
y
y,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_MOUSE,
null,
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -35,6 +50,9 @@ GameLib.API.Mouse = function(
};
GameLib.API.Mouse.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.Mouse.prototype.constructor = GameLib.API.Mouse;
/**
* Returns an API mouse from an Object mouse
* @param objectMouse
@ -45,6 +63,7 @@ GameLib.API.Mouse.FromObjectMouse = function (objectMouse) {
objectMouse.id,
objectMouse.name,
objectMouse.x,
objectMouse.y
objectMouse.y,
objectMouse.parentEntity
)
};

View File

@ -44,6 +44,9 @@ GameLib.API.System = function (
this.entityManager = entityManager;
};
GameLib.API.System.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.System.prototype.constructor = GameLib.API.System;
/**
* Object to GameLib.D3.API.System
* @param objectComponent

View File

@ -56,7 +56,7 @@ GameLib.D3.API.Camera = function(
this.id = id;
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
cameraType = GameLib.Component.COMPONENT_CAMERA;
cameraType = GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE;
}
this.cameraType = cameraType;

View File

@ -22,7 +22,8 @@ GameLib.D3.API.Editor = function(
this,
GameLib.Component.COMPONENT_EDITOR,
{
'game' : GameLib.D3.Game
'game' : GameLib.D3.Game,
'viewports' : [GameLib.D3.Viewport]
},
null,
parentEntity

View File

@ -44,7 +44,7 @@ GameLib.D3.API.Game = function(
'cameras' : [GameLib.D3.Camera],
'renderers' : [GameLib.D3.Renderer],
'composers' : [GameLib.D3.Composer],
'systems' : [GameLib.D3.System],
'systems' : [GameLib.System],
'viewports' : [GameLib.D3.Viewport],
'entityManager' : GameLib.EntityManager,
'mouse' : GameLib.Mouse
@ -125,7 +125,7 @@ GameLib.D3.API.Game = function(
this.entityManager = entityManager;
if (GameLib.Utils.UndefinedOrNull(mouse)) {
mouse = null;
mouse = new GameLib.API.Mouse();
}
this.mouse = mouse;
};

View File

@ -45,6 +45,11 @@ GameLib.D3.API.Pass = function (
}
this.passType = passType;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(scene)) {
scene = null;
}
@ -64,7 +69,6 @@ GameLib.D3.API.Pass = function (
}
this.renderToScreen = renderToScreen;
};
GameLib.D3.API.Pass.prototype = Object.create(GameLib.Component.prototype);

View File

@ -51,7 +51,7 @@ GameLib.D3.API.PathFollowing = function (
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING,
GameLib.Component.COMPONENT_PATH_FOLLOWING,
{
'spline': GameLib.D3.Spline,
'mesh' : GameLib.D3.Mesh,

View File

@ -29,7 +29,7 @@ GameLib.D3.API.RenderTarget = function (
this,
GameLib.Component.COMPONENT_RENDER_TARGET,
{
texture : GameLib.D3.Texture
'texture' : GameLib.D3.Texture
},
null,
parentEntity

View File

@ -9,6 +9,7 @@
* @param boneTextureHeight Number
* @param boneMatrices GameLib.API.Matrix4[]
* @param boneTexture null (not implemented)
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Skeleton = function (
@ -20,8 +21,24 @@ GameLib.D3.API.Skeleton = function (
boneTextureWidth,
boneTextureHeight,
boneMatrices,
boneTexture
boneTexture,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_SKELETON,
{
'bones' : [GameLib.D3.Bone]
},
false,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -77,6 +94,9 @@ GameLib.D3.API.Skeleton = function (
this.boneTexture = boneTexture;
};
GameLib.D3.API.Skeleton.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Skeleton.prototype.constructor = GameLib.D3.API.Skeleton;
/**
* Creates an API skeleton from an Object skeleton
* @param objectSkeleton
@ -104,6 +124,7 @@ GameLib.D3.API.Skeleton.FromObjectSkeleton = function(objectSkeleton) {
return GameLib.D3.API.Matrix4.FromObjectMatrix(boneMatrix);
}
),
objectSkeleton.boneTexture
objectSkeleton.boneTexture,
objectSkeleton.parentEntity
);
};

View File

@ -21,6 +21,7 @@
* @param unpackAlignment
* @param premultiplyAlpha
* @param encoding
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Texture = function(
@ -44,8 +45,22 @@ GameLib.D3.API.Texture = function(
mipmaps,
unpackAlignment,
premultiplyAlpha,
encoding
encoding,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_TEXTURE,
null,
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
@ -179,6 +194,7 @@ GameLib.D3.API.Texture.FromObjectTexture = function(objectTexture) {
objectTexture.mipmaps,
objectTexture.unpackAlignment,
objectTexture.premultiplyAlpha,
objectTexture.encoding
objectTexture.encoding,
objectTexture.parentEntity
)
};

View File

@ -39,23 +39,38 @@ GameLib.D3.Camera = function(
apiCamera.focalLength
);
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
if (this.position instanceof GameLib.API.Vector3) {
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
} else {
console.warn('position not instance of API.Vector3');
throw new Error('position not instance of API.Vector3');
}
this.quaternion = new GameLib.Quaternion(
graphics,
this.quaternion,
this
);
if (this.quaternion instanceof GameLib.API.Quaternion) {
this.quaternion = new GameLib.Quaternion(
graphics,
this.quaternion,
this
);
} else {
console.warn('quaternion not instance of API.Quaternion');
throw new Error('quaternion not instance of API.Quaternion');
}
this.lookAt = new GameLib.Vector3(
graphics,
this.lookAt,
this
);
if (this.lookAt instanceof GameLib.API.Vector3) {
this.lookAt = new GameLib.Vector3(
graphics,
this.lookAt,
this
);
} else {
console.warn('lookAt not instance of API.Vector3');
throw new Error('lookAt not instance of API.Vector3');
}
this.instance = this.createInstance();
@ -99,9 +114,7 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
this.maxZ
);
} else if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
if (!instance) {
instance = new THREE.StereoCamera();
}
instance = new THREE.StereoCamera();
}
}
@ -133,6 +146,11 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
}
}
if (!instance) {
console.log('Unsupported camera type : ' + this.cameraType);
throw new Error('Unsupported camera type : ' + this.cameraType);
}
instance.position.x = this.position.x;
instance.position.y = this.position.y;
instance.position.z = this.position.z;

View File

@ -26,6 +26,8 @@ GameLib.D3.Composer = function (
apiComposer.parentEntity
);
this.buildIdToObject();
this.instance = this.createInstance();
};
@ -43,7 +45,10 @@ GameLib.D3.Composer.prototype.createInstance = function(update) {
if (update) {
instance = this.instance;
} else {
}
if (this.renderer &&
this.renderTarget) {
if (!THREE.EffectComposer) {
console.warn('No THREE.EffectComposer');

View File

@ -21,6 +21,8 @@ GameLib.D3.CustomCode = function(
apiCustomCode.args
);
this.buildIdToObject();
this.instance = this.createInstance();
};

View File

@ -3,6 +3,8 @@
* @param graphics GameLib.D3.Graphics
* @param apiEditor GameLib.D3.API.Editor
* @param onSelectionChanged
* @param onSelectObject
* @param onDeSelectObject
* @constructor
*/
GameLib.D3.Editor = function(
@ -75,6 +77,8 @@ GameLib.D3.Editor = function(
}
this.onDeSelectObject = onDeSelectObject;
this.buildIdToObject();
this.instance = this.createInstance();
};
@ -172,16 +176,7 @@ GameLib.D3.Editor.prototype.selectObject = function(object) {
this.selectedObjects.push(
new GameLib.D3.SelectedObject(
this.graphics,
object,
new GameLib.D3.Helper(
this.graphics,
new GameLib.D3.API.Helper(
null,
null,
null,
object
)
)
object
)
);
@ -220,4 +215,4 @@ GameLib.D3.Editor.prototype.deSelectObject = function(object) {
this.onDeSelectObject(results);
}
};
};

View File

@ -56,6 +56,9 @@ GameLib.D3.Follow = function (
this.rotated,
this
);
this.buildIdToObject();
};
GameLib.D3.Follow.prototype = Object.create(GameLib.D3.API.Follow.prototype);

View File

@ -144,7 +144,29 @@ GameLib.D3.Game = function (
}.bind(this)
);
if (this.entityManager instanceof GameLib.API.EntityManager) {
this.entityManager = new GameLib.EntityManager(
this.graphics,
this.entityManager
);
} else {
console.warn('EntityManager not of type API.EntityManager');
throw new Error('EntityManager not of type API.EntityManager');
}
if (this.mouse instanceof GameLib.API.Mouse) {
this.mouse = new GameLib.Mouse(
this.graphics,
this.mouse
);
} else {
console.warn('mouse not of type API.Mouse');
throw new Error('mouse not of type API.Mouse');
}
this.buildIdToObject();
this.entityManager.linkObjects(this.idToObject);
};
GameLib.D3.Game.prototype = Object.create(GameLib.D3.API.Game.prototype);
@ -198,55 +220,6 @@ GameLib.D3.Game.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
GameLib.D3.Game.prototype.buildIdToObject = function() {
this.idToObject = {};
if (this.entityManager instanceof GameLib.API.EntityManager) {
this.entityManager = new GameLib.EntityManager(
this.graphics,
this.entityManager
);
this.entityManager.entities.map(
function (entity) {
this.idToObject[entity.id] = entity;
entity.components.map(
function(component) {
if (component instanceof GameLib.Component) {
this.idToObject[component.id] = component;
} else {
console.warn('Component not of type Component');
throw new Error('Component not of type Component');
}
}.bind(this)
)
}.bind(this)
);
this.entityManager.linkObjects(this.idToObject);
} else {
console.warn('EntityManager not of type API.EntityManager');
throw new Error('EntityManager not of type API.EntityManager');
}
this.scenes.map(
function(scene) {
var idToObject = scene.idToObject;
for (var property in idToObject) {
if (idToObject.hasOwnProperty(property)) {
this.idToObject[property] = idToObject[property];
}
}
}.bind(this)
)
};
/**
* Converts a GameLib.D3.Game to a new GameLib.D3.API.Game
* @returns {GameLib.D3.API.Game}

View File

@ -1,46 +1,83 @@
/**
* Helpers for displaying outlines or making 'invisible' scene objects visible
* @param graphics GameLib.D3.Graphics
* @param apiHelper GameLib.D3.API.Helper
* @param id
* @param name
* @param object
* @param helperType
* @constructor
*/
GameLib.D3.Helper = function Helper(
graphics,
apiHelper
id,
name,
object,
helperType
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiHelper)) {
apiHelper = {};
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
GameLib.D3.API.Helper.call(
this,
apiHelper.id,
apiHelper.name,
apiHelper.helperType,
apiHelper.object,
apiHelper.parentEntity
);
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');
}
this.object = object;
if (GameLib.Utils.UndefinedOrNull(helperType)) {
helperType = GameLib.D3.Helper.HELPER_TYPE_NONE;
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;
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
* @type {string}
*/
GameLib.D3.Helper.HELPER_TYPE_EDGES = 'edges';
GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 'directional-light';
GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 'spot-light';
GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 'point-light';
GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 'wireframe';
GameLib.D3.Helper.HELPER_TYPE_SKELETON = 'skeleton';
GameLib.D3.Helper.HELPER_TYPE_NONE = 0x0;
GameLib.D3.Helper.HELPER_TYPE_EDGES = 0x1;
GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 0x2;
GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 0x3;
GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 0x4;
GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 0x5;
GameLib.D3.Helper.HELPER_TYPE_SKELETON = 0x6;
/**
* Creates a helper instance
@ -71,17 +108,13 @@ GameLib.D3.Helper.prototype.createInstance = function(update) {
}
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) {
instance = new THREE.WireframeHelper(this.object.instance, 0x007700);
instance = new THREE.WireframeGeometry(this.object.instance, 0x007700);
}
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SKELETON) {
instance = new THREE.SkeletonHelper(this.object.instance);
}
if (!instance) {
throw new Error('Unsupported helper type: ' + this.helperType);
}
return instance;
};
@ -91,37 +124,3 @@ GameLib.D3.Helper.prototype.createInstance = function(update) {
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
);
};

View File

@ -45,6 +45,8 @@ GameLib.D3.Input.Drive = function (
this.keyRight = false;
this.buildIdToObject();
this.instance = this.createInstance();
};

View File

@ -67,6 +67,8 @@ GameLib.D3.Input.Editor = function (
this.graphics
);
this.buildIdToObject();
this.instance = this.createInstance();
};

View File

@ -55,6 +55,8 @@ GameLib.D3.LookAt = function (
this.targetPosition,
this
);
this.buildIdToObject();
};
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);

View File

@ -272,6 +272,8 @@ GameLib.D3.Material = function Material(
}
}
this.buildIdToObject();
this.instance = this.createInstance();
};

View File

@ -137,6 +137,8 @@ GameLib.D3.Mesh = function (
this
);
this.buildIdToObject();
this.instance = this.createInstance(false);
this.instance.geometry.computeBoundingBox();

View File

@ -27,6 +27,8 @@ GameLib.D3.Pass = function (
apiPass.parentEntity
);
this.buildIdToObject();
this.instance = this.createInstance();
};
@ -47,10 +49,11 @@ GameLib.D3.Pass.prototype.createInstance = function(update) {
if (update) {
instance = this.instance;
} else {
}
if (this.passType == GameLib.D3.Pass.PASS_TYPE_RENDER) {
if (this.passType == GameLib.D3.Pass.PASS_TYPE_RENDER) {
if (this.scene && this.camera) {
if (!THREE.RenderPass) {
console.warn('No THREE.RenderPass');
throw new Error('No THREE.RenderPass');
@ -60,20 +63,25 @@ GameLib.D3.Pass.prototype.createInstance = function(update) {
this.scene.instance,
this.camera.instance
);
} else if (this.passType == GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
if (!THREE.CopyShader) {
console.warn('No THREE.CopyShader');
throw new Error('No THREE.CopyShader');
}
instance = THREE.CopyShader;
} else {
console.warn('Render pass not supported yet: ' + this.passType);
throw new Error('Render pass not supported yet: ' + this.passType);
}
} else if (this.passType == GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
if (!THREE.CopyShader) {
console.warn('No THREE.CopyShader');
throw new Error('No THREE.CopyShader');
}
instance = THREE.CopyShader;
} else {
console.warn('Render pass not supported yet: ' + this.passType);
throw new Error('Render pass not supported yet: ' + this.passType);
}
instance.renderToScreen = this.renderToScreen;
if (instance) {
instance.renderToScreen = this.renderToScreen;
}
return instance;
};

View File

@ -105,6 +105,7 @@ GameLib.D3.PathFollowing = function (
this.my = new GameLib.Utils.MovingAverage(10);
this.mz = new GameLib.Utils.MovingAverage(10);
this.buildIdToObject();
};
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);

View File

@ -29,6 +29,8 @@ GameLib.D3.RenderTarget = function (
apiRenderTarget.texture
);
this.buildIdToObject();
this.instance = this.createInstance();
};

View File

@ -46,48 +46,24 @@ GameLib.D3.Scene = function (
}
this.imageFactory = imageFactory;
this.idToObject = {};
this.meshes = this.meshes.map(
function(apiMesh) {
var mesh = new GameLib.D3.Mesh(
this.graphics,
apiMesh,
this.computeNormals,
this.imageFactory
);
if (apiMesh instanceof GameLib.D3.API.Mesh) {
this.idToObject[mesh.id] = mesh;
return new GameLib.D3.Mesh(
this.graphics,
apiMesh,
this.computeNormals,
this.imageFactory
);
if (mesh.skeleton) {
this.idToObject[mesh.skeleton.id] = mesh.skeleton;
mesh.skeleton.bones.map(
function (bone) {
this.idToObject[bone.id] = bone;
}.bind(this)
)
} else {
console.warn('apiMesh not an instance of API.Mesh');
throw new Error('apiMesh not an instance of API.Mesh');
}
mesh.materials.map(
function(material) {
this.idToObject[material.id] = material;
for (var property in material) {
if (material.hasOwnProperty(property)) {
if (material[property] instanceof GameLib.D3.Texture) {
this.idToObject[material[property].id] = material[property];
}
}
}
}.bind(this)
);
return mesh;
}.bind(this)
);
@ -113,22 +89,21 @@ GameLib.D3.Scene = function (
function(apiLight) {
if (apiLight instanceof GameLib.D3.API.Light) {
var light = new GameLib.D3.Light(
return new GameLib.D3.Light(
this.graphics,
apiLight
);
this.idToObject[light.id] = light;
return light;
} else {
console.warn('apiLight not an instance of API.Light');
throw new Error('apiLight not an instance of API.Light');
}
}.bind(this)
);
this.idToObject[this.id] = this;
this.buildIdToObject();
this.instance = this.createInstance();
};

View File

@ -23,14 +23,11 @@ GameLib.D3.SelectedObject = function SelectedObject(
if (GameLib.Utils.UndefinedOrNull(helper)) {
helper = new GameLib.D3.Helper(
graphics,
new GameLib.D3.API.Helper(
null,
null,
null,
object
)
);
this.graphics,
null,
null,
object
)
}
this.helper = helper;

View File

@ -25,7 +25,8 @@ GameLib.D3.Skeleton = function Skeleton(
apiSkeleton.boneTextureWidth,
apiSkeleton.boneTextureHeight,
apiSkeleton.boneMatrices,
apiSkeleton.boneTexture
apiSkeleton.boneTexture,
apiSkeleton.parentEntity
);
this.bones = this.bones.map(
@ -78,6 +79,8 @@ GameLib.D3.Skeleton = function Skeleton(
}.bind(this)
);
this.buildIdToObject();
this.instance = this.createInstance();
};
@ -192,7 +195,8 @@ GameLib.D3.Skeleton.prototype.toApiSkeleton = function() {
return boneMatrix.toApiMatrix();
}
),
this.boneTexture
this.boneTexture,
this.parentEntity
);
return apiSkeleton;

View File

@ -47,7 +47,8 @@ GameLib.D3.Texture = function Texture(
apiTexture.mipmaps,
apiTexture.unpackAlignment,
apiTexture.premultiplyAlpha,
apiTexture.encoding
apiTexture.encoding,
apiTexture.parentEntity
);
this.offset = new GameLib.Vector2(
@ -273,7 +274,8 @@ GameLib.D3.Texture.prototype.toApiTexture = function() {
this.mipmaps,
this.unpackAlignment,
this.premultiplyAlpha,
this.encoding
this.encoding,
this.parentEntity
)
};

View File

@ -57,7 +57,9 @@ GameLib.D3.Viewport = function (
this.camera
)
}
this.buildIdToObject();
this.instance = this.createInstance();
};

View File

@ -18,7 +18,10 @@ GameLib.EntityManager = function(
GameLib.API.EntityManager.call(
this,
apiEntityManager.entities
apiEntityManager.id,
apiEntityManager.name,
apiEntityManager.entities,
apiEntityManager.parentEntity
);
this.entities = this.entities.map(
@ -37,6 +40,8 @@ GameLib.EntityManager = function(
}.bind(this)
);
this.buildIdToObject();
this.instance = this.createInstance();
};
@ -60,9 +65,15 @@ GameLib.EntityManager.prototype.createInstance = function() {
*/
GameLib.EntityManager.prototype.createEntity = function(name) {
var apiEntity = new GameLib.API.Entity(null, name);
var apiEntity = new GameLib.API.Entity(
null,
name
);
var entity = new GameLib.Entity(this.graphics, apiEntity);
var entity = new GameLib.Entity(
this.graphics,
apiEntity
);
this.entities.push(entity);
@ -168,7 +179,10 @@ GameLib.EntityManager.prototype.toApiEntityManager = function() {
);
var apiEntityManager = new GameLib.API.EntityManager(
apiEntities
this.id,
this.name,
apiEntities,
this.parentEntity
);
return apiEntityManager;

View File

@ -23,6 +23,8 @@ GameLib.Entity = function (
apiEntity.components
);
this.componentToCreate = 0;
this.components = this.components.map(
function (apiComponent) {
@ -92,7 +94,12 @@ GameLib.Entity.prototype.createInstance = function() {
* Adds a component to this entity through the instance (should notify the entity manager instance)
* @param component
*/
GameLib.Entity.prototype.addComponent = function(component) {
GameLib.Entity.prototype.addComponent = function() {
if (this.componentToCreate == GameLib.Component.COMPONENT_CUSTOM_CODE) {
var component = new GameLib.D3.CustomCode();
}
this.components.push(component);
component.parentEntity = this;
};

View File

@ -9,51 +9,42 @@ GameLib.Mouse = function (graphics, apiMouse) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
GameLib.API.Mouse.call(
this,
apiMouse.id,
apiMouse.name,
apiMouse.x,
apiMouse.y
apiMouse.y,
apiMouse.parentEntity
);
this.parentObject = parentObject;
// this.instance = this.createInstance();
this.instance = this.createInstance();
};
GameLib.Mouse.prototype = Object.create(GameLib.API.Mouse.prototype);
GameLib.Mouse.prototype.constructor = GameLib.Mouse;
/**
* Creates an instance mouse
* @param update
* @returns {*}
*/
GameLib.Mouse.prototype.createInstance = function(update) {
//
// var instance = null;
//
// if (update) {
// instance = this.instance;
// instance.x = this.x;
// instance.y = this.y;
// } else {
// instance = new THREE.Mouse(this.x, this.y);
// }
//
// return instance;
var instance = null;
if (update) {
instance = this.instance;
}
return instance;
};
/**
* Updates the instance vector, calls updateInstance on the parent object
*/
GameLib.Mouse.prototype.updateInstance = function() {
this.createInstance(true);
if (this.parentObject.updateInstance) {
this.parentObject.updateInstance();
}
};
/**
@ -65,6 +56,7 @@ GameLib.Mouse.prototype.toApiMouse = function() {
this.id,
this.name,
this.x,
this.y
this.y,
this.parentEntity
);
};

View File

@ -35,6 +35,50 @@ GameLib.Utils.Extend = function(
// }
// };
GameLib.Utils.LoadIdsFromArrayToIdObject = function(array, idToObject) {
array.map(
function(object) {
if (object.buildIdToObject) {
object.buildIdToObject();
var _idToObject = object.idToObject;
for (var property in _idToObject) {
if (_idToObject.hasOwnProperty(property)) {
idToObject[property] = _idToObject[property];
}
}
}
idToObject[object.id] = object;
}
);
return idToObject;
};
GameLib.Utils.LoadIdsFromObjectToIdObject = function(object, idToObject) {
if (!object) {
return idToObject;
}
if (object.buildIdToObject) {
object.buildIdToObject();
var _idToObject = object.idToObject;
for (var property in _idToObject) {
if (_idToObject.hasOwnProperty(property)) {
idToObject[property] = _idToObject[property];
}
}
}
idToObject[object.id] = object;
return idToObject;
};
GameLib.Utils.UndefinedOrNull = function (
variable
) {

View File

@ -1,5 +1,8 @@
GameLib.API.System.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.System.prototype.constructor = GameLib.API.System;
if (typeof module !== 'undefined') {
module.exports = GameLib;