streamlined object to api to runtime

beta.r3js.org
Theunis J. Botha 2017-01-05 19:34:28 +01:00
parent 87ec110b49
commit 76e36e0fa7
36 changed files with 1126 additions and 882 deletions

View File

@ -11,3 +11,12 @@ GameLib.API.EntityManager = function(
} }
this.entities = entities; this.entities = entities;
}; };
/**
* Creates an API entity manager from an Object entity manager
* @param objectEntityManager
* @constructor
*/
GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager) {
};

View File

@ -53,4 +53,17 @@ GameLib.API.Entity.prototype.removeComponent = function(component) {
this.components.splice(index, 1); this.components.splice(index, 1);
return true; return true;
}; };
/**
* Returns an API entity from an Object entity
* @param objectEntity
* @constructor
*/
GameLib.API.Entity.FromObjectEntity = function(objectEntity) {
return new GameLib.API.Entity(
objectEntity.id,
objectEntity.name,
objectEntity.components
)
};

View File

@ -131,3 +131,36 @@ GameLib.API.Matrix4.prototype.identity = function () {
]; ];
}; };
/**
* Returns an API matrix from an Object matrix
* @param objectMatrix
* @constructor
*/
GameLib.API.Matrix4.FromObjectMatrix = function(objectMatrix) {
return new GameLib.API.Matrix4(
new GameLib.API.Vector4(
objectMatrix.rows[0].x,
objectMatrix.rows[0].y,
objectMatrix.rows[0].z,
objectMatrix.rows[0].w
),
new GameLib.API.Vector4(
objectMatrix.rows[1].x,
objectMatrix.rows[1].y,
objectMatrix.rows[1].z,
objectMatrix.rows[1].w
),
new GameLib.API.Vector4(
objectMatrix.rows[2].x,
objectMatrix.rows[2].y,
objectMatrix.rows[2].z,
objectMatrix.rows[2].w
),
new GameLib.API.Vector4(
objectMatrix.rows[3].x,
objectMatrix.rows[3].y,
objectMatrix.rows[3].z,
objectMatrix.rows[3].w
)
)
};

View File

@ -194,4 +194,24 @@ GameLib.API.Quaternion.prototype.slerp = function (quaternion, t) {
this.w = this.instance.w; this.w = this.instance.w;
return this; return this;
};
/**
* Returns an API quaternion from an Object quaternion
* @param objectQuaternion
* @constructor
*/
GameLib.API.Quaternion.FromObjectQuaternion = function (objectQuaternion) {
return new GameLib.API.Quaternion(
objectQuaternion.x,
objectQuaternion.y,
objectQuaternion.z,
objectQuaternion.w,
new GameLib.API.Vector3(
objectQuaternion.axis.x,
objectQuaternion.axis.y,
objectQuaternion.axis.z
),
objectQuaternion.angle
)
}; };

View File

@ -17,4 +17,16 @@ GameLib.API.Vector2.prototype.copy = function () {
this.x, this.x,
this.y this.y
); );
}; };
/**
* Returns an API vector from an Object vector
* @param objectVector
* @constructor
*/
GameLib.API.Vector2.FromObjectVector = function (objectVector) {
return new GameLib.API.Vector2(
objectVector.x,
objectVector.y
)
};

View File

@ -251,4 +251,17 @@ GameLib.API.Vector3.prototype.reflect = function(normal) {
GameLib.API.Vector3.prototype.angleTo = function (v) { GameLib.API.Vector3.prototype.angleTo = function (v) {
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) ); var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
return Math.acos( exports.Math.clamp( theta, - 1, 1 ) ); return Math.acos( exports.Math.clamp( theta, - 1, 1 ) );
}; };
/**
* Returns an API vector from an Object vector
* @param objectVector
* @constructor
*/
GameLib.API.Vector3.FromObjectVector = function (objectVector) {
return new GameLib.API.Vector3(
objectVector.x,
objectVector.y,
objectVector.z
)
};

View File

@ -19,4 +19,18 @@ GameLib.API.Vector4 = function (x, y, z, w) {
w = 1; w = 1;
} }
this.w = w; this.w = w;
}; };
/**
* Returns an API vector from an Object vector
* @param objectVector
* @constructor
*/
GameLib.API.Vector4.FromObjectVector = function (objectVector) {
return new GameLib.API.Vector2(
objectVector.x,
objectVector.y,
objectVector.z,
objectVector.w
)
};

View File

@ -43,6 +43,7 @@ GameLib.Component.COMPONENT_MESH = 0x8;
GameLib.Component.COMPONENT_SPLINE = 0x9; GameLib.Component.COMPONENT_SPLINE = 0x9;
GameLib.Component.COMPONENT_LIGHT = 0xa; GameLib.Component.COMPONENT_LIGHT = 0xa;
GameLib.Component.COMPONENT_INPUT_DRIVE = 0xb; GameLib.Component.COMPONENT_INPUT_DRIVE = 0xb;
GameLib.Component.COMPONENT_MATERIAL = 0xc;
GameLib.Component.prototype.toApiComponent = function() { GameLib.Component.prototype.toApiComponent = function() {
return this.id; return this.id;

View File

@ -60,4 +60,22 @@ GameLib.D3.API.Bone = function (
up = new GameLib.API.Vector3(0,1,0); up = new GameLib.API.Vector3(0,1,0);
} }
this.up = up; this.up = up;
}; };
/**
* Returns an API bone from an Object bone
* @param objectBone
* @constructor
*/
GameLib.D3.API.Bone.FromObjectBone = function(objectBone) {
return new GameLib.D3.API.Bone(
objectBone.id,
objectBone.name,
objectBone.childBoneIds,
objectBone.parentBoneIds,
GameLib.API.Vector3.FromObjectVector(objectBone.position),
GameLib.API.Quaternion.FromObjectQuaternion(objectBone.quaternion),
GameLib.API.Vector3.FromObjectVector(objectBone.scale),
GameLib.API.Vector3.FromObjectVector(objectBone.up)
);
};

View File

