Everything can be anything
parent
db4e225227
commit
ba1aa215b7
|
@ -39,7 +39,7 @@ GameLib.API.Component = function(
|
||||||
GameLib.API.Component.FromObjectComponent = function(objectComponent) {
|
GameLib.API.Component.FromObjectComponent = function(objectComponent) {
|
||||||
if (objectComponent instanceof Object) {
|
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);
|
return GameLib.D3.API.PathFollowing.FromObjectComponent(objectComponent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,15 @@ GameLib.Component = function(
|
||||||
parentEntity
|
parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.idToObject = {};
|
||||||
|
|
||||||
this.linkedObjects.parentEntity = GameLib.Entity;
|
this.linkedObjects.parentEntity = GameLib.Entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype);
|
GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
GameLib.Component.prototype.constructor = GameLib.Component;
|
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_MATERIAL = 0x2;
|
||||||
GameLib.Component.COMPONENT_RENDERER = 0x3;
|
GameLib.Component.COMPONENT_RENDERER = 0x3;
|
||||||
GameLib.Component.COMPONENT_LOOK_AT = 0x5;
|
GameLib.Component.COMPONENT_LOOK_AT = 0x5;
|
||||||
|
@ -48,6 +50,10 @@ GameLib.Component.COMPONENT_SYSTEM = 0x14;
|
||||||
GameLib.Component.COMPONENT_GRAPHICS = 0x15;
|
GameLib.Component.COMPONENT_GRAPHICS = 0x15;
|
||||||
GameLib.Component.COMPONENT_HELPER = 0x16;
|
GameLib.Component.COMPONENT_HELPER = 0x16;
|
||||||
GameLib.Component.COMPONENT_CUSTOM_CODE = 0x17;
|
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
|
* Components are linked at runtime - for storing, we just store the ID
|
||||||
|
@ -56,3 +62,23 @@ GameLib.Component.COMPONENT_CUSTOM_CODE = 0x17;
|
||||||
GameLib.Component.prototype.toApiComponent = function() {
|
GameLib.Component.prototype.toApiComponent = function() {
|
||||||
return this.id;
|
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;
|
||||||
|
};
|
|
@ -1,17 +1,46 @@
|
||||||
/**
|
/**
|
||||||
* Entity API Object (for storing / loading entities to and from API)
|
* Entity API Object (for storing / loading entities to and from API)
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
* @param entities GameLib.API.Entity[]
|
* @param entities GameLib.API.Entity[]
|
||||||
|
* @param parentEntity
|
||||||
*/
|
*/
|
||||||
GameLib.API.EntityManager = function(
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(entities)) {
|
||||||
entities = [];
|
entities = [];
|
||||||
}
|
}
|
||||||
this.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
|
* Creates an API entity manager from an Object entity manager
|
||||||
* @param objectEntityManager
|
* @param objectEntityManager
|
||||||
|
@ -26,6 +55,9 @@ GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager
|
||||||
);
|
);
|
||||||
|
|
||||||
return new GameLib.API.EntityManager(
|
return new GameLib.API.EntityManager(
|
||||||
apiEntities
|
objectEntityManager.id,
|
||||||
|
objectEntityManager.name,
|
||||||
|
apiEntities,
|
||||||
|
objectEntityManager.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ GameLib.API.Entity = function(
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = this.constructor.name;
|
name = 'Entity (' + this.id + ')';
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,30 @@
|
||||||
* @param name
|
* @param name
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Mouse = function(
|
GameLib.API.Mouse = function(
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
x,
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
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
|
* Returns an API mouse from an Object mouse
|
||||||
* @param objectMouse
|
* @param objectMouse
|
||||||
|
@ -45,6 +63,7 @@ GameLib.API.Mouse.FromObjectMouse = function (objectMouse) {
|
||||||
objectMouse.id,
|
objectMouse.id,
|
||||||
objectMouse.name,
|
objectMouse.name,
|
||||||
objectMouse.x,
|
objectMouse.x,
|
||||||
objectMouse.y
|
objectMouse.y,
|
||||||
|
objectMouse.parentEntity
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,6 +44,9 @@ GameLib.API.System = function (
|
||||||
this.entityManager = entityManager;
|
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
|
* Object to GameLib.D3.API.System
|
||||||
* @param objectComponent
|
* @param objectComponent
|
||||||
|
|
|
@ -56,7 +56,7 @@ GameLib.D3.API.Camera = function(
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
|
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
|
||||||
cameraType = GameLib.Component.COMPONENT_CAMERA;
|
cameraType = GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE;
|
||||||
}
|
}
|
||||||
this.cameraType = cameraType;
|
this.cameraType = cameraType;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ GameLib.D3.API.Editor = function(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_EDITOR,
|
GameLib.Component.COMPONENT_EDITOR,
|
||||||
{
|
{
|
||||||
'game' : GameLib.D3.Game
|
'game' : GameLib.D3.Game,
|
||||||
|
'viewports' : [GameLib.D3.Viewport]
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
|
|
@ -44,7 +44,7 @@ GameLib.D3.API.Game = function(
|
||||||
'cameras' : [GameLib.D3.Camera],
|
'cameras' : [GameLib.D3.Camera],
|
||||||
'renderers' : [GameLib.D3.Renderer],
|
'renderers' : [GameLib.D3.Renderer],
|
||||||
'composers' : [GameLib.D3.Composer],
|
'composers' : [GameLib.D3.Composer],
|
||||||
'systems' : [GameLib.D3.System],
|
'systems' : [GameLib.System],
|
||||||
'viewports' : [GameLib.D3.Viewport],
|
'viewports' : [GameLib.D3.Viewport],
|
||||||
'entityManager' : GameLib.EntityManager,
|
'entityManager' : GameLib.EntityManager,
|
||||||
'mouse' : GameLib.Mouse
|
'mouse' : GameLib.Mouse
|
||||||
|
@ -125,7 +125,7 @@ GameLib.D3.API.Game = function(
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(mouse)) {
|
if (GameLib.Utils.UndefinedOrNull(mouse)) {
|
||||||
mouse = null;
|
mouse = new GameLib.API.Mouse();
|
||||||
}
|
}
|
||||||
this.mouse = mouse;
|
this.mouse = mouse;
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,6 +45,11 @@ GameLib.D3.API.Pass = function (
|
||||||
}
|
}
|
||||||
this.passType = passType;
|
this.passType = passType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
|
camera = null;
|
||||||
|
}
|
||||||
|
this.camera = camera;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(scene)) {
|
if (GameLib.Utils.UndefinedOrNull(scene)) {
|
||||||
scene = null;
|
scene = null;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +69,6 @@ GameLib.D3.API.Pass = function (
|
||||||
}
|
}
|
||||||
this.renderToScreen = renderToScreen;
|
this.renderToScreen = renderToScreen;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.Pass.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Pass.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
|
|
@ -51,7 +51,7 @@ GameLib.D3.API.PathFollowing = function (
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING,
|
GameLib.Component.COMPONENT_PATH_FOLLOWING,
|
||||||
{
|
{
|
||||||
'spline': GameLib.D3.Spline,
|
'spline': GameLib.D3.Spline,
|
||||||
'mesh' : GameLib.D3.Mesh,
|
'mesh' : GameLib.D3.Mesh,
|
||||||
|
|
|
@ -29,7 +29,7 @@ GameLib.D3.API.RenderTarget = function (
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_RENDER_TARGET,
|
GameLib.Component.COMPONENT_RENDER_TARGET,
|
||||||
{
|
{
|
||||||
texture : GameLib.D3.Texture
|
'texture' : GameLib.D3.Texture
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
* @param boneTextureHeight Number
|
* @param boneTextureHeight Number
|
||||||
* @param boneMatrices GameLib.API.Matrix4[]
|
* @param boneMatrices GameLib.API.Matrix4[]
|
||||||
* @param boneTexture null (not implemented)
|
* @param boneTexture null (not implemented)
|
||||||
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Skeleton = function (
|
GameLib.D3.API.Skeleton = function (
|
||||||
|
@ -20,8 +21,24 @@ GameLib.D3.API.Skeleton = function (
|
||||||
boneTextureWidth,
|
boneTextureWidth,
|
||||||
boneTextureHeight,
|
boneTextureHeight,
|
||||||
boneMatrices,
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
|
@ -77,6 +94,9 @@ GameLib.D3.API.Skeleton = function (
|
||||||
this.boneTexture = boneTexture;
|
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
|
* Creates an API skeleton from an Object skeleton
|
||||||
* @param objectSkeleton
|
* @param objectSkeleton
|
||||||
|
@ -104,6 +124,7 @@ GameLib.D3.API.Skeleton.FromObjectSkeleton = function(objectSkeleton) {
|
||||||
return GameLib.D3.API.Matrix4.FromObjectMatrix(boneMatrix);
|
return GameLib.D3.API.Matrix4.FromObjectMatrix(boneMatrix);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
objectSkeleton.boneTexture
|
objectSkeleton.boneTexture,
|
||||||
|
objectSkeleton.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
|
@ -21,6 +21,7 @@
|
||||||
* @param unpackAlignment
|
* @param unpackAlignment
|
||||||
* @param premultiplyAlpha
|
* @param premultiplyAlpha
|
||||||
* @param encoding
|
* @param encoding
|
||||||
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Texture = function(
|
GameLib.D3.API.Texture = function(
|
||||||
|
@ -44,8 +45,22 @@ GameLib.D3.API.Texture = function(
|
||||||
mipmaps,
|
mipmaps,
|
||||||
unpackAlignment,
|
unpackAlignment,
|
||||||
premultiplyAlpha,
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
|
@ -179,6 +194,7 @@ GameLib.D3.API.Texture.FromObjectTexture = function(objectTexture) {
|
||||||
objectTexture.mipmaps,
|
objectTexture.mipmaps,
|
||||||
objectTexture.unpackAlignment,
|
objectTexture.unpackAlignment,
|
||||||
objectTexture.premultiplyAlpha,
|
objectTexture.premultiplyAlpha,
|
||||||
objectTexture.encoding
|
objectTexture.encoding,
|
||||||
|
objectTexture.parentEntity
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,23 +39,38 @@ GameLib.D3.Camera = function(
|
||||||
apiCamera.focalLength
|
apiCamera.focalLength
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.position instanceof GameLib.API.Vector3) {
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this.position,
|
this.position,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
console.warn('position not instance of API.Vector3');
|
||||||
|
throw new Error('position not instance of API.Vector3');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.quaternion instanceof GameLib.API.Quaternion) {
|
||||||
this.quaternion = new GameLib.Quaternion(
|
this.quaternion = new GameLib.Quaternion(
|
||||||
graphics,
|
graphics,
|
||||||
this.quaternion,
|
this.quaternion,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
console.warn('quaternion not instance of API.Quaternion');
|
||||||
|
throw new Error('quaternion not instance of API.Quaternion');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.lookAt instanceof GameLib.API.Vector3) {
|
||||||
this.lookAt = new GameLib.Vector3(
|
this.lookAt = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this.lookAt,
|
this.lookAt,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
console.warn('lookAt not instance of API.Vector3');
|
||||||
|
throw new Error('lookAt not instance of API.Vector3');
|
||||||
|
}
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
|
@ -99,11 +114,9 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
this.maxZ
|
this.maxZ
|
||||||
);
|
);
|
||||||
} else if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
} else if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
||||||
if (!instance) {
|
|
||||||
instance = new THREE.StereoCamera();
|
instance = new THREE.StereoCamera();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
|
|
||||||
|
@ -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.x = this.position.x;
|
||||||
instance.position.y = this.position.y;
|
instance.position.y = this.position.y;
|
||||||
instance.position.z = this.position.z;
|
instance.position.z = this.position.z;
|
||||||
|
|
|
@ -26,6 +26,8 @@ GameLib.D3.Composer = function (
|
||||||
apiComposer.parentEntity
|
apiComposer.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +45,10 @@ GameLib.D3.Composer.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
instance = this.instance;
|
instance = this.instance;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (this.renderer &&
|
||||||
|
this.renderTarget) {
|
||||||
|
|
||||||
if (!THREE.EffectComposer) {
|
if (!THREE.EffectComposer) {
|
||||||
console.warn('No THREE.EffectComposer');
|
console.warn('No THREE.EffectComposer');
|
||||||
|
|
|
@ -21,6 +21,8 @@ GameLib.D3.CustomCode = function(
|
||||||
apiCustomCode.args
|
apiCustomCode.args
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiEditor GameLib.D3.API.Editor
|
* @param apiEditor GameLib.D3.API.Editor
|
||||||
* @param onSelectionChanged
|
* @param onSelectionChanged
|
||||||
|
* @param onSelectObject
|
||||||
|
* @param onDeSelectObject
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Editor = function(
|
GameLib.D3.Editor = function(
|
||||||
|
@ -75,6 +77,8 @@ GameLib.D3.Editor = function(
|
||||||
}
|
}
|
||||||
this.onDeSelectObject = onDeSelectObject;
|
this.onDeSelectObject = onDeSelectObject;
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -172,17 +176,8 @@ GameLib.D3.Editor.prototype.selectObject = function(object) {
|
||||||
this.selectedObjects.push(
|
this.selectedObjects.push(
|
||||||
new GameLib.D3.SelectedObject(
|
new GameLib.D3.SelectedObject(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
object,
|
|
||||||
new GameLib.D3.Helper(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.D3.API.Helper(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
object
|
object
|
||||||
)
|
)
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.onSelectObject) {
|
if (this.onSelectObject) {
|
||||||
|
|
|
@ -56,6 +56,9 @@ GameLib.D3.Follow = function (
|
||||||
this.rotated,
|
this.rotated,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Follow.prototype = Object.create(GameLib.D3.API.Follow.prototype);
|
GameLib.D3.Follow.prototype = Object.create(GameLib.D3.API.Follow.prototype);
|
||||||
|
|
|
@ -144,7 +144,29 @@ GameLib.D3.Game = function (
|
||||||
}.bind(this)
|
}.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.buildIdToObject();
|
||||||
|
|
||||||
|
this.entityManager.linkObjects(this.idToObject);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Game.prototype = Object.create(GameLib.D3.API.Game.prototype);
|
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);
|
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
|
* Converts a GameLib.D3.Game to a new GameLib.D3.API.Game
|
||||||
* @returns {GameLib.D3.API.Game}
|
* @returns {GameLib.D3.API.Game}
|
||||||
|
|
|
@ -1,46 +1,83 @@
|
||||||
/**
|
/**
|
||||||
* Helpers for displaying outlines or making 'invisible' scene objects visible
|
* Helpers for displaying outlines or making 'invisible' scene objects visible
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiHelper GameLib.D3.API.Helper
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param object
|
||||||
|
* @param helperType
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Helper = function Helper(
|
GameLib.D3.Helper = function Helper(
|
||||||
graphics,
|
graphics,
|
||||||
apiHelper
|
id,
|
||||||
|
name,
|
||||||
|
object,
|
||||||
|
helperType
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiHelper)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
apiHelper = {};
|
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');
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Helper.call(
|
if (object instanceof GameLib.D3.Light) {
|
||||||
this,
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||||
apiHelper.id,
|
helperType = GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT;
|
||||||
apiHelper.name,
|
}
|
||||||
apiHelper.helperType,
|
|
||||||
apiHelper.object,
|
if (object.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||||||
apiHelper.parentEntity
|
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();
|
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}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Helper.HELPER_TYPE_EDGES = 'edges';
|
GameLib.D3.Helper.HELPER_TYPE_NONE = 0x0;
|
||||||
GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 'directional-light';
|
GameLib.D3.Helper.HELPER_TYPE_EDGES = 0x1;
|
||||||
GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 'spot-light';
|
GameLib.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT = 0x2;
|
||||||
GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 'point-light';
|
GameLib.D3.Helper.HELPER_TYPE_SPOT_LIGHT = 0x3;
|
||||||
GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 'wireframe';
|
GameLib.D3.Helper.HELPER_TYPE_POINT_LIGHT = 0x4;
|
||||||
GameLib.D3.Helper.HELPER_TYPE_SKELETON = 'skeleton';
|
GameLib.D3.Helper.HELPER_TYPE_WIREFRAME = 0x5;
|
||||||
|
GameLib.D3.Helper.HELPER_TYPE_SKELETON = 0x6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a helper instance
|
* Creates a helper instance
|
||||||
|
@ -71,17 +108,13 @@ GameLib.D3.Helper.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_WIREFRAME) {
|
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) {
|
if (this.helperType == GameLib.D3.Helper.HELPER_TYPE_SKELETON) {
|
||||||
instance = new THREE.SkeletonHelper(this.object.instance);
|
instance = new THREE.SkeletonHelper(this.object.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance) {
|
|
||||||
throw new Error('Unsupported helper type: ' + this.helperType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -91,37 +124,3 @@ GameLib.D3.Helper.prototype.createInstance = function(update) {
|
||||||
GameLib.D3.Helper.prototype.updateInstance = function() {
|
GameLib.D3.Helper.prototype.updateInstance = function() {
|
||||||
this.instance = this.createInstance(true);
|
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
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ GameLib.D3.Input.Drive = function (
|
||||||
|
|
||||||
this.keyRight = false;
|
this.keyRight = false;
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,8 @@ GameLib.D3.Input.Editor = function (
|
||||||
this.graphics
|
this.graphics
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,8 @@ GameLib.D3.LookAt = function (
|
||||||
this.targetPosition,
|
this.targetPosition,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
|
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
|
||||||
|
|
|
@ -272,6 +272,8 @@ GameLib.D3.Material = function Material(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -137,6 +137,8 @@ GameLib.D3.Mesh = function (
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance(false);
|
this.instance = this.createInstance(false);
|
||||||
|
|
||||||
this.instance.geometry.computeBoundingBox();
|
this.instance.geometry.computeBoundingBox();
|
||||||
|
|
|
@ -27,6 +27,8 @@ GameLib.D3.Pass = function (
|
||||||
apiPass.parentEntity
|
apiPass.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,10 +49,11 @@ GameLib.D3.Pass.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
instance = this.instance;
|
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) {
|
if (!THREE.RenderPass) {
|
||||||
console.warn('No THREE.RenderPass');
|
console.warn('No THREE.RenderPass');
|
||||||
throw new Error('No THREE.RenderPass');
|
throw new Error('No THREE.RenderPass');
|
||||||
|
@ -60,20 +63,25 @@ GameLib.D3.Pass.prototype.createInstance = function(update) {
|
||||||
this.scene.instance,
|
this.scene.instance,
|
||||||
this.camera.instance
|
this.camera.instance
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
} else if (this.passType == GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
|
} else if (this.passType == GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
|
||||||
|
|
||||||
if (!THREE.CopyShader) {
|
if (!THREE.CopyShader) {
|
||||||
console.warn('No THREE.CopyShader');
|
console.warn('No THREE.CopyShader');
|
||||||
throw new Error('No THREE.CopyShader');
|
throw new Error('No THREE.CopyShader');
|
||||||
}
|
}
|
||||||
|
|
||||||
instance = THREE.CopyShader;
|
instance = THREE.CopyShader;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.warn('Render pass not supported yet: ' + this.passType);
|
console.warn('Render pass not supported yet: ' + this.passType);
|
||||||
throw new Error('Render pass not supported yet: ' + this.passType);
|
throw new Error('Render pass not supported yet: ' + this.passType);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (instance) {
|
||||||
instance.renderToScreen = this.renderToScreen;
|
instance.renderToScreen = this.renderToScreen;
|
||||||
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,6 +105,7 @@ GameLib.D3.PathFollowing = function (
|
||||||
this.my = new GameLib.Utils.MovingAverage(10);
|
this.my = new GameLib.Utils.MovingAverage(10);
|
||||||
this.mz = 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);
|
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
|
||||||
|
|
|
@ -29,6 +29,8 @@ GameLib.D3.RenderTarget = function (
|
||||||
apiRenderTarget.texture
|
apiRenderTarget.texture
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,48 +46,24 @@ GameLib.D3.Scene = function (
|
||||||
}
|
}
|
||||||
this.imageFactory = imageFactory;
|
this.imageFactory = imageFactory;
|
||||||
|
|
||||||
this.idToObject = {};
|
|
||||||
|
|
||||||
this.meshes = this.meshes.map(
|
this.meshes = this.meshes.map(
|
||||||
function(apiMesh) {
|
function(apiMesh) {
|
||||||
|
|
||||||
var mesh = new GameLib.D3.Mesh(
|
if (apiMesh instanceof GameLib.D3.API.Mesh) {
|
||||||
|
|
||||||
|
return new GameLib.D3.Mesh(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiMesh,
|
apiMesh,
|
||||||
this.computeNormals,
|
this.computeNormals,
|
||||||
this.imageFactory
|
this.imageFactory
|
||||||
);
|
);
|
||||||
|
|
||||||
this.idToObject[mesh.id] = mesh;
|
} else {
|
||||||
|
console.warn('apiMesh not an instance of API.Mesh');
|
||||||
if (mesh.skeleton) {
|
throw new Error('apiMesh not an instance of API.Mesh');
|
||||||
|
|
||||||
this.idToObject[mesh.skeleton.id] = mesh.skeleton;
|
|
||||||
|
|
||||||
mesh.skeleton.bones.map(
|
|
||||||
function (bone) {
|
|
||||||
this.idToObject[bone.id] = bone;
|
|
||||||
}.bind(this)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -113,22 +89,21 @@ GameLib.D3.Scene = function (
|
||||||
function(apiLight) {
|
function(apiLight) {
|
||||||
|
|
||||||
if (apiLight instanceof GameLib.D3.API.Light) {
|
if (apiLight instanceof GameLib.D3.API.Light) {
|
||||||
var light = new GameLib.D3.Light(
|
|
||||||
|
return new GameLib.D3.Light(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiLight
|
apiLight
|
||||||
);
|
);
|
||||||
|
|
||||||
this.idToObject[light.id] = light;
|
|
||||||
|
|
||||||
return light;
|
|
||||||
} else {
|
} else {
|
||||||
|
console.warn('apiLight not an instance of API.Light');
|
||||||
|
throw new Error('apiLight not an instance of API.Light');
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.idToObject[this.id] = this;
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,14 +23,11 @@ GameLib.D3.SelectedObject = function SelectedObject(
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(helper)) {
|
if (GameLib.Utils.UndefinedOrNull(helper)) {
|
||||||
helper = new GameLib.D3.Helper(
|
helper = new GameLib.D3.Helper(
|
||||||
graphics,
|
this.graphics,
|
||||||
new GameLib.D3.API.Helper(
|
|
||||||
null,
|
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
object
|
object
|
||||||
)
|
)
|
||||||
);
|
|
||||||
}
|
}
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,8 @@ GameLib.D3.Skeleton = function Skeleton(
|
||||||
apiSkeleton.boneTextureWidth,
|
apiSkeleton.boneTextureWidth,
|
||||||
apiSkeleton.boneTextureHeight,
|
apiSkeleton.boneTextureHeight,
|
||||||
apiSkeleton.boneMatrices,
|
apiSkeleton.boneMatrices,
|
||||||
apiSkeleton.boneTexture
|
apiSkeleton.boneTexture,
|
||||||
|
apiSkeleton.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.bones = this.bones.map(
|
this.bones = this.bones.map(
|
||||||
|
@ -78,6 +79,8 @@ GameLib.D3.Skeleton = function Skeleton(
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -192,7 +195,8 @@ GameLib.D3.Skeleton.prototype.toApiSkeleton = function() {
|
||||||
return boneMatrix.toApiMatrix();
|
return boneMatrix.toApiMatrix();
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
this.boneTexture
|
this.boneTexture,
|
||||||
|
this.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiSkeleton;
|
return apiSkeleton;
|
||||||
|
|
|
@ -47,7 +47,8 @@ GameLib.D3.Texture = function Texture(
|
||||||
apiTexture.mipmaps,
|
apiTexture.mipmaps,
|
||||||
apiTexture.unpackAlignment,
|
apiTexture.unpackAlignment,
|
||||||
apiTexture.premultiplyAlpha,
|
apiTexture.premultiplyAlpha,
|
||||||
apiTexture.encoding
|
apiTexture.encoding,
|
||||||
|
apiTexture.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.offset = new GameLib.Vector2(
|
this.offset = new GameLib.Vector2(
|
||||||
|
@ -273,7 +274,8 @@ GameLib.D3.Texture.prototype.toApiTexture = function() {
|
||||||
this.mipmaps,
|
this.mipmaps,
|
||||||
this.unpackAlignment,
|
this.unpackAlignment,
|
||||||
this.premultiplyAlpha,
|
this.premultiplyAlpha,
|
||||||
this.encoding
|
this.encoding,
|
||||||
|
this.parentEntity
|
||||||
)
|
)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,6 +58,8 @@ GameLib.D3.Viewport = function (
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,10 @@ GameLib.EntityManager = function(
|
||||||
|
|
||||||
GameLib.API.EntityManager.call(
|
GameLib.API.EntityManager.call(
|
||||||
this,
|
this,
|
||||||
apiEntityManager.entities
|
apiEntityManager.id,
|
||||||
|
apiEntityManager.name,
|
||||||
|
apiEntityManager.entities,
|
||||||
|
apiEntityManager.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.entities = this.entities.map(
|
this.entities = this.entities.map(
|
||||||
|
@ -37,6 +40,8 @@ GameLib.EntityManager = function(
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,9 +65,15 @@ GameLib.EntityManager.prototype.createInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager.prototype.createEntity = function(name) {
|
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);
|
this.entities.push(entity);
|
||||||
|
|
||||||
|
@ -168,7 +179,10 @@ GameLib.EntityManager.prototype.toApiEntityManager = function() {
|
||||||
);
|
);
|
||||||
|
|
||||||
var apiEntityManager = new GameLib.API.EntityManager(
|
var apiEntityManager = new GameLib.API.EntityManager(
|
||||||
apiEntities
|
this.id,
|
||||||
|
this.name,
|
||||||
|
apiEntities,
|
||||||
|
this.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiEntityManager;
|
return apiEntityManager;
|
||||||
|
|
|
@ -23,6 +23,8 @@ GameLib.Entity = function (
|
||||||
apiEntity.components
|
apiEntity.components
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.componentToCreate = 0;
|
||||||
|
|
||||||
this.components = this.components.map(
|
this.components = this.components.map(
|
||||||
|
|
||||||
function (apiComponent) {
|
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)
|
* Adds a component to this entity through the instance (should notify the entity manager instance)
|
||||||
* @param component
|
* @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);
|
this.components.push(component);
|
||||||
component.parentEntity = this;
|
component.parentEntity = this;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,51 +9,42 @@ GameLib.Mouse = function (graphics, apiMouse) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GameLib.API.Mouse.call(
|
GameLib.API.Mouse.call(
|
||||||
this,
|
this,
|
||||||
apiMouse.id,
|
apiMouse.id,
|
||||||
apiMouse.name,
|
apiMouse.name,
|
||||||
apiMouse.x,
|
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
|
* Creates an instance mouse
|
||||||
* @param update
|
* @param update
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.Mouse.prototype.createInstance = function(update) {
|
GameLib.Mouse.prototype.createInstance = function(update) {
|
||||||
//
|
|
||||||
// var instance = null;
|
var instance = null;
|
||||||
//
|
|
||||||
// if (update) {
|
if (update) {
|
||||||
// instance = this.instance;
|
instance = this.instance;
|
||||||
// instance.x = this.x;
|
}
|
||||||
// instance.y = this.y;
|
|
||||||
// } else {
|
return instance;
|
||||||
// instance = new THREE.Mouse(this.x, this.y);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the instance vector, calls updateInstance on the parent object
|
* Updates the instance vector, calls updateInstance on the parent object
|
||||||
*/
|
*/
|
||||||
GameLib.Mouse.prototype.updateInstance = function() {
|
GameLib.Mouse.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
if (this.parentObject.updateInstance) {
|
|
||||||
this.parentObject.updateInstance();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,6 +56,7 @@ GameLib.Mouse.prototype.toApiMouse = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.x,
|
this.x,
|
||||||
this.y
|
this.y,
|
||||||
|
this.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 (
|
GameLib.Utils.UndefinedOrNull = function (
|
||||||
variable
|
variable
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -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') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports = GameLib;
|
module.exports = GameLib;
|
||||||
|
|
Loading…
Reference in New Issue