toApiObject

beta.r3js.org
-=yb4f310 2017-05-16 14:51:57 +02:00
parent 80f5ac9663
commit bc8e36ea24
39 changed files with 223 additions and 143 deletions

View File

@ -27,7 +27,7 @@ GameLib.Component = function(
//this.parentObjects = [];
this.build = true;
this.built = true;
//this.linkedObjects.parentEntity = GameLib.Entity;
};
@ -70,17 +70,17 @@ GameLib.Component.COMPONENT_GUI = 0x1f;
* Components are linked at runtime - for storing, we just store the ID
* @returns {*}
*/
GameLib.Component.prototype.toApiComponent = function() {
GameLib.Component.prototype.toApiObject = function() {
return this.id;
};
GameLib.Component.prototype.buildIdToObject = function() {
if (!this.build) {
if (!this.built) {
return;
}
this.build = false;
this.built = false;
this.idToObject = {};
@ -100,7 +100,7 @@ GameLib.Component.prototype.buildIdToObject = function() {
this.idToObject[this.id] = this;
this.build = true;
this.built = true;
};
/**

View File

@ -86,7 +86,7 @@ GameLib.Color.prototype.updateInstance = function() {
* Converts runtime color to API Color
* @returns {GameLib.API.Color}
*/
GameLib.Color.prototype.toApiColor = function() {
GameLib.Color.prototype.toApiObject = function() {
return new GameLib.API.Color(
this.r,
this.g,

View File

@ -33,7 +33,7 @@ GameLib.D3.BoneWeight.prototype.constructor = GameLib.D3.BoneWeight;
* Converts a GameLib.D3.BoneWeight to GameLib.D3.API.BoneWeight
* @returns {GameLib.D3.API.BoneWeight}
*/
GameLib.D3.BoneWeight.prototype.toApiBoneWeight = function() {
GameLib.D3.BoneWeight.prototype.toApiObject = function() {
var apiBoneWeight = new GameLib.D3.API.BoneWeight(
this.boneIndex,

View File

@ -109,17 +109,17 @@ GameLib.D3.Bone.prototype.updateInstance = function() {
* Converts a GameLib.D3.Bone to GameLib.D3.API.Bone
* @returns {GameLib.D3.API.Bone}
*/
GameLib.D3.Bone.prototype.toApiBone = function() {
GameLib.D3.Bone.prototype.toApiObject = function() {
var apiBone = new GameLib.D3.API.Bone(
this.id,
this.name,
this.childBoneIds,
this.parentBoneIds,
this.position.toApiVector(),
this.quaternion.toApiQuaternion(),
this.scale.toApiVector(),
this.up.toApiVector()
this.position.toApiObject(),
this.quaternion.toApiObject(),
this.scale.toApiObject(),
this.up.toApiObject()
);
return apiBone;

View File

@ -182,7 +182,7 @@ GameLib.D3.Camera.prototype.updateInstance = function() {
* Converts a GameLib.D3.Camera to a new GameLib.D3.API.Camera
* @returns {GameLib.D3.API.Camera}
*/
GameLib.D3.Camera.prototype.toApiCamera = function() {
GameLib.D3.Camera.prototype.toApiObject = function() {
return new GameLib.D3.API.Camera(
this.id,
@ -192,15 +192,15 @@ GameLib.D3.Camera.prototype.toApiCamera = function() {
this.aspect,
this.near,
this.far,
this.position.toApiVector(),
this.lookAt.toApiVector(),
this.position.toApiObject(),
this.lookAt.toApiObject(),
this.minX,
this.maxX,
this.minY,
this.maxY,
this.minZ,
this.maxZ,
this.quaternion.toApiQuaternion(),
this.quaternion.toApiObject(),
GameLib.Utils.IdOrNull(this.parentEntity),
this.eyeSeparation,
this.focalLength

View File

@ -113,7 +113,7 @@ GameLib.D3.Composer.prototype.updateInstance = function() {
* GameLib.D3.Composer to GameLib.D3.API.Composer
* @returns {GameLib.D3.API.Composer}
*/
GameLib.D3.Composer.prototype.toApiComponent = function() {
GameLib.D3.Composer.prototype.toApiObject = function() {
var apiComposer = new GameLib.D3.API.Composer(
this.id,

View File

@ -59,7 +59,7 @@ GameLib.D3.CustomCode.prototype.updateInstance = function() {
* Converts a GameLib.D3.CustomCode to a new GameLib.D3.API.CustomCode
* @returns {GameLib.D3.API.CustomCode}
*/
GameLib.D3.CustomCode.prototype.toApiCustomCode = function() {
GameLib.D3.CustomCode.prototype.toApiObject = function() {
var apiArgs = [];

View File

@ -240,7 +240,7 @@ GameLib.D3.Editor.prototype.updateInstance = function() {
* Converts a GameLib.D3.Editor to a new GameLib.D3.API.Editor
* @returns {GameLib.D3.API.Editor}
*/
GameLib.D3.Editor.prototype.toApiEditor = function() {
GameLib.D3.Editor.prototype.toApiObject = function() {
var apiImageFactory = null;
var apiGames = [];
@ -254,14 +254,14 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
var apiEntityManager = null;
if (this.imageFactory instanceof GameLib.D3.ImageFactory) {
apiImageFactory = this.imageFactory.toApiImageFactory();
apiImageFactory = this.imageFactory.toApiObject();
}
if (this.games) {
apiGames = this.games.map(
function(game) {
if (game instanceof GameLib.D3.Game) {
return game.toApiGame();
return game.toApiObject();
} else {
console.warn('game not an instance of Game');
throw new Error('game not an instance of Game');
@ -274,7 +274,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
apiScenes = this.scenes.map(
function(scene) {
if (scene instanceof GameLib.D3.Scene) {
return scene.toApiScene();
return scene.toApiObject();
} else {
console.warn('scene not an instance of Scene');
throw new Error('scene not an instance of Scene');
@ -287,7 +287,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
apiCameras = this.cameras.map(
function(camera) {
if (camera instanceof GameLib.D3.Camera) {
return camera.toApiCamera();
return camera.toApiObject();
} else {
console.warn('camera not an instance of Camera');
throw new Error('camera not an instance of Camera');
@ -300,7 +300,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
apiComposers = this.composers.map(
function(composer) {
if (composer instanceof GameLib.D3.Composer) {
return composer.toApiComponent();
return composer.toApiObject();
} else {
console.warn('composer not an instance of Composer');
throw new Error('composer not an instance of Composer');
@ -313,7 +313,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
apiViewports = this.viewports.map(
function(viewport) {
if (viewport instanceof GameLib.D3.Viewport) {
return viewport.toApiComponent();
return viewport.toApiObject();
} else {
console.warn('viewport not an instance of Viewport');
throw new Error('viewport not an instance of Viewport');
@ -326,7 +326,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
apiRenderers = this.renderers.map(
function(renderer) {
if (renderer instanceof GameLib.D3.Renderer) {
return renderer.toApiComponent();
return renderer.toApiObject();
} else {
console.warn('renderer not an instance of Renderer');
throw new Error('renderer not an instance of Renderer');
@ -339,7 +339,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
apiRenderTargets = this.renderTargets.map(
function(renderTarget) {
if (renderTarget instanceof GameLib.D3.RenderTarget) {
return renderTarget.toApiComponent();
return renderTarget.toApiObject();
} else {
console.warn('renderTarget not an instance of RenderTarget');
throw new Error('renderTarget not an instance of RenderTarget');
@ -352,7 +352,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
apiSystems = this.systems.map(
function(system) {
if (system instanceof GameLib.System) {
return system.toApiComponent();
return system.toApiObject();
} else {
console.warn('system not an instance of System');
throw new Error('system not an instance of System');
@ -363,7 +363,7 @@ GameLib.D3.Editor.prototype.toApiEditor = function() {
if (this.entityManager) {
if (this.entityManager instanceof GameLib.EntityManager) {
apiEntityManager = this.entityManager.toApiEntityManager();
apiEntityManager = this.entityManager.toApiObject();
} else {
console.warn('entityManager not an instance of EntityManager');
throw new Error('entityManager not an instance of EntityManager');

View File

@ -68,14 +68,14 @@ GameLib.D3.Follow = function (
GameLib.D3.Follow.prototype = Object.create(GameLib.D3.API.Follow.prototype);
GameLib.D3.Follow.prototype.constructor = GameLib.D3.Follow;
GameLib.D3.Follow.prototype.toApiComponent = function() {
GameLib.D3.Follow.prototype.toApiObject = function() {
var apiFollow = new GameLib.D3.API.Follow(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.currentComponent),
GameLib.Utils.IdOrNull(this.targetComponent),
this.targetPositionOffset.toApiVector(),
this.targetPositionOffset.toApiObject(),
this.minDistance,
this.moveSpeed,
GameLib.Utils.IdOrNull(this.parentEntity)

View File

@ -201,7 +201,7 @@ GameLib.D3.Game.prototype.updateInstance = function() {
* Converts a GameLib.D3.Game to a new GameLib.D3.API.Game
* @returns {GameLib.D3.API.Game}
*/
GameLib.D3.Game.prototype.toApiGame = function() {
GameLib.D3.Game.prototype.toApiObject = function() {
var apiImageFactory = null;
var apiCameras = [];
@ -213,14 +213,14 @@ GameLib.D3.Game.prototype.toApiGame = function() {
var apiEntityManager = null;
if (this.imageFactory instanceof GameLib.D3.ImageFactory) {
apiImageFactory = this.imageFactory.toApiImageFactory();
apiImageFactory = this.imageFactory.toApiObject();
}
if (this.cameras) {
apiCameras = this.cameras.map(
function(camera) {
if (camera instanceof GameLib.D3.Camera) {
return camera.toApiCamera();
return camera.toApiObject();
} else {
console.warn('camera not an instance of Camera');
throw new Error('camera not an instance of Camera');
@ -233,7 +233,7 @@ GameLib.D3.Game.prototype.toApiGame = function() {
apiComposers = this.composers.map(
function(composer) {
if (composer instanceof GameLib.D3.Composer) {
return composer.toApiComponent();
return composer.toApiObject();
} else {
console.warn('composer not an instance of Composer');
throw new Error('composer not an instance of Composer');
@ -246,7 +246,7 @@ GameLib.D3.Game.prototype.toApiGame = function() {
apiViewports = this.viewports.map(
function(viewport) {
if (viewport instanceof GameLib.D3.Viewport) {
return viewport.toApiComponent();
return viewport.toApiObject();
} else {
console.warn('viewport not an instance of Viewport');
throw new Error('viewport not an instance of Viewport');
@ -259,7 +259,7 @@ GameLib.D3.Game.prototype.toApiGame = function() {
apiRenderers = this.renderers.map(
function(renderer) {
if (renderer instanceof GameLib.D3.Renderer) {
return renderer.toApiComponent();
return renderer.toApiObject();
} else {
console.warn('renderer not an instance of Renderer');
throw new Error('renderer not an instance of Renderer');
@ -272,7 +272,7 @@ GameLib.D3.Game.prototype.toApiGame = function() {
apiRenderTargets = this.renderTargets.map(
function(renderTarget) {
if (renderTarget instanceof GameLib.D3.RenderTarget) {
return renderTarget.toApiComponent();
return renderTarget.toApiObject();
} else {
console.warn('renderTarget not an instance of RenderTarget');
throw new Error('renderTarget not an instance of RenderTarget');
@ -285,7 +285,7 @@ GameLib.D3.Game.prototype.toApiGame = function() {
apiSystems = this.systems.map(
function(system) {
if (system instanceof GameLib.System) {
return system.toApiComponent();
return system.toApiObject();
} else {
console.warn('system not an instance of System');
throw new Error('system not an instance of System');
@ -296,7 +296,7 @@ GameLib.D3.Game.prototype.toApiGame = function() {
if (this.entityManager) {
if (this.entityManager instanceof GameLib.EntityManager) {
apiEntityManager = this.entityManager.toApiEntityManager();
apiEntityManager = this.entityManager.toApiObject();
} else {
console.warn('entityManager not an instance of EntityManager');
throw new Error('entityManager not an instance of EntityManager');

View File

@ -115,7 +115,7 @@ GameLib.D3.ImageFactory.prototype.loadImage = function(
* Converts a GameLib.D3.ImageFactory to a GameLib.D3.API.ImageFactory
* @returns {GameLib.D3.API.ImageFactory}
*/
GameLib.D3.ImageFactory.prototype.toApiImageFactory = function() {
GameLib.D3.ImageFactory.prototype.toApiObject = function() {
return new GameLib.D3.API.ImageFactory(
this.id,
this.name,

View File

@ -104,7 +104,7 @@ GameLib.D3.Input.Drive.prototype.updateInstance = function() {
* GameLib.D3.Input.Drive to GameLib.D3.API.Input.Drive
* @returns {GameLib.D3.API.Input.Drive}
*/
GameLib.D3.Input.Drive.prototype.toApiComponent = function() {
GameLib.D3.Input.Drive.prototype.toApiObject = function() {
var apiInputDrive = new GameLib.D3.API.Input.Drive(
this.id,

View File

@ -91,7 +91,7 @@ GameLib.D3.Input.Editor.prototype.updateInstance = function() {
* GameLib.D3.Input.Editor to GameLib.D3.API.Input.Editor
* @returns {GameLib.D3.API.Input.Editor}
*/
GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
GameLib.D3.Input.Editor.prototype.toApiObject = function() {
var apiInputEditor = new GameLib.D3.API.Input.Editor(
this.id,
@ -212,6 +212,8 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity) {
return;
}
var gui = entity.getFirstComponent(GameLib.GUI);
if (intersects[0].selected) {
helper = new GameLib.D3.Helper(
@ -233,12 +235,12 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity) {
scene.instance.add(helper.instance);
var gui = entity.getFirstComponent(GameLib.GUI);
gui.instance.add(intersects[0], 'name');
gui.addObject(intersects[0]);
} else {
gui.removeObject(intersects[0]);
var components = entity.getComponents(GameLib.D3.Helper);
helper = components.reduce(
@ -266,6 +268,8 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(entity) {
console.warn('failed to locate helper object which should exist for ' + intersects[0].name);
}
}
gui.build();
}
}
}

View File

@ -201,18 +201,18 @@ GameLib.D3.Light.prototype.clone = function() {
* Converts a GameLib.D3.Light to a GameLib.D3.API.Light
* @returns {GameLib.D3.API.Light}
*/
GameLib.D3.Light.prototype.toApiLight = function() {
GameLib.D3.Light.prototype.toApiObject = function() {
return new GameLib.D3.API.Light(
this.id,
this.lightType,
this.name,
this.color.toApiColor(),
this.color.toApiObject(),
this.intensity,
this.position.toApiVector(),
this.targetPosition.toApiVector(),
this.quaternion.toApiQuaternion(),
this.position.toApiObject(),
this.targetPosition.toApiObject(),
this.quaternion.toApiObject(),
this.rotation,
this.scale.toApiVector(),
this.scale.toApiObject(),
this.distance,
this.decay,
this.power,

View File

@ -66,14 +66,14 @@ GameLib.D3.LookAt = function (
GameLib.D3.LookAt.prototype = Object.create(GameLib.D3.API.LookAt.prototype);
GameLib.D3.LookAt.prototype.constructor = GameLib.D3.LookAt;
GameLib.D3.LookAt.prototype.toApiComponent = function() {
GameLib.D3.LookAt.prototype.toApiObject = function() {
var apiLookAt = new GameLib.D3.API.LookAt(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.currentComponent),
GameLib.Utils.IdOrNull(this.targetComponent),
this.targetPositionOffset.toApiVector(),
this.targetPositionOffset.toApiObject(),
this.rotationSpeed,
GameLib.Utils.IdOrNull(this.parentEntity)
);

View File

@ -673,66 +673,66 @@ GameLib.D3.Material.prototype.clone = function() {
* Converts a GameLib.D3.Material to a GameLib.D3.API.Material
* @returns {GameLib.D3.API.Material}
*/
GameLib.D3.Material.prototype.toApiMaterial = function() {
GameLib.D3.Material.prototype.toApiObject = function() {
var apiAlphaMap = null;
if (this.alphaMap) {
apiAlphaMap = this.alphaMap.toApiTexture();
apiAlphaMap = this.alphaMap.toApiObject();
}
var apiAoMap = null;
if (this.aoMap) {
apiAoMap = this.aoMap.toApiTexture();
apiAoMap = this.aoMap.toApiObject();
}
var apiBumpMap = null;
if (this.bumpMap) {
apiBumpMap = this.bumpMap.toApiTexture();
apiBumpMap = this.bumpMap.toApiObject();
}
var apiDiffuseMap = null;
if (this.diffuseMap) {
apiDiffuseMap = this.diffuseMap.toApiTexture();
apiDiffuseMap = this.diffuseMap.toApiObject();
}
var apiDisplacementMap = null;
if (this.displacementMap) {
apiDisplacementMap = this.displacementMap.toApiTexture();
apiDisplacementMap = this.displacementMap.toApiObject();
}
var apiEmissiveMap = null;
if (this.emissiveMap) {
apiEmissiveMap = this.emissiveMap.toApiTexture();
apiEmissiveMap = this.emissiveMap.toApiObject();
}
var apiEnvironmentMap = null;
if (this.environmentMap) {
apiEnvironmentMap = this.environmentMap.toApiTexture();
apiEnvironmentMap = this.environmentMap.toApiObject();
}
var apiLightMap = null;
if (this.lightMap) {
apiLightMap = this.lightMap.toApiTexture();
apiLightMap = this.lightMap.toApiObject();
}
var apiMetalnessMap = null;
if (this.metalnessMap) {
apiMetalnessMap = this.metalnessMap.toApiTexture();
apiMetalnessMap = this.metalnessMap.toApiObject();
}
var apiNormalMap = null;
if (this.normalMap) {
apiNormalMap = this.normalMap.toApiTexture();
apiNormalMap = this.normalMap.toApiObject();
}
var apiRoughnessMap = null;
if (this.roughnessMap) {
apiRoughnessMap = this.roughnessMap.toApiTexture();
apiRoughnessMap = this.roughnessMap.toApiObject();
}
var apiSpecularMap = null;
if (this.specularMap) {
apiSpecularMap = this.specularMap.toApiTexture();
apiSpecularMap = this.specularMap.toApiObject();
}
return new GameLib.D3.API.Material(
@ -742,11 +742,11 @@ GameLib.D3.Material.prototype.toApiMaterial = function() {
this.opacity,
this.side,
this.transparent,
this.specular.toApiColor(),
this.specular.toApiObject(),
this.lightMapIntensity,
this.aoMapIntensity,
this.color.toApiColor(),
this.emissive.toApiColor(),
this.color.toApiObject(),
this.emissive.toApiObject(),
this.emissiveIntensity,
this.combine,
this.shininess,

View File

@ -434,12 +434,12 @@ GameLib.D3.Mesh.prototype.clone = function() {
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
* @returns {GameLib.D3.API.Mesh}
*/
GameLib.D3.Mesh.prototype.toApiMesh = function() {
GameLib.D3.Mesh.prototype.toApiObject = function() {
var apiSkeleton = null;
if (this.skeleton) {
apiSkeleton = this.skeleton.toApiSkeleton();
apiSkeleton = this.skeleton.toApiObject();
}
return new GameLib.D3.API.Mesh(
@ -448,7 +448,7 @@ GameLib.D3.Mesh.prototype.toApiMesh = function() {
this.name,
this.vertices.map(
function (vertex) {
return vertex.toApiVertex();
return vertex.toApiObject();
}
),
this.faces,
@ -459,14 +459,14 @@ GameLib.D3.Mesh.prototype.toApiMesh = function() {
apiSkeleton,
this.skinIndices,
this.skinWeights,
this.position.toApiVector(),
this.quaternion.toApiQuaternion(),
this.scale.toApiVector(),
this.localPosition.toApiVector(),
this.localRotation.toApiVector(),
this.localScale.toApiVector(),
this.up.toApiVector(),
this.modelMatrix.toApiMatrix(),
this.position.toApiObject(),
this.quaternion.toApiObject(),
this.scale.toApiObject(),
this.localPosition.toApiObject(),
this.localRotation.toApiObject(),
this.localScale.toApiObject(),
this.up.toApiObject(),
this.modelMatrix.toApiObject(),
GameLib.Utils.IdOrNull(this.parentEntity),
this.renderOrder
);

View File

@ -101,7 +101,7 @@ GameLib.D3.Pass.prototype.updateInstance = function() {
* GameLib.D3.Pass to GameLib.D3.API.Pass
* @returns {GameLib.D3.API.Pass}
*/
GameLib.D3.Pass.prototype.toApiComponent = function() {
GameLib.D3.Pass.prototype.toApiObject = function() {
var apiPass = new GameLib.D3.API.Pass(
this.id,

View File

@ -115,7 +115,7 @@ GameLib.D3.PathFollowing = function (
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
GameLib.D3.PathFollowing.prototype.constructor = GameLib.D3.PathFollowing;
GameLib.D3.PathFollowing.prototype.toApiComponent = function() {
GameLib.D3.PathFollowing.prototype.toApiObject = function() {
var apiPathFollowing = new GameLib.D3.API.PathFollowing(
this.id,
@ -125,20 +125,20 @@ GameLib.D3.PathFollowing.prototype.toApiComponent = function() {
GameLib.Utils.IdOrNull(this.raytraceMesh),
this.accelleration,
this.maxSpeed,
this.baseOffset.toApiVector(),
this.maxOffset.toApiVector(),
this.baseOffset.toApiObject(),
this.maxOffset.toApiObject(),
this.steeringSpeed,
this.targetOffset.toApiVector(),
this.currentOffset.toApiVector(),
this.targetOffset.toApiObject(),
this.currentOffset.toApiObject(),
this.currentPathValue,
this.currentSpeed,
this.direction,
this.raycaster.toApiRaycaster(),
this.currentPosition.toApiVector(),
this.futurePosition.toApiVector(),
this.up.toApiVector(),
this.rotationMatrix.toApiMatrix(),
this.rotationVector.toApiQuaternion(),
this.raycaster.toApiObject(),
this.currentPosition.toApiObject(),
this.futurePosition.toApiObject(),
this.up.toApiObject(),
this.rotationMatrix.toApiObject(),
this.rotationVector.toApiObject(),
GameLib.Utils.IdOrNull(this.parentEntity)
);

View File

@ -72,12 +72,12 @@ GameLib.D3.Raycaster.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
GameLib.D3.Raycaster.prototype.toApiRaycaster = function() {
GameLib.D3.Raycaster.prototype.toApiObject = function() {
return new GameLib.D3.API.Raycaster(
this.id,
this.name,
this.position.toApiVector(),
this.direction.toApiVector()
this.position.toApiObject(),
this.direction.toApiObject()
)
};

View File

@ -99,7 +99,7 @@ GameLib.D3.RenderTarget.prototype.updateInstance = function() {
* Render Target to API Render Target
* @returns {GameLib.D3.API.RenderTarget}
*/
GameLib.D3.RenderTarget.prototype.toApiComponent = function() {
GameLib.D3.RenderTarget.prototype.toApiObject = function() {
var apiRenderTarget = new GameLib.D3.API.RenderTarget(
this.id,

View File

@ -82,7 +82,7 @@ GameLib.D3.Renderer.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
GameLib.D3.Renderer.prototype.toApiComponent = function() {
GameLib.D3.Renderer.prototype.toApiObject = function() {
var apiRenderer = new GameLib.D3.API.Renderer(
this.id,
@ -92,7 +92,7 @@ GameLib.D3.Renderer.prototype.toApiComponent = function() {
this.width,
this.height,
this.preserveDrawingBuffer,
this.domElement.toApiDomElement(),
this.domElement.toApiObject(),
GameLib.Utils.IdOrNull(this.parentEntity)
);

View File

@ -204,34 +204,34 @@ GameLib.D3.Scene.prototype.createInstance = function() {
* Converts a GameLib.D3.Scene to a GameLib.D3.API.Scene
* @returns {GameLib.D3.API.Scene}
*/
GameLib.D3.Scene.prototype.toApiScene = function() {
GameLib.D3.Scene.prototype.toApiObject = function() {
var apiImageFactory = null;
if (this.imageFactory instanceof GameLib.D3.ImageFactory) {
apiImageFactory = this.imageFactory.toApiImageFactory();
apiImageFactory = this.imageFactory.toApiObject();
}
var apiMeshes = this.meshes.map(
function(mesh) {
return mesh.toApiMesh();
return mesh.toApiObject();
}
);
var apiLights = this.lights.map(
function(light) {
return light.toApiLight();
return light.toApiObject();
}
);
var apiTextures = this.textures.map(
function(texture) {
return texture.toApiTexture();
return texture.toApiObject();
}
);
var apiMaterials = this.materials.map(
function(material) {
return material.toApiMaterial();
return material.toApiObject();
}
);
@ -240,9 +240,9 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
this.name,
apiImageFactory,
apiMeshes,
this.position.toApiVector(),
this.quaternion.toApiQuaternion(),
this.scale.toApiVector(),
this.position.toApiObject(),
this.quaternion.toApiObject(),
this.scale.toApiObject(),
this.parentGameId,
apiLights,
apiTextures,

View File

@ -176,19 +176,19 @@ GameLib.D3.Skeleton.prototype.updateInstance = function() {
* Converts a GameLib.D3.Skeleton to GameLib.D3.API.Skeleton
* @returns {GameLib.D3.API.Skeleton}
*/
GameLib.D3.Skeleton.prototype.toApiSkeleton = function() {
GameLib.D3.Skeleton.prototype.toApiObject = function() {
var apiSkeleton = new GameLib.D3.API.Skeleton(
this.id,
this.name,
this.bones.map(
function (bone) {
return bone.toApiBone();
return bone.toApiObject();
}
),
this.boneInverses.map(
function (boneInverse) {
return boneInverse.toApiMatrix();
return boneInverse.toApiObject();
}
),
this.useVertexTexture,
@ -196,7 +196,7 @@ GameLib.D3.Skeleton.prototype.toApiSkeleton = function() {
this.boneTextureHeight,
this.boneMatrices.map(
function (boneMatrix) {
return boneMatrix.toApiMatrix();
return boneMatrix.toApiObject();
}
),
this.boneTexture,

View File

@ -73,14 +73,14 @@ GameLib.D3.Spline.prototype.updateInstance = function() {
* Converts a GameLib.D3.Spline to GameLib.D3.API.Spline
* @returns {GameLib.D3.API.Spline}
*/
GameLib.D3.Spline.prototype.toApiComponent = function() {
GameLib.D3.Spline.prototype.toApiObject = function() {
return new GameLib.D3.API.Spline(
this.id,
this.name,
this.vertices.map(
function (vertex) {
return vertex.toApiVector()
return vertex.toApiObject()
}
),
GameLib.Utils.IdOrNull(this.parentEntity)

View File

@ -248,7 +248,7 @@ GameLib.D3.Texture.prototype.clone = function() {
* Converts a GameLib.D3.Texture to a GameLib.D3.API.Texture
* @returns {GameLib.D3.API.Texture}
*/
GameLib.D3.Texture.prototype.toApiTexture = function() {
GameLib.D3.Texture.prototype.toApiObject = function() {
return new GameLib.D3.API.Texture(
this.id,
@ -257,7 +257,7 @@ GameLib.D3.Texture.prototype.toApiTexture = function() {
this.imagePath,
this.wrapS,
this.wrapT,
this.repeat.toApiVector(),
this.repeat.toApiObject(),
this.data,
this.format,
this.mapping,
@ -265,7 +265,7 @@ GameLib.D3.Texture.prototype.toApiTexture = function() {
this.minFilter,
this.textureType,
this.anisotropy,
this.offset.toApiVector(),
this.offset.toApiObject(),
this.generateMipmaps,
this.flipY,
this.mipmaps,

View File

@ -48,12 +48,12 @@ GameLib.D3.Vertex.prototype.constructor = GameLib.D3.Vertex;
* Converts a GameLib.D3.Vertex to GameLib.D3.API.Vertex
* @returns {GameLib.D3.API.Vertex}
*/
GameLib.D3.Vertex.prototype.toApiVertex = function() {
GameLib.D3.Vertex.prototype.toApiObject = function() {
return new GameLib.D3.API.Vertex(
this.position.toApiVector(),
this.position.toApiObject(),
this.boneWeights.map(function(boneWeight){
return boneWeight.toApiBoneWeight();
return boneWeight.toApiObject();
})
);

View File

@ -138,7 +138,7 @@ GameLib.D3.Viewport.prototype.updateInstance = function() {
* GameLib.D3.Viewport to GameLib.D3.API.Viewport
* @returns {GameLib.D3.API.Viewport}
*/
GameLib.D3.Viewport.prototype.toApiComponent = function() {
GameLib.D3.Viewport.prototype.toApiObject = function() {
var apiViewport = new GameLib.D3.API.Viewport(
this.id,

View File

@ -52,7 +52,7 @@ GameLib.DomElement.prototype.updateInstance = function() {
* Converts runtime vector to API Vector
* @returns {GameLib.API.DomElement}
*/
GameLib.DomElement.prototype.toApiDomElement = function() {
GameLib.DomElement.prototype.toApiObject = function() {
return new GameLib.API.DomElement(
this.id,
this.name,

View File

@ -209,17 +209,17 @@ GameLib.EntityManager.prototype.queryComponents = function(constructor) {
* Converts a GameLib.Entity to GameLib.API.Entity
* @returns {GameLib.API.EntityManager}
*/
GameLib.EntityManager.prototype.toApiEntityManager = function() {
GameLib.EntityManager.prototype.toApiObject = function() {
var apiEntities = this.entities.map(
function (entity) {
return entity.toApiEntity();
return entity.toApiObject();
}
);
// var apiSystems = this.systems.map(
// function (system) {
// return system.toApiSystem();
// return system.toApiObject();
// }
// );

View File

@ -192,11 +192,11 @@ GameLib.Entity.prototype.updateInstance = function() {
* Converts a GameLib.Entity to GameLib.API.Entity
* @returns {GameLib.API.Entity}
*/
GameLib.Entity.prototype.toApiEntity = function() {
GameLib.Entity.prototype.toApiObject = function() {
var apiComponents = this.components.map(
function(component) {
return component.toApiComponent();
return component.toApiObject();
}
);

View File

@ -4,6 +4,7 @@
* @param id
* @param name
* @param domElement
* @param objects
* @param parentEntity
* @constructor
*/
@ -12,6 +13,7 @@ GameLib.GUI = function(
id,
name,
domElement,
objects,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(gui)) {
@ -45,6 +47,11 @@ GameLib.GUI = function(
}
this.domElement = domElement;
if (GameLib.Utils.UndefinedOrNull(objects)) {
objects = [];
}
this.objects = objects;
this.instance = this.createInstance();
};
@ -60,11 +67,15 @@ GameLib.GUI.prototype.createInstance = function(update) {
var instance = null;
if (update) {
this.instance = new this.gui( { autoPlace: false } );
instance = this.instance;
} else {
instance = new this.gui( { autoPlace: false } );
}
instance = new dat.GUI( { autoPlace: false } );
}
return instance;
};
@ -75,3 +86,68 @@ GameLib.GUI.prototype.createInstance = function(update) {
GameLib.GUI.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
GameLib.GUI.prototype.addObject = function(object) {
this.objects.push(object);
};
GameLib.GUI.prototype.removeObject = function(object) {
var index = this.objects.indexOf(object);
if (index === -1) {
console.warn('could not find object to remove');
return false;
} else {
this.objects.splice(index, 1);
}
return true;
};
GameLib.GUI.prototype.build = function() {
this.instance.removeAllFolders();
var discoveredObjects = [];
this.objects.map(
function(object) {
if (object.idToObject) {
for (var property in object.idToObject) {
if (object.idToObject.hasOwnProperty(property)) {
discoveredObjects.push(object.idToObject[property]);
}
}
}
}.bind(this)
);
discoveredObjects.map(
function(object) {
var apiObject = object.toApiObject();
var folder = this.instance.addFolder(apiObject.name);
for (var property in apiObject) {
if (
apiObject.hasOwnProperty(property) &&
object.hasOwnProperty(property)
) {
if (typeof (object[property]) === 'object') {
console.log('ignored: ' + property);
} else {
folder.add(object, property);
}
}
}
}.bind(this)
);
};

View File

@ -144,12 +144,12 @@ GameLib.Matrix4.prototype.updateInstance = function() {
* GameLib.Matrix4 to GameLib.API.Matrix4
* @returns {*}
*/
GameLib.Matrix4.prototype.toApiMatrix = function () {
GameLib.Matrix4.prototype.toApiObject = function () {
return this.rows.map(
function(row) {
if (row instanceof GameLib.Vector4) {
return row.toApiVector();
return row.toApiObject();
} else {
console.warn('Incompatible conversion to API matrix for vector: ', row);
throw new Error('Incompatible conversion to API matrix for a vector');

View File

@ -59,7 +59,7 @@ GameLib.Mouse.prototype.updateInstance = function() {
* Converts runtime vector to API Vector
* @returns {GameLib.API.Mouse}
*/
GameLib.Mouse.prototype.toApiMouse = function() {
GameLib.Mouse.prototype.toApiObject = function() {
return new GameLib.API.Mouse(
this.id,
this.name,

View File

@ -100,13 +100,13 @@ GameLib.Quaternion.prototype.updateInstance = function() {
* Converts runtime quaternion to API quaternion
* @returns {*}
*/
GameLib.Quaternion.prototype.toApiQuaternion = function() {
GameLib.Quaternion.prototype.toApiObject = function() {
return new GameLib.API.Quaternion(
this.x,
this.y,
this.z,
this.w,
this.axis.toApiVector(),
this.axis.toApiObject(),
this.angle
);
};

View File

@ -103,15 +103,15 @@ GameLib.System.prototype.start = function() {
function(entity) {
var stats = entity.getFirstComponent(GameLib.D3.Stats);
stats.instance.dom.style.position = 'absolute';
// stats.instance.dom.style.float = 'left';
stats.instance.dom.style.top = '34px';
stats.instance.dom.style.left = 'unset';
stats.instance.dom.style.left = '0px';
stats.domElement.instance.parentElement.appendChild(stats.instance.dom);
var gui = entity.getFirstComponent(GameLib.GUI);
gui.instance.domElement.style.position = 'absolute';
gui.instance.domElement.style.top = '34px';
gui.instance.domElement.style.right = '0px';
gui.instance.domElement.getElementsByTagName('ul')[0].style.maxHeight = window.innerHeight - 93 + 'px';
gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
}
)
@ -274,16 +274,16 @@ GameLib.System.prototype.stop = function() {
* Converts runtime vector to API Vector
* @returns {GameLib.API.System}
*/
GameLib.System.prototype.toApiSystem = function() {
GameLib.System.prototype.toApiObject = function() {
var apiDomElement = null;
if (this.domElement instanceof GameLib.DomElement) {
apiDomElement = this.domElement.toApiDomElement();
apiDomElement = this.domElement.toApiObject();
}
var apiDomStats = null;
if (this.domStats instanceof GameLib.DomElement) {
apiDomStats = this.domStats.toApiDomElement();
apiDomStats = this.domStats.toApiObject();
}
return new GameLib.API.System(

View File

@ -83,7 +83,7 @@ GameLib.Vector2.prototype.updateInstance = function() {
* Converts runtime vector to API Vector
* @returns {GameLib.API.Vector2}
*/
GameLib.Vector2.prototype.toApiVector = function() {
GameLib.Vector2.prototype.toApiObject = function() {
return new GameLib.API.Vector2(
this.x,
this.y

View File

@ -87,7 +87,7 @@ GameLib.Vector3.prototype.updateInstance = function() {
/**
* Converts runtime vector to API Vector
*/
GameLib.Vector3.prototype.toApiVector = function() {
GameLib.Vector3.prototype.toApiObject = function() {
return new GameLib.API.Vector3(
this.x,
this.y,

View File

@ -86,7 +86,7 @@ GameLib.Vector4.prototype.updateInstance = function() {
/**
* Converts runtime vector to API Vector
*/
GameLib.Vector4.prototype.toApiVector = function() {
GameLib.Vector4.prototype.toApiObject = function() {
return new GameLib.API.Vector4(
this.x,
this.y,