@ -137,3 +137,32 @@ GameLib.D3.API.Camera = function(
GameLib.D3.API.Camera.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Camera.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera; GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
/**
* Creates an API camera from an Object camera
* @param objectCamera
* @constructor
*/
GameLib.D3.API.Camera.FromObjectCamera = function(objectCamera) {
return new GameLib.D3.API.Camera(
objectCamera.id,
objectCamera.cameraType,
objectCamera.name,
objectCamera.fov,
objectCamera.aspect,
objectCamera.near,
objectCamera.far,
GameLib.API.Vector3.FromObjectVector(objectCamera.position),
GameLib.API.Vector3.FromObjectVector(objectCamera.lookAt),
objectCamera.minX,
objectCamera.maxX,
objectCamera.minY,
objectCamera.maxY,
objectCamera.minZ,
objectCamera.maxZ,
GameLib.API.Quaternion.FromObjectQuaternion(objectCamera.quaternion),
objectCamera.parentEntity
);
};

View File

@ -1,4 +1,4 @@
GameLib.D3.API.Color = function ApiColor(r, g, b, a) { GameLib.D3.API.Color = function (r, g, b, a) {
if (GameLib.Utils.UndefinedOrNull(r)) { if (GameLib.Utils.UndefinedOrNull(r)) {
r = 1; r = 1;
@ -20,4 +20,20 @@ GameLib.D3.API.Color = function ApiColor(r, g, b, a) {
} }
this.a = a; this.a = a;
}; };
/**
* Returns an API color from an Object color
* @param objectColor
* @constructor
*/
GameLib.D3.API.Color.FromObjectColor = function(objectColor) {
return new GameLib.D3.API.Color(
objectColor.r,
objectColor.g,
objectColor.b,
objectColor.a
);
};

View File

@ -121,4 +121,30 @@ GameLib.D3.API.Light = function(
}; };
GameLib.D3.API.Light.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Light.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light; GameLib.D3.API.Light.prototype.constructor = GameLib.D3.API.Light;
/**
* Returns an API light from an Object light
* @param objectLight
* @constructor
*/
GameLib.D3.API.Light.FromObjectLight = function(objectLight) {
return new GameLib.D3.API.Light(
objectLight.id,
objectLight.lightType,
objectLight.name,
GameLib.D3.API.Color.FromObjectColor(objectLight.color),
objectLight.intensity,
GameLib.API.Vector3.FromObjectVector(objectLight.position),
GameLib.API.Vector3.FromObjectVector(objectLight.targetPosition),
GameLib.API.Quaternion.FromObjectQuaternion(objectLight.quaternion),
GameLib.API.Vector3.FromObjectVector(objectLight.rotation),
GameLib.API.Vector3.FromObjectVector(objectLight.scale),
objectLight.distance,
objectLight.decay,
objectLight.power,
objectLight.angle,
objectLight.penumbra,
objectLight.parentEntity
);
};

View File

@ -6,7 +6,6 @@
* @param opacity * @param opacity
* @param side * @param side
* @param transparent * @param transparent
* @param maps
* @param specular * @param specular
* @param lightMapIntensity * @param lightMapIntensity
* @param aoMapIntensity * @param aoMapIntensity
@ -57,6 +56,19 @@
* @param pointSizeAttenuation * @param pointSizeAttenuation
* @param spriteRotation * @param spriteRotation
* @param envMapIntensity * @param envMapIntensity
* @param alphaMap
* @param aoMap
* @param bumpMap
* @param diffuseMap
* @param displacementMap
* @param emissiveMap
* @param environmentMap
* @param lightMap
* @param metalnessMap
* @param normalMap
* @param roughnessMap
* @param specularMap
* @param parentEntity
* @constructor * @constructor
*/ */
GameLib.D3.API.Material = function( GameLib.D3.API.Material = function(
@ -66,7 +78,6 @@ GameLib.D3.API.Material = function(
opacity, opacity,
side, side,
transparent, transparent,
maps,
specular, specular,
lightMapIntensity, lightMapIntensity,
aoMapIntensity, aoMapIntensity,
@ -116,8 +127,42 @@ GameLib.D3.API.Material = function(
pointSize, pointSize,
pointSizeAttenuation, pointSizeAttenuation,
spriteRotation, spriteRotation,
envMapIntensity envMapIntensity,
alphaMap,
aoMap,
bumpMap,
diffuseMap,
displacementMap,
emissiveMap,
environmentMap,
lightMap,
metalnessMap,
normalMap,
roughnessMap,
specularMap,
parentEntity
) { ) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_MATERIAL,
{
alphaMap : GameLib.D3.Texture,
aoMap : GameLib.D3.Texture,
bumpMap : GameLib.D3.Texture,
diffuseMap : GameLib.D3.Texture,
displacementMap : GameLib.D3.Texture,
emissiveMap : GameLib.D3.Texture,
environmentMap : GameLib.D3.Texture,
lightMap : GameLib.D3.Texture,
metalnessMap : GameLib.D3.Texture,
normalMap : GameLib.D3.Texture,
roughnessMap : GameLib.D3.Texture,
specularMap : GameLib.D3.Texture
},
false,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) { if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId(); id = GameLib.Utils.RandomId();
} }
@ -148,11 +193,6 @@ GameLib.D3.API.Material = function(
} }
this.transparent = transparent; this.transparent = transparent;
if (GameLib.Utils.UndefinedOrNull(maps)) {
maps = GameLib.D3.API.TextureMapTemplate();
}
this.maps = maps;
if (GameLib.Utils.UndefinedOrNull(specular)) { if (GameLib.Utils.UndefinedOrNull(specular)) {
specular = new GameLib.D3.API.Color(0.06, 0.06, 0.06, 0.06); specular = new GameLib.D3.API.Color(0.06, 0.06, 0.06, 0.06);
} }
@ -402,4 +442,202 @@ GameLib.D3.API.Material = function(
envMapIntensity = 1.0; envMapIntensity = 1.0;
} }
this.envMapIntensity = envMapIntensity; this.envMapIntensity = envMapIntensity;
};
if (GameLib.Utils.UndefinedOrNull(alphaMap)) {
alphaMap = null;
}
this.alphaMap = alphaMap;
if (GameLib.Utils.UndefinedOrNull(aoMap)) {
aoMap = null;
}
this.aoMap = aoMap;
if (GameLib.Utils.UndefinedOrNull(bumpMap)) {
bumpMap = null;
}
this.bumpMap = bumpMap;
if (GameLib.Utils.UndefinedOrNull(diffuseMap)) {
diffuseMap = null;
}
this.diffuseMap = diffuseMap;
if (GameLib.Utils.UndefinedOrNull(displacementMap)) {
displacementMap = null;
}
this.displacementMap = displacementMap;
if (GameLib.Utils.UndefinedOrNull(emissiveMap)) {
emissiveMap = null;
}
this.emissiveMap = emissiveMap;
if (GameLib.Utils.UndefinedOrNull(lightMap)) {
lightMap = null;
}
this.lightMap = lightMap;
if (GameLib.Utils.UndefinedOrNull(metalnessMap)) {
metalnessMap = null;
}
this.metalnessMap = metalnessMap;
if (GameLib.Utils.UndefinedOrNull(normalMap)) {
normalMap = null;
}
this.normalMap = normalMap;
if (GameLib.Utils.UndefinedOrNull(roughnessMap)) {
roughnessMap = null;
}
this.roughnessMap = roughnessMap;
if (GameLib.Utils.UndefinedOrNull(specularMap)) {
specularMap = null;
}
this.specularMap = specularMap;
};
GameLib.D3.API.Material.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Material.prototype.constructor = GameLib.D3.API.Material;
/**
* Returns an API Material from an Object material
* @param objectMaterial
* @constructor
*/
GameLib.D3.API.Material.FromObjectMaterial = function(objectMaterial) {
var apiAlphaMap = null;
var apiAoMap = null;
var apiBumpMap = null;
var apiDiffuseMap = null;
var apiDisplacementMap = null;
var apiEmissiveMap = null;
var apiEnvironmentMap = null;
var apiLightMap = null;
var apiMetalnessMap = null;
var apiNormalMap = null;
var apiRoughnessMap = null;
var apiSpecularMap = null;
if (objectMaterial.alphaMap) {
apiAlphaMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.alphaMap);
}
if (objectMaterial.aoMap) {
apiAoMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.aoMap);
}
if (objectMaterial.bumpMap) {
apiBumpMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.bumpMap);
}
if (objectMaterial.diffuseMap) {
apiDiffuseMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.diffuseMap);
}
if (objectMaterial.displacementMap) {
apiDisplacementMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.displacementMap);
}
if (objectMaterial.emissiveMap) {
apiEmissiveMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.emissiveMap);
}
if (objectMaterial.environmentMap) {
apiEnvironmentMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.environmentMap);
}
if (objectMaterial.lightMap) {
apiLightMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.lightMap);
}
if (objectMaterial.metalnessMap) {
apiMetalnessMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.metalnessMap);
}
if (objectMaterial.normalMap) {
apiNormalMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.normalMap);
}
if (objectMaterial.roughnessMap) {
apiRoughnessMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.roughnessMap);
}
if (objectMaterial.specularMap) {
apiSpecularMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.specularMap);
}
return new GameLib.D3.API.Material(
objectMaterial.id,
objectMaterial.materialType,
objectMaterial.name,
objectMaterial.opacity,
objectMaterial.side,
objectMaterial.transparent,
GameLib.D3.API.Color.FromObjectColor(objectMaterial.specular),
objectMaterial.lightMapIntensity,
objectMaterial.aoMapIntensity,
GameLib.D3.API.Color.FromObjectColor(objectMaterial.color),
GameLib.D3.API.Color.FromObjectColor(objectMaterial.emissive),
objectMaterial.emissiveIntensity,
objectMaterial.combine,
objectMaterial.shininess,
objectMaterial.reflectivity,
objectMaterial.refractionRatio,
objectMaterial.fog,
objectMaterial.wireframe,
objectMaterial.wireframeLineWidth,
objectMaterial.wireframeLineCap,
objectMaterial.wireframeLineJoin,
objectMaterial.vertexColors,
objectMaterial.skinning,
objectMaterial.morphTargets,
objectMaterial.morphNormals,
objectMaterial.lineWidth,
objectMaterial.lineCap,
objectMaterial.lineJoin,
objectMaterial.dashSize,
objectMaterial.gapWidth,
objectMaterial.blending,
objectMaterial.blendSrc,
objectMaterial.blendDst,
objectMaterial.blendEquation,
objectMaterial.depthTest,
objectMaterial.depthFunc,
objectMaterial.depthWrite,
objectMaterial.polygonOffset,
objectMaterial.polygonOffsetFactor,
objectMaterial.polygonOffsetUnits,
objectMaterial.alphaTest,
objectMaterial.clippingPlanes,
objectMaterial.clipShadows,
objectMaterial.visible,
objectMaterial.overdraw,
objectMaterial.shading,
objectMaterial.bumpScale,
objectMaterial.normalScale,
objectMaterial.displacementScale,
objectMaterial.displacementBias,
objectMaterial.roughness,
objectMaterial.metalness,
objectMaterial.pointSize,
objectMaterial.pointSizeAttenuation,
objectMaterial.spriteRotation,
objectMaterial.envMapIntensity,
apiAlphaMap,
apiAoMap,
apiBumpMap,
apiDiffuseMap,
apiDisplacementMap,
apiEmissiveMap,
apiEnvironmentMap,
apiLightMap,
apiMetalnessMap,
apiNormalMap,
apiRoughnessMap,
apiSpecularMap
)
};

View File

@ -166,4 +166,51 @@ GameLib.D3.API.Mesh = function(
}; };
GameLib.D3.API.Mesh.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Mesh.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Mesh.prototype.constructor = GameLib.D3.API.Mesh; GameLib.D3.API.Mesh.prototype.constructor = GameLib.D3.API.Mesh;
/**
* Returns an API Mesh from an Object mesh
* @param objectMesh
* @constructor
*/
GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
var apiSkeleton = null;
if (objectMesh.skeleton) {
apiSkeleton = GameLib.D3.API.Skeleton.FromObjectSkeleton(objectMesh.skeleton);
}
return new GameLib.D3.API.Mesh(
objectMesh.id,
objectMesh.meshType,
objectMesh.name,
objectMesh.vertices.map(
function (objectVertex) {
return GameLib.D3.API.Vertex.FromObjectVertex(objectVertex);
}
),
objectMesh.faces,
objectMesh.faceVertexUvs,
objectMesh.materials.map(
function (objectMaterial) {
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial);
}
),
objectMesh.parentMesh,
objectMesh.parentScene,
apiSkeleton,
objectMesh.skinIndices,
objectMesh.skinWeights,
GameLib.API.Vector3.FromObjectVector(objectMesh.position),
GameLib.API.Quaternion.FromObjectQuaternion(objectMesh.quaternion),
GameLib.API.Vector3.FromObjectVector(objectMesh.scale),
GameLib.API.Vector3.FromObjectVector(objectMesh.localPosition),
GameLib.API.Vector3.FromObjectVector(objectMesh.localRotation),
GameLib.API.Vector3.FromObjectVector(objectMesh.localScale),
GameLib.API.Vector3.FromObjectVector(objectMesh.up),
GameLib.API.Matrix4.FromObjectMatrix(objectMesh.modelMatrix),
objectMesh.parentEntity,
objectMesh.renderOrder
);
};

View File

@ -102,3 +102,47 @@ GameLib.D3.API.Scene = function(
} }
this.activeCameraIndex = activeCameraIndex; this.activeCameraIndex = activeCameraIndex;
}; };
/**
* Returns an API scene from an Object scene
* @param objectScene
* @constructor
*/
GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
var apiEntityManager = null;
if (objectScene.entityManager) {
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectScene.entityManager);
}
return new GameLib.D3.API.Scene(
objectScene.id,
objectScene.path,
objectScene.name,
objectScene.meshes.map(
function (objectMesh) {
return GameLib.D3.API.Mesh.FromObjectMesh(objectMesh)
}
),
GameLib.API.Vector3.FromObjectVector(objectScene.position),
GameLib.API.Quaternion.FromObjectQuaternion(objectScene.quaternion),
GameLib.API.Vector3.FromObjectVector(objectScene.scale),
objectScene.parentSceneId,
objectScene.lights.map(
function (objectLight) {
return GameLib.D3.API.Light.FromObjectLight(objectLight)
}
),
[], //TODO : implement worlds here
apiEntityManager,
[], //TODO : implement shapes here
objectScene.cameras.map(
function (objectCamera) {
return GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
}
),
objectScene.activeCameraIndex
);
};

View File

@ -77,3 +77,33 @@ GameLib.D3.API.Skeleton = function (
this.boneTexture = boneTexture; this.boneTexture = boneTexture;
}; };
/**
* Creates an API skeleton from an Object skeleton
* @param objectSkeleton
* @constructor
*/
GameLib.D3.API.Skeleton.FromObjectSkeleton = function(objectSkeleton) {
return new GameLib.D3.API.Skeleton(
objectSkeleton.id,
objectSkeleton.name,
objectSkeleton.bones.map(
function (objectBone) {
return GameLib.D3.API.Bone.FromObjectBone(objectBone);
}
),
objectSkeleton.boneInverses.map(
function (boneInverse) {
return GameLib.D3.API.Matrix4.FromObjectMatrix(boneInverse);
}
),
objectSkeleton.useVertexTexture,
objectSkeleton.boneTextureWidth,
objectSkeleton.boneTextureHeight,
objectSkeleton.boneMatrices.map(
function (boneMatrix) {
return GameLib.D3.API.Matrix4.FromObjectMatrix(boneMatrix);
}
),
objectSkeleton.boneTexture
);
};

View File

@ -1,20 +0,0 @@
/**
* Raw API Texture Map Template - should match the contents of the Material Schema (maps property)
* @constructor
*/
GameLib.D3.API.TextureMapTemplate = function() {
return new GameLib.D3.TextureMaps(
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap()
);
};

View File

@ -151,3 +151,34 @@ GameLib.D3.API.Texture = function(
} }
this.encoding = encoding; this.encoding = encoding;
}; };
/**
* Creates an API texture from Object data
* @param objectTexture
* @constructor
*/
GameLib.D3.API.Texture.FromObjectTexture = function(objectTexture) {
new GameLib.D3.API.Texture(
objectTexture.id,
objectTexture.textureType,
objectTexture.name,
objectTexture.imagePath,
objectTexture.wrapS,
objectTexture.wrapT,
GameLib.API.Vector2.FromObjectVector(objectTexture.repeat),
objectTexture.data,
objectTexture.format,
objectTexture.mapping,
objectTexture.magFilter,
objectTexture.minFilter,
objectTexture.textureType,
objectTexture.anisotropy,
GameLib.API.Vector2.FromObjectVector(objectTexture.offset),
objectTexture.generateMipmaps,
objectTexture.flipY,
objectTexture.mipmaps,
objectTexture.unpackAlignment,
objectTexture.premultiplyAlpha,
objectTexture.encoding
)
};

View File

@ -19,3 +19,15 @@ GameLib.D3.API.Vertex = function(
} }
this.boneWeights = boneWeights; this.boneWeights = boneWeights;
}; };
/**
* Creates an API vertex from an Object vertex
* @param objectVertex
* @constructor
*/
GameLib.D3.API.Vertex.FromObjectVertex = function(objectVertex) {
return new GameLib.D3.API.Vertex(
GameLib.API.Vector3.FromObjectVector(objectVertex.position),
objectVertex.boneWeights
);
};

View File

@ -4,7 +4,7 @@
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param apiBone GameLib.D3.API.Bone * @param apiBone GameLib.D3.API.Bone
*/ */
GameLib.D3.Bone = function RuntimeBone( GameLib.D3.Bone = function (
graphics, graphics,
apiBone apiBone
) { ) {
@ -121,48 +121,16 @@ GameLib.D3.Bone.prototype.toApiBone = function() {
* Returns a GameLib.D3.Bone from a bone Object * Returns a GameLib.D3.Bone from a bone Object
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param objectBone Object * @param objectBone Object
* @returns GameLib.D3.Bone * @returns {GameLib.D3.Bone}
* @constructor * @constructor
*/ */
GameLib.D3.Bone.FromObjectBone = function( GameLib.D3.Bone.FromObjectBone = function(
graphics, graphics,
objectBone objectBone
) { ) {
var apiBone = new GameLib.D3.API.Bone( var apiBone = GameLib.D3.API.Bone.FromObjectBone(objectBone);
objectBone.id,
objectBone.name,
objectBone.childBoneIds,
objectBone.parentBoneIds,
new GameLib.API.Vector3(
objectBone.position.x,
objectBone.position.y,
objectBone.position.z
),
new GameLib.API.Quaternion(
objectBone.quaternion.x,
objectBone.quaternion.y,
objectBone.quaternion.z,
objectBone.quaternion.w,
new GameLib.API.Vector3(
objectBone.quaternion.axis.x,
objectBone.quaternion.axis.y,
objectBone.quaternion.axis.z
),
objectBone.quaternion.angle
),
new GameLib.API.Vector3(
objectBone.scale.x,
objectBone.scale.y,
objectBone.scale.z
),
new GameLib.API.Vector3(
objectBone.up.x,
objectBone.up.y,
objectBone.up.z
)
);
var bone = new GameLib.D3.Bone( var bone = GameLib.D3.Bone(
graphics, graphics,
apiBone apiBone
); );

View File

@ -174,44 +174,7 @@ GameLib.D3.Camera.prototype.toApiCamera = function() {
*/ */
GameLib.D3.Camera.FromObjectCamera = function(graphics, objectCamera) { GameLib.D3.Camera.FromObjectCamera = function(graphics, objectCamera) {
var apiCamera = new GameLib.D3.API.Camera( var apiCamera = GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
objectCamera.id,
objectCamera.cameraType,
objectCamera.name,
objectCamera.fov,
objectCamera.aspect,
objectCamera.near,
objectCamera.far,
new GameLib.API.Vector3(
objectCamera.position.x,
objectCamera.position.y,
objectCamera.position.z
),
new GameLib.API.Vector3(
objectCamera.lookAt.x,
objectCamera.lookAt.y,
objectCamera.lookAt.z
),
objectCamera.minX,
objectCamera.maxX,
objectCamera.minY,
objectCamera.maxY,
objectCamera.minZ,
objectCamera.maxZ,
new GameLib.API.Quaternion(
objectCamera.quaternion.x,
objectCamera.quaternion.y,
objectCamera.quaternion.z,
objectCamera.quaternion.w,
new GameLib.API.Vector3(
objectCamera.quaternion.axis.x,
objectCamera.quaternion.axis.y,
objectCamera.quaternion.axis.z
),
objectCamera.quaternion.angle
),
objectCamera.parentEntity
);
return new GameLib.D3.Camera( return new GameLib.D3.Camera(
graphics, graphics,

View File

@ -6,20 +6,19 @@
* @param grain Number * @param grain Number
* @constructor * @constructor
*/ */
GameLib.D3.Color = function RuntimeColor(graphics, parentObject, apiColor, grain) { GameLib.D3.Color = function (graphics, parentObject, apiColor, grain) {
for (var property in apiColor) {
if (apiColor.hasOwnProperty(property)) {
this[property] = apiColor[property];
}
}
GameLib.Utils.Extend(GameLib.D3.Color, GameLib.D3.API.Color);
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
GameLib.D3.API.Color.call(
this,
apiColor.r,
apiColor.g,
apiColor.b,
apiColor.a
);
this.parentObject = parentObject; this.parentObject = parentObject;
if (GameLib.Utils.UndefinedOrNull(grain)) { if (GameLib.Utils.UndefinedOrNull(grain)) {
@ -30,6 +29,9 @@ GameLib.D3.Color = function RuntimeColor(graphics, parentObject, apiColor, grain
this.instance = this.createInstance(); this.instance = this.createInstance();
}; };
GameLib.D3.Color.prototype = Object.create(GameLib.D3.API.Color.prototype);
GameLib.D3.Color.prototype.constructor = GameLib.D3.Color;
/** /**
* Creates an instance color * Creates an instance color
* @param update * @param update
@ -45,7 +47,7 @@ GameLib.D3.Color.prototype.createInstance = function(update) {
instance.g = this.g; instance.g = this.g;
instance.b = this.b; instance.b = this.b;
} else { } else {
instance = new this.graphics.instance.Color(this.r, this.g, this.b); instance = THREE.Color(this.r, this.g, this.b);
} }
return instance; return instance;

View File

@ -0,0 +1,71 @@
/**
* The image factory takes care that we only make requests for Image URLs which we have not already started downloading
* @param graphics GameLib.D3.Graphics
* @param baseUrl
* @returns {Function}
* @constructor
*/
GameLib.D3.ImageFactory = function (
graphics,
baseUrl
) {
graphics.isNotThreeThrow();
var promiseList = {};
return function(imagePath, progressCallback) {
if (!imagePath) {
console.log('Attempted to download bad URL : ' + imagePath);
throw new Error('Bad URL : ' + imagePath);
}
if (promiseList[imagePath]) {
return promiseList[imagePath];
}
var defer = Q.defer();
promiseList[imagePath] = defer.promise;
GameLib.D3.ImageFactory.LoadImage(graphics, baseUrl + imagePath, defer, progressCallback);
return promiseList[imagePath];
}
};
/**
* Loads an image and resolves the defered promise once it succeeded (or failed)
* @param graphics
* @param url
* @param defer
* @param progressCallback
* @constructor
*/
GameLib.D3.ImageFactory.LoadImage = function (
graphics,
url,
defer,
progressCallback
) {
var loader = new graphics.instance.ImageLoader();
loader.crossOrigin = '';
loader.load(
url + '?ts=' + Date.now(),
function (image) {
defer.resolve(image);
},
function onProgress(xhr) {
if (progressCallback) {
progressCallback((xhr.loaded / xhr.total * 100));
}
},
function onError() {
defer.reject('Failed to download image : ' + url);
}
);
};

View File

@ -1,72 +1,10 @@
/**
* The image factory takes care that we only make requests for Image URLs which we have not already started downloading
* @param graphics GameLib.D3.Graphics
* @returns {Function}
* @constructor
*/
GameLib.D3.ImageFactory = function (graphics, baseUrl) {
graphics.isNotThreeThrow();
var promiseList = {};
return function(imagePath, progressCallback) {
if (!imagePath) {
console.log('Attempted to download bad URL : ' + imagePath);
throw new Error('Bad URL : ' + imagePath);
}
if (promiseList[imagePath]) {
return promiseList[imagePath];
}
var defer = Q.defer();
promiseList[imagePath] = defer.promise;
GameLib.D3.ImageFactory.LoadImage(graphics, baseUrl + imagePath, defer, progressCallback);
return promiseList[imagePath];
}
};
/**
* Loads an image and resolves the defered promise once it succeeded (or failed)
* @param graphics
* @param url
* @param defer
* @param progressCallback
* @constructor
*/
GameLib.D3.ImageFactory.LoadImage = function (graphics, url, defer, progressCallback) {
var loader = new graphics.instance.ImageLoader();
loader.crossOrigin = '';
loader.load(
url + '?ts=' + Date.now(),
function (image) {
defer.resolve(image);
},
function onProgress(xhr) {
if (progressCallback) {
progressCallback((xhr.loaded / xhr.total * 100));
}
},
function onError() {
defer.reject('Failed to download image : ' + url);
}
);
};
/** /**
* Image * Image
* @param id * @param id
* @param filename * @param filename
* @param size * @param size
* @param contentType * @param contentType
* @param textureLink
* @constructor * @constructor
*/ */
GameLib.D3.Image = function( GameLib.D3.Image = function(

View File

@ -207,56 +207,7 @@ GameLib.D3.Light.FromObjectLight = function(graphics, objectLight) {
return new GameLib.D3.Light( return new GameLib.D3.Light(
graphics, graphics,
new GameLib.D3.API.Light( GameLib.D3.API.Light.FromObjectLight(objectLight)
objectLight.id,
objectLight.lightType,
objectLight.name,
new GameLib.D3.API.Color(
objectLight.color.r,
objectLight.color.g,
objectLight.color.b,
objectLight.color.a
),
objectLight.intensity,
new GameLib.API.Vector3(
objectLight.position.x,
objectLight.position.y,
objectLight.position.z
),
new GameLib.API.Vector3(
objectLight.targetPosition.x,
objectLight.targetPosition.y,
objectLight.targetPosition.z
),
new GameLib.API.Quaternion(
objectLight.quaternion.x,
objectLight.quaternion.y,
objectLight.quaternion.z,
objectLight.quaternion.w,
new GameLib.API.Vector3(
objectLight.quaternion.axis.x,
objectLight.quaternion.axis.y,
objectLight.quaternion.axis.z
),
objectLight.quaternion.angle
),
new GameLib.API.Vector3(
objectLight.rotation.x,
objectLight.rotation.y,
objectLight.rotation.z
),
new GameLib.API.Vector3(
objectLight.scale.x,
objectLight.scale.y,
objectLight.scale.z
),
objectLight.distance,
objectLight.decay,
objectLight.power,
objectLight.angle,
objectLight.penumbra,
objectLight.parentEntity
)
); );
}; };

View File

@ -3,21 +3,91 @@
* created * created
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param apiMaterial GameLib.D3.API.Material * @param apiMaterial GameLib.D3.API.Material
* @param imageFactory GameLib.D3.ImageFactory
* @constructor * @constructor
* @returns {GameLib.D3.Material | GameLib.D3.API.Material} * @returns {GameLib.D3.Material | GameLib.D3.API.Material}
*/ */
GameLib.D3.Material = function Material( GameLib.D3.Material = function Material(
graphics, graphics,
apiMaterial apiMaterial,
imageFactory
) { ) {
for (var property in apiMaterial) {
if (apiMaterial.hasOwnProperty(property)) {
this[property] = apiMaterial[property];
}
}
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
GameLib.D3.API.Material.call(
this,
apiMaterial.id,
apiMaterial.materialType,
apiMaterial.name,
apiMaterial.opacity,
apiMaterial.side,
apiMaterial.transparent,
apiMaterial.specular,
apiMaterial.lightMapIntensity,
apiMaterial.aoMapIntensity,
apiMaterial.color,
apiMaterial.emissive,
apiMaterial.emissiveIntensity,
apiMaterial.combine,
apiMaterial.shininess,
apiMaterial.reflectivity,
apiMaterial.refractionRatio,
apiMaterial.fog,
apiMaterial.wireframe,
apiMaterial.wireframeLineWidth,
apiMaterial.wireframeLineCap,
apiMaterial.wireframeLineJoin,
apiMaterial.vertexColors,
apiMaterial.skinning,
apiMaterial.morphTargets,
apiMaterial.morphNormals,
apiMaterial.lineWidth,
apiMaterial.lineCap,
apiMaterial.lineJoin,
apiMaterial.dashSize,
apiMaterial.gapWidth,
apiMaterial.blending,
apiMaterial.blendSrc,
apiMaterial.blendDst,
apiMaterial.blendEquation,
apiMaterial.depthTest,
apiMaterial.depthFunc,
apiMaterial.depthWrite,
apiMaterial.polygonOffset,
apiMaterial.polygonOffsetFactor,
apiMaterial.polygonOffsetUnits,
apiMaterial.alphaTest,
apiMaterial.clippingPlanes,
apiMaterial.clipShadows,
apiMaterial.visible,
apiMaterial.overdraw,
apiMaterial.shading,
apiMaterial.bumpScale,
apiMaterial.normalScale,
apiMaterial.displacementScale,
apiMaterial.displacementBias,
apiMaterial.roughness,
apiMaterial.metalness,
apiMaterial.pointSize,
apiMaterial.pointSizeAttenuation,
apiMaterial.spriteRotation,
apiMaterial.envMapIntensity,
apiMaterial.alphaMap,
apiMaterial.aoMap,
apiMaterial.bumpMap,
apiMaterial.diffuseMap,
apiMaterial.displacementMap,
apiMaterial.emissiveMap,
apiMaterial.environmentMap,
apiMaterial.lightMap,
apiMaterial.metalnessMap,
apiMaterial.normalMap,
apiMaterial.roughnessMap,
apiMaterial.specularMap,
apiMaterial.parentEntity
);
this.specular = new GameLib.D3.Color( this.specular = new GameLib.D3.Color(
graphics, graphics,
@ -37,11 +107,109 @@ GameLib.D3.Material = function Material(
this.emissive this.emissive
); );
this.alphaMap = new GameLib.D3.Texture(
this.graphics,
this.alphaMap,
this,
'alphaMap',
imageFactory
);
this.aoMap = new GameLib.D3.Texture(
this.graphics,
this.aoMap,
this,
'aoMap',
imageFactory
);
this.bumpMap = new GameLib.D3.Texture(
this.graphics,
this.bumpMap,
this,
'bumpMap',
imageFactory
);
this.diffuseMap = new GameLib.D3.Texture(
this.graphics,
this.diffuseMap,
this,
'map',
imageFactory
);
this.displacementMap = new GameLib.D3.Texture(
this.graphics,
this.displacementMap,
this,
'displacementMap',
imageFactory
);
this.emissiveMap = new GameLib.D3.Texture(
this.graphics,
this.emissiveMap,
this,
'emissiveMap',
imageFactory
);
this.environmentMap = new GameLib.D3.Texture(
this.graphics,
this.environmentMap,
this,
'envMap',
imageFactory
);
this.lightMap = new GameLib.D3.Texture(
this.graphics,
this.lightMap,
this,
'lightMap',
imageFactory
);
this.metalnessMap = new GameLib.D3.Texture(
this.graphics,
this.metalnessMap,
this,
'metalnessMap',
imageFactory
);
this.normalMap = new GameLib.D3.Texture(
this.graphics,
this.normalMap,
this,
'normalMap',
imageFactory
);
this.roughnessMap = new GameLib.D3.Texture(
this.graphics,
this.roughnessMap,
this,
'roughnessMap',
imageFactory
);
this.specularMap = new GameLib.D3.Texture(
this.graphics,
this.specularMap,
this,
'specularMap',
imageFactory
);
this.instance = this.createInstance(); this.instance = this.createInstance();
this.needsUpdate = false;
}; };
GameLib.D3.Material.prototype = Object.create(GameLib.D3.API.Material.prototype);
GameLib.D3.Material.prototype.constructor = GameLib.D3.Material;
/** /**
* Combine Method * Combine Method
* @type {number} * @type {number}
@ -154,7 +322,7 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_STANDARD) { if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
instance = new this.graphics.instance.MeshStandardMaterial({ instance = new THREE.MeshStandardMaterial({
name: this.name, name: this.name,
opacity: this.opacity, opacity: this.opacity,
transparent: this.transparent, transparent: this.transparent,
@ -199,7 +367,7 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
} else if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_PHONG) { } else if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_PHONG) {
instance = new this.graphics.instance.MeshPhongMaterial({ instance = new THREE.MeshPhongMaterial({
name: this.name, name: this.name,
opacity: this.opacity, opacity: this.opacity,
transparent: this.transparent, transparent: this.transparent,
@ -302,23 +470,55 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
console.log("material type is not implemented yet: " + this.materialType + " - material indexes could be screwed up"); console.log("material type is not implemented yet: " + this.materialType + " - material indexes could be screwed up");
} }
} }
if (update) { if (update) {
for (var property in instance) { for (var property in instance) {
if ( if (instance.hasOwnProperty(property)) {
instance.hasOwnProperty(property) &&
this.hasOwnProperty(property)
) {
if (property == 'size') {
instance[property] = this.pointSize;
}
if (property == 'sizeAttenuation') { if (property == 'alphaMap') {
instance[property] = this.pointSizeAttenuation; instance.alphaMap = this.alphaMap.instance;
} }
else if (property == 'aoMap') {
if (instance[property] instanceof THREE.Color) { instance.aoMap = this.aoMap.instance;
}
else if (property == 'bumpMap') {
instance.bumpMap = this.bumpMap.instance;
}
else if (property == 'map') {
instance.map = this.diffuseMap.instance;
}
else if (property == 'displacementMap') {
instance.displacementMap = this.displacementMap.instance;
}
else if (property == 'emissiveMap') {
instance.emissiveMap = this.emissiveMap.instance;
}
else if (property == 'envMap') {
instance.envMap = this.environmentMap.instance;
}
else if (property == 'lightMap') {
instance.lightMap = this.lightMap.instance;
}
else if (property == 'metalnessMap') {
instance.metalnessMap = this.metalnessMap.instance;
}
else if (property == 'normalMap') {
instance.normalMap = this.normalMap.instance;
}
else if (property == 'roughnessMap') {
instance.roughnessMap = this.roughnessMap.instance;
}
else if (property == 'specularMap') {
instance.specularMap = this.specularMap.instance;
}
else if (property == 'size') {
instance.size = this.pointSize;
}
else if (property == 'sizeAttenuation') {
instance.sizeAttenuation = this.pointSizeAttenuation;
}
else if (instance[property] instanceof THREE.Color) {
instance[property].copy(this[property]) instance[property].copy(this[property])
} else { } else {
instance[property] = this[property]; instance[property] = this[property];
@ -356,7 +556,6 @@ GameLib.D3.Material.prototype.toApiMaterial = function() {
this.opacity, this.opacity,
this.side, this.side,
this.transparent, this.transparent,
this.maps.toApiTextureMaps(),
this.specular.toApiColor(), this.specular.toApiColor(),
this.lightMapIntensity, this.lightMapIntensity,
this.aoMapIntensity, this.aoMapIntensity,
@ -406,7 +605,20 @@ GameLib.D3.Material.prototype.toApiMaterial = function() {
this.pointSize, this.pointSize,
this.pointSizeAttenuation, this.pointSizeAttenuation,
this.spriteRotation, this.spriteRotation,
this.envMapIntensity this.envMapIntensity,
this.alphaMap.toApiTexture(),
this.aoMap.toApiTexture(),
this.bumpMap.toApiTexture(),
this.diffuseMap.toApiTexture(),
this.displacementMap.toApiTexture(),
this.emissiveMap.toApiTexture(),
this.environmentMap.toApiTexture(),
this.lightMap.toApiTexture(),
this.metalnessMap.toApiTexture(),
this.normalMap.toApiTexture(),
this.roughnessMap.toApiTexture(),
this.specularMap.toApiTexture(),
GameLib.Utils.IdOrNull(this.parentEntity)
); );
}; };
@ -418,98 +630,12 @@ GameLib.D3.Material.prototype.toApiMaterial = function() {
* @constructor * @constructor
*/ */
GameLib.D3.Material.FromObjectMaterial = function(graphics, objectMaterial, imageFactory) { GameLib.D3.Material.FromObjectMaterial = function(graphics, objectMaterial, imageFactory) {
var gameLibMaterial = new GameLib.D3.Material( var gameLibMaterial = new GameLib.D3.Material(
graphics, graphics,
new GameLib.D3.API.Material( GameLib.D3.API.Material.FromObjectMaterial(objectMaterial),
objectMaterial.id, imageFactory
objectMaterial.materialType,
objectMaterial.name,
objectMaterial.opacity,
objectMaterial.side,
objectMaterial.transparent,
GameLib.D3.API.TextureMapTemplate(),
new GameLib.D3.API.Color(
objectMaterial.specular.r,
objectMaterial.specular.g,
objectMaterial.specular.b,
objectMaterial.specular.a
),
objectMaterial.lightMapIntensity,
objectMaterial.aoMapIntensity,
new GameLib.D3.API.Color(
objectMaterial.color.r,
objectMaterial.color.g,
objectMaterial.color.b,
objectMaterial.color.a
),
new GameLib.D3.API.Color(
objectMaterial.emissive.r,
objectMaterial.emissive.g,
objectMaterial.emissive.b,
objectMaterial.emissive.a
),
objectMaterial.emissiveIntensity,
objectMaterial.combine,
objectMaterial.shininess,
objectMaterial.reflectivity,
objectMaterial.refractionRatio,
objectMaterial.fog,
objectMaterial.wireframe,
objectMaterial.wireframeLineWidth,
objectMaterial.wireframeLineCap,
objectMaterial.wireframeLineJoin,
objectMaterial.vertexColors,
objectMaterial.skinning,
objectMaterial.morphTargets,
objectMaterial.morphNormals,
objectMaterial.lineWidth,
objectMaterial.lineCap,
objectMaterial.lineJoin,
objectMaterial.dashSize,
objectMaterial.gapWidth,
objectMaterial.blending,
objectMaterial.blendSrc,
objectMaterial.blendDst,
objectMaterial.blendEquation,
objectMaterial.depthTest,
objectMaterial.depthFunc,
objectMaterial.depthWrite,
objectMaterial.polygonOffset,
objectMaterial.polygonOffsetFactor,
objectMaterial.polygonOffsetUnits,
objectMaterial.alphaTest,
objectMaterial.clippingPlanes,
objectMaterial.clipShadows,
objectMaterial.visible,
objectMaterial.overdraw,
objectMaterial.shading,
objectMaterial.bumpScale,
objectMaterial.normalScale,
objectMaterial.displacementScale,
objectMaterial.displacementBias,
objectMaterial.roughness,
objectMaterial.metalness,
objectMaterial.pointSize,
objectMaterial.pointSizeAttenuation,
objectMaterial.spriteRotation,
objectMaterial.envMapIntensity
)
); );
var objectMaps = objectMaterial.maps;
var gameLibTextureMap = new GameLib.D3.TextureMapTemplate(graphics);
for (var map in gameLibTextureMap) {
if (gameLibTextureMap.hasOwnProperty(map) && objectMaps[map] && objectMaps[map].texture && objectMaps[map].texture.imagePath) {
gameLibTextureMap[map].texture = GameLib.D3.Texture.FromObjectTexture(graphics, objectMaps[map].texture, gameLibMaterial, map, gameLibTextureMap, imageFactory);
}
}
gameLibMaterial.maps = gameLibTextureMap;
return gameLibMaterial; return gameLibMaterial;
}; };

View File

@ -3,12 +3,14 @@
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param computeNormals Boolean * @param computeNormals Boolean
* @param apiMesh GameLib.D3.API.Mesh * @param apiMesh GameLib.D3.API.Mesh
* @param imageFactory GameLib.D3.ImageFactory
* @constructor * @constructor
*/ */
GameLib.D3.Mesh = function RuntimeMesh( GameLib.D3.Mesh = function (
graphics, graphics,
apiMesh,
computeNormals, computeNormals,
apiMesh imageFactory
) { ) {
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
@ -39,53 +41,77 @@ GameLib.D3.Mesh = function RuntimeMesh(
apiMesh.renderOrder apiMesh.renderOrder
); );
this.materials = this.materials.map(
function (apiMaterial) {
return new GameLib.D3.Material(
this.graphics,
apiMaterial,
imageFactory
)
}.bind(this)
);
this.skeleton = new GameLib.D3.Skeleton(
this.graphics,
this.skeleton
);
this.vertices = this.vertices.map(
function (apiVertex) {
return new GameLib.D3.Vertex(
this.graphics,
apiVertex
);
}.bind(this)
);
this.position = new GameLib.Vector3( this.position = new GameLib.Vector3(
graphics, this.graphics,
this, this,
this.position, this.position,
0.001 0.001
); );
this.scale = new GameLib.Vector3( this.scale = new GameLib.Vector3(
graphics, this.graphics,
this, this,
this.scale, this.scale,
0.001 0.001
); );
this.up = new GameLib.Vector3( this.up = new GameLib.Vector3(
graphics, this.graphics,
this, this,
this.up, this.up,
0.001 0.001
); );
this.quaternion = new GameLib.Quaternion( this.quaternion = new GameLib.Quaternion(
graphics, this.graphics,
this, this,
this.quaternion this.quaternion
); );
this.localPosition = new GameLib.Vector3( this.localPosition = new GameLib.Vector3(
graphics, this.graphics,
this, this,
this.localPosition this.localPosition
); );
this.localRotation = new GameLib.Vector3( this.localRotation = new GameLib.Vector3(
graphics, this.graphics,
this, this,
this.localRotation this.localRotation
); );
this.localScale = new GameLib.Vector3( this.localScale = new GameLib.Vector3(
graphics, this.graphics,
this, this,
this.localScale this.localScale
); );
this.modelMatrix = new GameLib.Matrix4( this.modelMatrix = new GameLib.Matrix4(
graphics, this.graphics,
this, this,
this.modelMatrix this.modelMatrix
); );
@ -247,14 +273,12 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
this.computeNormals = false; this.computeNormals = false;
} }
var instanceMaterial = this.materials[0].instance;
if (this.meshType == GameLib.D3.Mesh.TYPE_NORMAL) { if (this.meshType == GameLib.D3.Mesh.TYPE_NORMAL) {
instance = new THREE.Mesh(instanceGeometry, instanceMaterial); instance = new THREE.Mesh(instanceGeometry, this.materials[0].instance);
} }
if (this.meshType == GameLib.D3.Mesh.TYPE_CURVE) { if (this.meshType == GameLib.D3.Mesh.TYPE_CURVE) {
instance = new THREE.Points(instanceGeometry, instanceMaterial); instance = new THREE.Points(instanceGeometry, this.materials[0].instance);
} }
if (this.meshType == GameLib.D3.Mesh.TYPE_SKINNED) { if (this.meshType == GameLib.D3.Mesh.TYPE_SKINNED) {
@ -287,7 +311,7 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
); );
} }
instance = new THREE.SkinnedMesh(instanceGeometry, instanceMaterial); instance = new THREE.SkinnedMesh(instanceGeometry, this.materials[0].instance);
instance.add(this.skeleton.rootBoneInstance); instance.add(this.skeleton.rootBoneInstance);
@ -428,113 +452,13 @@ GameLib.D3.Mesh.prototype.toApiMesh = function() {
*/ */
GameLib.D3.Mesh.FromObjectMesh = function(graphics, objectMesh, computeNormals, imageFactory) { GameLib.D3.Mesh.FromObjectMesh = function(graphics, objectMesh, computeNormals, imageFactory) {
var apiMesh = new GameLib.D3.API.Mesh( var apiMesh = GameLib.D3.API.Mesh.FromObjectMesh(objectMesh);
objectMesh.id,
objectMesh.meshType,
objectMesh.name,
objectMesh.vertices.map(
function (objectVertex) {
return GameLib.D3.Vertex.FromObjectVertex(
graphics,
objectVertex
);
}
),
objectMesh.faces,
objectMesh.faceVertexUvs,
objectMesh.materials.map(
function (objectMaterial) {
return GameLib.D3.Material.FromObjectMaterial(
graphics,
objectMaterial,
imageFactory
);
}
),
objectMesh.parentMesh,
objectMesh.parentScene,
GameLib.D3.Skeleton.FromObjectSkeleton(
graphics,
objectMesh.skeleton
),
objectMesh.skinIndices,
objectMesh.skinWeights,
new GameLib.API.Vector3(
objectMesh.position.x,
objectMesh.position.y,
objectMesh.position.z
),
new GameLib.API.Quaternion(
objectMesh.quaternion.x,
objectMesh.quaternion.y,
objectMesh.quaternion.z,
objectMesh.quaternion.w,
new GameLib.API.Vector3(
objectMesh.quaternion.axis.x,
objectMesh.quaternion.axis.y,
objectMesh.quaternion.axis.z
),
objectMesh.quaternion.angle
),
new GameLib.API.Vector3(
objectMesh.scale.x,
objectMesh.scale.y,
objectMesh.scale.z
),
new GameLib.API.Vector3(
objectMesh.localPosition.x,
objectMesh.localPosition.y,
objectMesh.localPosition.z
),
new GameLib.API.Vector3(
objectMesh.localRotation.x,
objectMesh.localRotation.y,
objectMesh.localRotation.z
),
new GameLib.API.Vector3(
objectMesh.localScale.x,
objectMesh.localScale.y,
objectMesh.localScale.z
),
new GameLib.API.Vector3(
objectMesh.up.x,
objectMesh.up.y,
objectMesh.up.z
),
new GameLib.API.Matrix4(
new GameLib.API.Vector4(
objectMesh.modelMatrix.rows[0].x,
objectMesh.modelMatrix.rows[0].y,
objectMesh.modelMatrix.rows[0].z,
objectMesh.modelMatrix.rows[0].w
),
new GameLib.API.Vector4(
objectMesh.modelMatrix.rows[1].x,
objectMesh.modelMatrix.rows[1].y,
objectMesh.modelMatrix.rows[1].z,
objectMesh.modelMatrix.rows[1].w
),
new GameLib.API.Vector4(
objectMesh.modelMatrix.rows[2].x,
objectMesh.modelMatrix.rows[2].y,
objectMesh.modelMatrix.rows[2].z,
objectMesh.modelMatrix.rows[2].w
),
new GameLib.API.Vector4(
objectMesh.modelMatrix.rows[3].x,
objectMesh.modelMatrix.rows[3].y,
objectMesh.modelMatrix.rows[3].z,
objectMesh.modelMatrix.rows[3].w
)
),
objectMesh.parentEntity,
objectMesh.renderOrder
);
return new GameLib.D3.Mesh( return new GameLib.D3.Mesh(
graphics, graphics,
apiMesh,
computeNormals, computeNormals,
apiMesh imageFactory
); );
}; };

View File

@ -5,13 +5,15 @@
* @param progressCallback * @param progressCallback
* @param apiScene GameLib.D3.API.Scene * @param apiScene GameLib.D3.API.Scene
* @param imageFactory * @param imageFactory
* @param computeNormals
* @constructor * @constructor
*/ */
GameLib.D3.Scene = function Scene( GameLib.D3.Scene = function Scene(
graphics, graphics,
progressCallback, progressCallback,
apiScene, apiScene,
imageFactory imageFactory,
computeNormals
) { ) {
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
@ -34,6 +36,40 @@ GameLib.D3.Scene = function Scene(
apiScene.activeCameraIndex apiScene.activeCameraIndex
); );
this.meshes = this.meshes.map(
function(apiMesh) {
return new GameLib.D3.Mesh(
this.graphics,
apiMesh,
computeNormals,
imageFactory
)
}.bind(this)
);
this.lights = this.lights.map(
function(apiLight) {
return new GameLib.D3.Light(
this.graphics,
apiLight
)
}.bind(this)
);
this.entityManager = new GameLib.EntityManager(
this,
this.entityManager
);
this.cameras = this.cameras.map(
function(apiCamera) {
return new GameLib.D3.Camera(
this.graphics,
apiCamera
)
}.bind(this)
);
this.position = new GameLib.Vector3( this.position = new GameLib.Vector3(
graphics, graphics,
this, this,
@ -219,81 +255,7 @@ GameLib.D3.Scene.FromObjectScene = function(
imageFactory, imageFactory,
progressCallback progressCallback
) { ) {
var apiScene = new GameLib.D3.API.Scene( var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene);
objectScene.id,
objectScene.path,
objectScene.name,
objectScene.meshes.map(
function (objectMesh) {
return GameLib.D3.Mesh.FromObjectMesh(
graphics,
objectMesh,
computeNormals,
imageFactory
)
}
),
new GameLib.API.Vector3(
objectScene.position.x,
objectScene.position.y,
objectScene.position.z
),
new GameLib.API.Quaternion(
objectScene.quaternion.x,
objectScene.quaternion.y,
objectScene.quaternion.z,
objectScene.quaternion.w,
new GameLib.API.Vector3(
objectScene.quaternion.axis.x,
objectScene.quaternion.axis.y,
objectScene.quaternion.axis.z
),
objectScene.quaternion.angle
),
new GameLib.API.Vector3(
objectScene.scale.x,
objectScene.scale.y,
objectScene.scale.z
),
objectScene.parentSceneId,
objectScene.lights.map(
function (objectLight) {
return GameLib.D3.Light.FromObjectLight(
graphics,
objectLight
)
}
),
objectScene.worlds.map(
function (objectWorld) {
return GameLib.D3.World.FromObjectWorld(
graphics,
objectWorld
);
}
),
GameLib.EntityManager.FromObjectEntityManager(
graphics,
objectScene.entityManager
),
objectScene.shapes.map(
function (objectShape) {
return GameLib.D3.Shape.FromObjectShape(
graphics,
objectShape
);
}
),
objectScene.cameras.map(
function (objectCamera) {
return GameLib.D3.Camera.FromObjectCamera(
graphics,
objectCamera
);
}
),
objectScene.activeCameraIndex
);
return new GameLib.D3.Scene( return new GameLib.D3.Scene(
graphics, graphics,

View File

@ -160,79 +160,7 @@ GameLib.D3.Skeleton.FromObjectSkeleton = function(
return null; return null;
} }
var apiSkeleton = new GameLib.D3.API.Skeleton( var apiSkeleton = GameLib.D3.API.Skeleton.FromObjectSkeleton(objectSkeleton);
objectSkeleton.id,
objectSkeleton.name,
objectSkeleton.bones.map(
function (objectBone) {
return GameLib.D3.Bone.FromObjectBone(graphics, objectBone);
}
),
objectSkeleton.boneInverses.map(
function (boneInverse) {
return new GameLib.D3.API.Matrix4(
new GameLib.D3.Vector4(
boneInverse[0],
boneInverse[1],
boneInverse[2],
boneInverse[3]
),
new GameLib.D3.Vector4(
boneInverse[4],
boneInverse[5],
boneInverse[6],
boneInverse[7]
),
new GameLib.D3.Vector4(
boneInverse[8],
boneInverse[9],
boneInverse[10],
boneInverse[11]
),
new GameLib.D3.Vector4(
boneInverse[12],
boneInverse[13],
boneInverse[14],
boneInverse[15]
)
);
}
),
objectSkeleton.useVertexTexture,
objectSkeleton.boneTextureWidth,
objectSkeleton.boneTextureHeight,
objectSkeleton.boneMatrices.map(
function (boneMatrix) {
return new GameLib.D3.API.Matrix4(
new GameLib.D3.Vector4(
boneMatrix[0],
boneMatrix[1],
boneMatrix[2],
boneMatrix[3]
),
new GameLib.D3.Vector4(
boneMatrix[4],
boneMatrix[5],
boneMatrix[6],
boneMatrix[7]
),
new GameLib.D3.Vector4(
boneMatrix[8],
boneMatrix[9],
boneMatrix[10],
boneMatrix[11]
),
new GameLib.D3.Vector4(
boneMatrix[12],
boneMatrix[13],
boneMatrix[14],
boneMatrix[15]
)
);
}
),
objectSkeleton.boneTexture
);
var skeleton = new GameLib.D3.Skeleton( var skeleton = new GameLib.D3.Skeleton(
graphics, graphics,

View File

@ -1,64 +0,0 @@
/**
* We have a mapping between GameLib.D3.Texture and the Instance material map.
* Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap
* @param graphics
* @constructor
*/
GameLib.D3.TextureMapTemplate = function TextureMapTemplate(
graphics
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
return new GameLib.D3.TextureMaps(
new GameLib.D3.TextureMap(
null,
'alphaMap'
),
new GameLib.D3.TextureMap(
null,
'aoMap'
),
new GameLib.D3.TextureMap(
null,
'bumpMap'
),
new GameLib.D3.TextureMap(
null,
'map'
),
new GameLib.D3.TextureMap(
null,
'displacementMap'
),
new GameLib.D3.TextureMap(
null,
'emissiveMap'
),
new GameLib.D3.TextureMap(
null,
'envMap'
),
new GameLib.D3.TextureMap(
null,
'lightMap'
),
new GameLib.D3.TextureMap(
null,
'metalnessMap'
),
new GameLib.D3.TextureMap(
null,
'normalMap'
),
new GameLib.D3.TextureMap(
null,
'roughnessMap'
),
new GameLib.D3.TextureMap(
null,
'specularMap'
)
);
};

View File

@ -1,33 +0,0 @@
/**
* We have a mapping between GameLib.D3.Texture and the Instance material map.
* Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap
* @constructor
* @param texture GameLib.D3.Texture
* @param instanceMapId string
*/
GameLib.D3.TextureMap = function TextureMap(
texture,
instanceMapId
) {
if (GameLib.Utils.UndefinedOrNull(texture)) {
texture = null;
}
this.texture = texture;
if (GameLib.Utils.UndefinedOrNull(instanceMapId)) {
instanceMapId = null;
}
this.instanceMapId = instanceMapId;
};
GameLib.D3.TextureMap.prototype.toApiTextureMap = function() {
var apiTexture = null;
if (this.texture) {
apiTexture = this.texture.toApiTexture();
}
return new GameLib.D3.TextureMap(apiTexture, this.instanceMapId);
};

View File

@ -1,66 +0,0 @@
/**
* We have a mapping between GameLib.D3.Texture and the Instance material map.
* Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap
* @returns {{alpha: {texture: null, instanceMapId: string}, ao: {texture: null, instanceMapId: string}, bump: {texture: null, instanceMapId: string}, diffuse: {texture: null, instanceMapId: string}, displacement: {texture: null, instanceMapId: string}, emissive: {texture: null, instanceMapId: string}, environment: {texture: null, instanceMapId: string}, light: {texture: null, instanceMapId: string}, metalness: {texture: null, instanceMapId: string}, normal: {texture: null, instanceMapId: string}, roughness: {texture: null, instanceMapId: string}, specular: {texture: null, instanceMapId: string}}}
* @constructor
* @param alpha
* @param ao
* @param bump
* @param diffuse
* @param displacement
* @param emissive
* @param environment
* @param light
* @param metalness
* @param normal
* @param roughness
* @param specular
*/
GameLib.D3.TextureMaps = function TextureMaps(
alpha,
ao,
bump,
diffuse,
displacement,
emissive,
environment,
light,
metalness,
normal,
roughness,
specular
) {
this.alpha = alpha;
this.ao = ao;
this.bump = bump;
this.diffuse = diffuse;
this.displacement = displacement;
this.emissive = emissive;
this.environment = environment;
this.light = light;
this.metalness = metalness;
this.normal = normal;
this.roughness = roughness;
this.specular = specular;
};
/**
* Returns API textures from the Texture Maps
* @returns {GameLib.D3.TextureMaps}
*/
GameLib.D3.TextureMaps.prototype.toApiTextureMaps = function() {
return new GameLib.D3.TextureMaps(
this.alpha.toApiTextureMap(),
this.ao.toApiTextureMap(),
this.bump.toApiTextureMap(),
this.diffuse.toApiTextureMap(),
this.displacement.toApiTextureMap(),
this.emissive.toApiTextureMap(),
this.environment.toApiTextureMap(),
this.light.toApiTextureMap(),
this.metalness.toApiTextureMap(),
this.normal.toApiTextureMap(),
this.roughness.toApiTextureMap(),
this.specular.toApiTextureMap()
);
};

View File

@ -9,20 +9,39 @@
* @constructor * @constructor
*/ */
GameLib.D3.Texture = function Texture( GameLib.D3.Texture = function Texture(
apiTexture,
graphics, graphics,
apiTexture,
parentMaterial, parentMaterial,
parentMaterialInstanceMapId, parentMaterialInstanceMapId,
imageFactory imageFactory
) { ) {
for (var property in apiTexture) {
if (apiTexture.hasOwnProperty(property)) {
this[property] = apiTexture[property];
}
}
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
GameLib.API.Texture.call(
this,
apiTexture.id,
apiTexture.typeId,
apiTexture.name,
apiTexture.imagePath,
apiTexture.wrapS,
apiTexture.wrapT,
apiTexture.repeat,
apiTexture.data,
apiTexture.format,
apiTexture.mapping,
apiTexture.magFilter,
apiTexture.minFilter,
apiTexture.textureType,
apiTexture.anisotropy,
apiTexture.offset,
apiTexture.generateMipmaps,
apiTexture.flipY,
apiTexture.mipmaps,
apiTexture.unpackAlignment,
apiTexture.premultiplyAlpha,
apiTexture.encoding
);
this.offset = new GameLib.Vector2( this.offset = new GameLib.Vector2(
graphics, graphics,
@ -47,6 +66,13 @@ GameLib.D3.Texture = function Texture(
this.loadTexture(imageFactory); this.loadTexture(imageFactory);
}; };
GameLib.D3.Texture.prototype = Object.create(GameLib.D3.API.Texture.prototype);
GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture;
/**
* Loads a texture from the image factory, it could already have downloaded, and then it updates the instance
* @param imageFactory
*/
GameLib.D3.Texture.prototype.loadTexture = function(imageFactory) { GameLib.D3.Texture.prototype.loadTexture = function(imageFactory) {
this.imageData = imageFactory(this.imagePath); this.imageData = imageFactory(this.imagePath);
@ -238,14 +264,12 @@ GameLib.D3.Texture.prototype.toApiTexture = function() {
}; };
/** /**
* Converts from an Object texture to a GameLib.D3.Texture * Converts from an Object texture to a GameLib.D3.Texture
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param objectTexture Object * @param objectTexture Object
* @param gameLibMaterial GameLib.D3.Material * @param gameLibMaterial GameLib.D3.Material
* @param map GameLib.D3.TextureMap * @param instanceMapId String
* @param gameLibTextureMap GameLib.D3.TextureMapTemplate
* @param imageFactory GameLib.D3.ImageFactory * @param imageFactory GameLib.D3.ImageFactory
* @constructor * @constructor
*/ */
@ -253,43 +277,14 @@ GameLib.D3.Texture.FromObjectTexture = function(
graphics, graphics,
objectTexture, objectTexture,
gameLibMaterial, gameLibMaterial,
map, instanceMapId,
gameLibTextureMap,
imageFactory imageFactory
) { ) {
return new GameLib.D3.Texture( return new GameLib.D3.Texture(
new GameLib.D3.API.Texture(
objectTexture.id,
map,
objectTexture.name,
objectTexture.imagePath,
objectTexture.wrapS,
objectTexture.wrapT,
new GameLib.API.Vector2(
objectTexture.repeat.x,
objectTexture.repeat.y
),
objectTexture.data,
objectTexture.format,
objectTexture.mapping,
objectTexture.magFilter,
objectTexture.minFilter,
objectTexture.textureType,
objectTexture.anisotropy,
new GameLib.API.Vector2(
objectTexture.offset.x,
objectTexture.offset.y
),
objectTexture.generateMipmaps,
objectTexture.flipY,
objectTexture.mipmaps,
objectTexture.unpackAlignment,
objectTexture.premultiplyAlpha,
objectTexture.encoding
),
graphics, graphics,
GameLib.D3.API.Texture.FromObjectTexture(objectTexture),
gameLibMaterial, gameLibMaterial,
gameLibTextureMap[map].instanceMapId, instanceMapId,
imageFactory imageFactory
); );
}; };

View File

@ -83,14 +83,7 @@ GameLib.D3.Vertex.FromObjectVertex = function(
graphics, graphics,
objectVertex objectVertex
) { ) {
var apiVertex = new GameLib.D3.API.Vertex( var apiVertex = GameLib.D3.API.Vertex.FromObjectVertex(objectVertex);
new GameLib.API.Vector3(
objectVertex.position.x,
objectVertex.position.y,
objectVertex.position.z
),
objectVertex.boneWeights
);
return new GameLib.D3.Vertex( return new GameLib.D3.Vertex(
graphics, graphics,

View File

@ -19,6 +19,16 @@ GameLib.EntityManager = function(
apiEntityManager.entities apiEntityManager.entities
); );
this.entities = this.entities.map(
function(apiEntity) {
return new GameLib.Entity(
this,
this,
apiEntity
)
}
);
this.instance = this.createInstance(); this.instance = this.createInstance();
}; };
@ -165,45 +175,8 @@ GameLib.EntityManager.prototype.toApiEntityManager = function() {
GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntities) { GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntities) {
var apiEntities = objectEntities.entities.map( var apiEntities = objectEntities.entities.map(
function (objectEntity) { function (objectEntity) {
return GameLib.API.Entity.FromObjectEntity(objectEntity);
objectEntity.components = objectEntity.components.map(
function (component) {
if (component instanceof Object) {
if (component.componentType === GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING) {
return GameLib.D3.PathFollowing.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_RENDERABLE) {
return GameLib.D3.Renderable.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_RENDERER) {
return GameLib.D3.Renderer.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_EDITOR_INPUT) {
return GameLib.D3.Input.Editor.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
return GameLib.D3.LookAt.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_FOLLOW) {
return GameLib.D3.Follow.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_MESH) {
return GameLib.D3.Mesh.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_SPLINE) {
return GameLib.D3.Spline.FromObjectComponent(graphics, component);
} else if (component.componentType === GameLib.Component.COMPONENT_INPUT_DRIVE) {
return GameLib.D3.Input.Drive.FromObjectComponent(graphics, component);
}else {
console.warn('no component was associated with this object');
throw new Error('no component was associated with this object');
}
} else {
return component;
}
}
);
return new GameLib.API.Entity(
objectEntity.id,
objectEntity.name,
objectEntity.components
)
} }
); );
@ -216,16 +189,6 @@ GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntitie
apiEntityManager apiEntityManager
); );
entityManager.entities = entityManager.entities.map(
function(apiEntity) {
return new GameLib.Entity(
entityManager,
entityManager,
apiEntity
)
}
);
return entityManager; return entityManager;
}; };

View File

@ -2,6 +2,13 @@
* Entity Runtime * Entity Runtime
* @constructor * @constructor
*/ */
/**
*
* @param entityManager GameLib.D3.EntityManager
* @param parentObject
* @param apiEntity GameLib.D3.API.Entity
* @constructor
*/
GameLib.Entity = function RuntimeEntity( GameLib.Entity = function RuntimeEntity(
entityManager, entityManager,
parentObject, parentObject,
@ -24,6 +31,40 @@ GameLib.Entity = function RuntimeEntity(
apiEntity.components apiEntity.components
); );
this.components = this.components.map(
function (component) {
if (component instanceof Object) {
component.constructor.FromObjectComponent(entityManager.graphics, component);
//
// if (component.componentType === GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING) {
// return GameLib.D3.PathFollowing.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_RENDERABLE) {
// return GameLib.D3.Renderable.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_RENDERER) {
// return GameLib.D3.Renderer.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_EDITOR_INPUT) {
// return GameLib.D3.Input.Editor.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
// return GameLib.D3.LookAt.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_FOLLOW) {
// return GameLib.D3.Follow.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_MESH) {
// return GameLib.D3.Mesh.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_SPLINE) {
// return GameLib.D3.Spline.FromObjectComponent(entityManager.graphics, component);
// } else if (component.componentType === GameLib.Component.COMPONENT_INPUT_DRIVE) {
// return GameLib.D3.Input.Drive.FromObjectComponent(entityManager.graphics, component);
// }else {
// console.warn('no component was associated with this object');
// throw new Error('no component was associated with this object');
// }
} else {
return component;
}
}.bind(this)
);
this.instance = this.createInstance(); this.instance = this.createInstance();
}; };
@ -103,11 +144,7 @@ GameLib.Entity.prototype.toApiEntity = function() {
*/ */
GameLib.Entity.FromObjectEntity = function(entityManager, objectEntity) { GameLib.Entity.FromObjectEntity = function(entityManager, objectEntity) {
var apiEntity = new GameLib.API.Entity( var apiEntity = GameLib.API.Entity.FromObjectEntity(objectEntity);
objectEntity.id,
objectEntity.name,
objectEntity.components
);
return new GameLib.Entity( return new GameLib.Entity(
entityManager, entityManager,