texture refactoring done
parent
76e36e0fa7
commit
ec79b03977
|
@ -0,0 +1,110 @@
|
||||||
|
/**
|
||||||
|
* API Color
|
||||||
|
* @param r
|
||||||
|
* @param g
|
||||||
|
* @param b
|
||||||
|
* @param a
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Color = function (r, g, b, a) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(r)) {
|
||||||
|
r = 1;
|
||||||
|
}
|
||||||
|
this.r = r;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(g)) {
|
||||||
|
g = 1;
|
||||||
|
}
|
||||||
|
this.g = g;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(b)) {
|
||||||
|
b = 1;
|
||||||
|
}
|
||||||
|
this.b = b;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(a)) {
|
||||||
|
a = 0;
|
||||||
|
}
|
||||||
|
this.a = a;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an API color from an Object color
|
||||||
|
* @param objectColor
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Color.FromObjectColor = function(objectColor) {
|
||||||
|
|
||||||
|
return new GameLib.API.Color(
|
||||||
|
objectColor.r,
|
||||||
|
objectColor.g,
|
||||||
|
objectColor.b,
|
||||||
|
objectColor.a
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the current color to HTML hex format (ex. #ffffff)
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
GameLib.API.Color.prototype.toHex = function() {
|
||||||
|
|
||||||
|
if (this.r < 0) {
|
||||||
|
this.r = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.g < 0) {
|
||||||
|
this.g = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.b < 0) {
|
||||||
|
this.b = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.r > 1) {
|
||||||
|
this.r = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.g > 1) {
|
||||||
|
this.g = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.b > 1) {
|
||||||
|
this.b = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var rf = Math.floor(this.r >= 1? 255 : this.r * 256.0).toString(16);
|
||||||
|
var gf = Math.floor(this.g >= 1? 255 : this.g * 256.0).toString(16);
|
||||||
|
var bf = Math.floor(this.b >= 1? 255 : this.b * 256.0).toString(16);
|
||||||
|
|
||||||
|
if (rf.length < 2) {
|
||||||
|
rf = '0' + rf;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gf.length < 2) {
|
||||||
|
gf = '0' + gf;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bf.length < 2) {
|
||||||
|
bf = '0' + bf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '#' + rf + gf + bf;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets this object color to what the hex value is
|
||||||
|
* @param hex
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
GameLib.API.Color.prototype.fromHex = function(hex) {
|
||||||
|
|
||||||
|
var matches = hex.match(new RegExp('#+(..)(..)(..)'));
|
||||||
|
|
||||||
|
this.r = parseInt(matches[1], 16) / 255.0;
|
||||||
|
this.g = parseInt(matches[2], 16) / 255.0;
|
||||||
|
this.b = parseInt(matches[3], 16) / 255.0;
|
||||||
|
};
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
* API Component Interface - Do not construct objects of this type directly
|
||||||
|
* @param componentType
|
||||||
|
* @param linkedObjects
|
||||||
|
* @param loaded (indicates whether the linked Objects for this component has been loaded)
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Component = function(
|
||||||
|
componentType,
|
||||||
|
linkedObjects,
|
||||||
|
loaded,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
this.componentType = componentType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(linkedObjects)) {
|
||||||
|
linkedObjects = {};
|
||||||
|
}
|
||||||
|
this.linkedObjects = linkedObjects;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(loaded)) {
|
||||||
|
loaded = false;
|
||||||
|
}
|
||||||
|
this.loaded = loaded;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||||
|
parentEntity = null;
|
||||||
|
}
|
||||||
|
this.parentEntity = parentEntity;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an API component from an object component
|
||||||
|
* @param objectComponent (should be an ID string - components get loaded and linked)
|
||||||
|
* @returns {GameLib.API.Component}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Component.FromObjectComponent = function(objectComponent) {
|
||||||
|
if (objectComponent instanceof Object) {
|
||||||
|
|
||||||
|
if (objectComponent.componentType == GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING) {
|
||||||
|
return GameLib.D3.API.PathFollowing.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_RENDERER) {
|
||||||
|
return GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
|
||||||
|
return GameLib.D3.API.LookAt.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_FOLLOW) {
|
||||||
|
return GameLib.D3.API.Follow.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_MESH) {
|
||||||
|
return GameLib.D3.API.Mesh.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_SPLINE) {
|
||||||
|
return GameLib.D3.API.Spline.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_INPUT_DRIVE) {
|
||||||
|
return GameLib.D3.API.Input.Drive.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn('No API Component was associated with this Object');
|
||||||
|
throw new Error('No API Component was associated with this Object');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return objectComponent;
|
||||||
|
}
|
||||||
|
};
|
|
@ -19,4 +19,13 @@ GameLib.API.EntityManager = function(
|
||||||
*/
|
*/
|
||||||
GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager) {
|
GameLib.API.EntityManager.FromObjectEntityManager = function(objectEntityManager) {
|
||||||
|
|
||||||
|
var apiEntities = objectEntityManager.entities.map(
|
||||||
|
function (objectEntity) {
|
||||||
|
return GameLib.API.Entity.FromObjectEntity(objectEntity);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.API.EntityManager(
|
||||||
|
apiEntities
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,6 @@ GameLib.API.Entity = function(
|
||||||
*/
|
*/
|
||||||
GameLib.API.Entity.prototype.addComponent = function(component) {
|
GameLib.API.Entity.prototype.addComponent = function(component) {
|
||||||
this.components.push(component);
|
this.components.push(component);
|
||||||
this.instance.addComponent(component)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,8 +41,6 @@ GameLib.API.Entity.prototype.addComponent = function(component) {
|
||||||
*/
|
*/
|
||||||
GameLib.API.Entity.prototype.removeComponent = function(component) {
|
GameLib.API.Entity.prototype.removeComponent = function(component) {
|
||||||
|
|
||||||
this.instance.removeComponent(component);
|
|
||||||
|
|
||||||
var index = this.components.indexOf(component);
|
var index = this.components.indexOf(component);
|
||||||
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
|
@ -61,9 +58,16 @@ GameLib.API.Entity.prototype.removeComponent = function(component) {
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Entity.FromObjectEntity = function(objectEntity) {
|
GameLib.API.Entity.FromObjectEntity = function(objectEntity) {
|
||||||
|
|
||||||
|
var apiComponents = objectEntity.components.map(
|
||||||
|
function (objectComponent) {
|
||||||
|
return GameLib.API.Component.FromObjectComponent(objectComponent);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return new GameLib.API.Entity(
|
return new GameLib.API.Entity(
|
||||||
objectEntity.id,
|
objectEntity.id,
|
||||||
objectEntity.name,
|
objectEntity.name,
|
||||||
objectEntity.components
|
apiComponents
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/**
|
||||||
|
* Runtime color for updating instance objects
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param parentObject GameLib.D3.*
|
||||||
|
* @param apiColor GameLib.API.Color
|
||||||
|
* @param grain Number
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Color = function (graphics, parentObject, apiColor, grain) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.API.Color.call(
|
||||||
|
this,
|
||||||
|
apiColor.r,
|
||||||
|
apiColor.g,
|
||||||
|
apiColor.b,
|
||||||
|
apiColor.a
|
||||||
|
);
|
||||||
|
|
||||||
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||||
|
grain = 0.001;
|
||||||
|
}
|
||||||
|
this.grain = grain;
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.Color.prototype = Object.create(GameLib.API.Color.prototype);
|
||||||
|
GameLib.Color.prototype.constructor = GameLib.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance color
|
||||||
|
* @param update
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.Color.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
instance.r = this.r;
|
||||||
|
instance.g = this.g;
|
||||||
|
instance.b = this.b;
|
||||||
|
} else {
|
||||||
|
instance = new THREE.Color(this.r, this.g, this.b);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance color, calls updateInstance on the parent object
|
||||||
|
*/
|
||||||
|
GameLib.Color.prototype.updateInstance = function() {
|
||||||
|
|
||||||
|
this.createInstance(true);
|
||||||
|
|
||||||
|
if (this.parentObject.updateInstance) {
|
||||||
|
this.parentObject.updateInstance();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts runtime color to API Color
|
||||||
|
* @returns {GameLib.API.Color}
|
||||||
|
*/
|
||||||
|
GameLib.Color.prototype.toApiColor = function() {
|
||||||
|
return new GameLib.API.Color(
|
||||||
|
this.r,
|
||||||
|
this.g,
|
||||||
|
this.b,
|
||||||
|
this.a
|
||||||
|
);
|
||||||
|
};
|
|
@ -1,10 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* Component Interface
|
* Component Interface
|
||||||
|
* @constructor
|
||||||
* @param componentType
|
* @param componentType
|
||||||
* @param linkedObjects
|
* @param linkedObjects
|
||||||
* @param loaded (indicates whether the linked Objects for this component has been loaded)
|
* @param loaded
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
|
||||||
*/
|
*/
|
||||||
GameLib.Component = function(
|
GameLib.Component = function(
|
||||||
componentType,
|
componentType,
|
||||||
|
@ -12,30 +12,23 @@ GameLib.Component = function(
|
||||||
loaded,
|
loaded,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
this.componentType = componentType;
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
if (GameLib.Utils.UndefinedOrNull(linkedObjects)) {
|
componentType,
|
||||||
linkedObjects = {};
|
linkedObjects,
|
||||||
}
|
loaded,
|
||||||
this.linkedObjects = linkedObjects;
|
parentEntity
|
||||||
|
);
|
||||||
if (GameLib.Utils.UndefinedOrNull(loaded)) {
|
|
||||||
loaded = false;
|
|
||||||
}
|
|
||||||
this.loaded = loaded;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
||||||
parentEntity = null;
|
|
||||||
}
|
|
||||||
this.parentEntity = parentEntity;
|
|
||||||
|
|
||||||
this.linkedObjects.parentEntity = GameLib.Entity;
|
this.linkedObjects.parentEntity = GameLib.Entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
|
GameLib.Component.prototype.constructor = GameLib.Component;
|
||||||
|
|
||||||
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING = 0x1;
|
GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING = 0x1;
|
||||||
GameLib.Component.COMPONENT_RENDERABLE = 0x2;
|
GameLib.Component.COMPONENT_MATERIAL = 0x2;
|
||||||
GameLib.Component.COMPONENT_RENDERER = 0x3;
|
GameLib.Component.COMPONENT_RENDERER = 0x3;
|
||||||
GameLib.Component.COMPONENT_EDITOR_INPUT = 0x4;
|
|
||||||
GameLib.Component.COMPONENT_LOOK_AT = 0x5;
|
GameLib.Component.COMPONENT_LOOK_AT = 0x5;
|
||||||
GameLib.Component.COMPONENT_CAMERA = 0x6;
|
GameLib.Component.COMPONENT_CAMERA = 0x6;
|
||||||
GameLib.Component.COMPONENT_FOLLOW = 0x7;
|
GameLib.Component.COMPONENT_FOLLOW = 0x7;
|
||||||
|
@ -43,8 +36,11 @@ 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;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Components are linked at runtime - for storing, we just store the ID
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
GameLib.Component.prototype.toApiComponent = function() {
|
GameLib.Component.prototype.toApiComponent = function() {
|
||||||
return this.id;
|
return this.id;
|
||||||
};
|
};
|
|
@ -10,4 +10,17 @@ GameLib.D3.API.BoneWeight = function (
|
||||||
) {
|
) {
|
||||||
this.boneIndex = boneIndex;
|
this.boneIndex = boneIndex;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.BoneWeight
|
||||||
|
* @param objectBoneWeight
|
||||||
|
* @returns {GameLib.D3.API.BoneWeight}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.BoneWeight.FromObjectBoneWeight = function(objectBoneWeight) {
|
||||||
|
return new GameLib.D3.API.BoneWeight(
|
||||||
|
objectBoneWeight.boneIndex,
|
||||||
|
objectBoneWeight.weight
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
GameLib.D3.API.Color = function (r, g, b, a) {
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(r)) {
|
|
||||||
r = 1;
|
|
||||||
}
|
|
||||||
this.r = r;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(g)) {
|
|
||||||
g = 1;
|
|
||||||
}
|
|
||||||
this.g = g;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(b)) {
|
|
||||||
b = 1;
|
|
||||||
}
|
|
||||||
this.b = b;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(a)) {
|
|
||||||
a = 0;
|
|
||||||
}
|
|
||||||
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
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
|
@ -1,227 +0,0 @@
|
||||||
/**
|
|
||||||
* Superset for storing Components to API, and generating them from componentType
|
|
||||||
* @param id
|
|
||||||
* @param name
|
|
||||||
* @param componentType
|
|
||||||
* @param camera GameLib.D3.Camera
|
|
||||||
* @param parentEntity GameLib.Entity
|
|
||||||
* @param targetEntity GameLib.Entity
|
|
||||||
* @param targetOffset
|
|
||||||
* @param minDistance
|
|
||||||
* @param moveSpeed
|
|
||||||
* @param target
|
|
||||||
* @param targetToParent
|
|
||||||
* @param rotatedTargetOffset
|
|
||||||
* @param rotated
|
|
||||||
* @param rotationSpeed
|
|
||||||
* @param lookAtMatrix
|
|
||||||
* @param spline GameLib.D3.Spline
|
|
||||||
* @param mesh GameLib.D3.Mesh
|
|
||||||
* @param accelleration
|
|
||||||
* @param maxSpeed
|
|
||||||
* @param baseOffset
|
|
||||||
* @param maxOffset
|
|
||||||
* @param steeringSpeed
|
|
||||||
* @param up
|
|
||||||
* @param currentOffset
|
|
||||||
* @param currentPathValue
|
|
||||||
* @param currentSpeed
|
|
||||||
* @param direction
|
|
||||||
* @param currentPosition
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.API.Component = function(
|
|
||||||
// General
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
componentType,
|
|
||||||
parentEntity,
|
|
||||||
|
|
||||||
// Camera Component
|
|
||||||
camera,
|
|
||||||
|
|
||||||
|
|
||||||
// Follow Component
|
|
||||||
targetEntity,
|
|
||||||
targetOffset,
|
|
||||||
minDistance,
|
|
||||||
moveSpeed,
|
|
||||||
target,
|
|
||||||
targetToParent,
|
|
||||||
rotatedTargetOffset,
|
|
||||||
rotated,
|
|
||||||
|
|
||||||
// LookAt Component
|
|
||||||
rotationSpeed,
|
|
||||||
lookAtMatrix,
|
|
||||||
up,
|
|
||||||
|
|
||||||
// Path Following Component
|
|
||||||
spline,
|
|
||||||
mesh,
|
|
||||||
accelleration,
|
|
||||||
maxSpeed,
|
|
||||||
baseOffset,
|
|
||||||
maxOffset,
|
|
||||||
steeringSpeed,
|
|
||||||
currentOffset,
|
|
||||||
currentPathValue,
|
|
||||||
currentSpeed,
|
|
||||||
direction,
|
|
||||||
currentPosition
|
|
||||||
) {
|
|
||||||
/**
|
|
||||||
* General
|
|
||||||
*/
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
||||||
id = GameLib.Utils.RandomId();
|
|
||||||
}
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'component-unnamed';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(componentType)) {
|
|
||||||
componentType = GameLib.Component.COMPONENT_INTERFACE;
|
|
||||||
}
|
|
||||||
this.componentType = componentType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Camera Component
|
|
||||||
*/
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
||||||
parentEntity = null;
|
|
||||||
}
|
|
||||||
this.parentEntity = parentEntity;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
|
||||||
camera = null;
|
|
||||||
}
|
|
||||||
this.camera = camera;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Follow Component
|
|
||||||
*/
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(targetEntity)) {
|
|
||||||
targetEntity = null;
|
|
||||||
}
|
|
||||||
this.targetEntity = targetEntity;
|
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(targetOffset)) {
|
|
||||||
targetOffset = new GameLib.API.Vector3(0, 0, 0);
|
|
||||||
}
|
|
||||||
this.targetOffset = targetOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(moveSpeed)) {
|
|
||||||
moveSpeed = 12.5;
|
|
||||||
}
|
|
||||||
this.moveSpeed = moveSpeed;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(minDistance)) {
|
|
||||||
minDistance = 0;
|
|
||||||
}
|
|
||||||
this.minDistance = minDistance;
|
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(target)) {
|
|
||||||
target = new GameLib.API.Vector3(0, 0, 0);
|
|
||||||
}
|
|
||||||
this.target = target;
|
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(targetToParent)) {
|
|
||||||
targetToParent = new GameLib.API.Vector3(0, 0, 0);
|
|
||||||
}
|
|
||||||
this.targetToParent = targetToParent;
|
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(rotatedTargetOffset)) {
|
|
||||||
rotatedTargetOffset = new GameLib.API.Vector3(0, 0, 0);
|
|
||||||
}
|
|
||||||
this.rotatedTargetOffset = rotatedTargetOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(rotated)) {
|
|
||||||
rotated = new GameLib.API.Quaternion();
|
|
||||||
}
|
|
||||||
this.rotated = rotated;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LookAt Component
|
|
||||||
*/
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(rotationSpeed)) {
|
|
||||||
rotationSpeed = 22.0;
|
|
||||||
}
|
|
||||||
this.rotationSpeed = rotationSpeed;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(lookAtMatrix)) {
|
|
||||||
lookAtMatrix = new GameLib.API.Matrix4();
|
|
||||||
}
|
|
||||||
this.lookAtMatrix = lookAtMatrix;
|
|
||||||
|
|
||||||
if(GameLib.Utils.UndefinedOrNull(up)) {
|
|
||||||
up = new GameLib.API.Vector3(0, 1, 0);
|
|
||||||
}
|
|
||||||
this.up = up;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Path Following Component
|
|
||||||
*/
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(spline)) {
|
|
||||||
spline = null;
|
|
||||||
}
|
|
||||||
this.spline = spline;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(mesh)) {
|
|
||||||
mesh = null;
|
|
||||||
}
|
|
||||||
this.mesh = mesh;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(accelleration)) {
|
|
||||||
accelleration = 0.1;
|
|
||||||
}
|
|
||||||
this.accelleration = accelleration;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(maxSpeed)) {
|
|
||||||
maxSpeed = 0.03;
|
|
||||||
}
|
|
||||||
this.maxSpeed = maxSpeed;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(baseOffset)) {
|
|
||||||
baseOffset = new GameLib.API.Vector3();
|
|
||||||
}
|
|
||||||
this.baseOffset = baseOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(maxOffset)) {
|
|
||||||
maxOffset = new GameLib.API.Vector3(10, 10, 10);
|
|
||||||
}
|
|
||||||
this.maxOffset = maxOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(steeringSpeed)) {
|
|
||||||
steeringSpeed = 1.0;
|
|
||||||
}
|
|
||||||
this.steeringSpeed = steeringSpeed;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(currentOffset)) {
|
|
||||||
currentOffset = new GameLib.API.Vector3();
|
|
||||||
}
|
|
||||||
this.currentOffset = currentOffset;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(currentPathValue)) {
|
|
||||||
currentPathValue = 0;
|
|
||||||
}
|
|
||||||
this.currentPathValue = currentPathValue;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(currentSpeed)) {
|
|
||||||
currentSpeed = 0;
|
|
||||||
}
|
|
||||||
this.currentSpeed = currentSpeed;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(direction)) {
|
|
||||||
direction = 1;
|
|
||||||
}
|
|
||||||
this.direction = direction;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(currentPosition)) {
|
|
||||||
currentPosition = new GameLib.API.Vector3();
|
|
||||||
}
|
|
||||||
this.currentPosition = currentPosition;
|
|
||||||
};
|
|
|
@ -78,3 +78,22 @@ GameLib.D3.API.Follow = function (
|
||||||
|
|
||||||
GameLib.D3.API.Follow.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Follow.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.API.Follow.prototype.constructor = GameLib.D3.API.Follow;
|
GameLib.D3.API.Follow.prototype.constructor = GameLib.D3.API.Follow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Follow
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.API.Follow}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Follow.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Follow(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.currentComponent,
|
||||||
|
objectComponent.targetComponent,
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.targetPositionOffset),
|
||||||
|
objectComponent.minDistance,
|
||||||
|
objectComponent.moveSpeed,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
* @param heightOffset
|
* @param heightOffset
|
||||||
* @param distance
|
* @param distance
|
||||||
* @param distanceGrain
|
* @param distanceGrain
|
||||||
|
* @param rotationFactor
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Input.Drive = function (
|
GameLib.D3.API.Input.Drive = function (
|
||||||
|
@ -107,3 +108,27 @@ GameLib.D3.API.Input.Drive = function (
|
||||||
|
|
||||||
GameLib.D3.API.Input.Drive.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Input.Drive.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.API.Input.Drive.prototype.constructor = GameLib.D3.API.Input.Drive;
|
GameLib.D3.API.Input.Drive.prototype.constructor = GameLib.D3.API.Input.Drive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Input.Drive
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.API.Input.Drive}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Input.Drive.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Input.Drive(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.domElementId,
|
||||||
|
objectComponent.pathFollowingComponent,
|
||||||
|
objectComponent.parentEntity,
|
||||||
|
objectComponent.wheelFL,
|
||||||
|
objectComponent.wheelFR,
|
||||||
|
objectComponent.wheelRL,
|
||||||
|
objectComponent.wheelRR,
|
||||||
|
objectComponent.heightOffset,
|
||||||
|
objectComponent.distance,
|
||||||
|
objectComponent.distanceGrain,
|
||||||
|
objectComponent.rotationFactor
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -60,7 +60,7 @@ GameLib.D3.API.Light = function(
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||||
color = new GameLib.D3.API.Color(1,1,1,1);
|
color = new GameLib.API.Color(1,1,1,1);
|
||||||
}
|
}
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ GameLib.D3.API.Light.FromObjectLight = function(objectLight) {
|
||||||
objectLight.id,
|
objectLight.id,
|
||||||
objectLight.lightType,
|
objectLight.lightType,
|
||||||
objectLight.name,
|
objectLight.name,
|
||||||
GameLib.D3.API.Color.FromObjectColor(objectLight.color),
|
GameLib.API.Color.FromObjectColor(objectLight.color),
|
||||||
objectLight.intensity,
|
objectLight.intensity,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectLight.position),
|
GameLib.API.Vector3.FromObjectVector(objectLight.position),
|
||||||
GameLib.API.Vector3.FromObjectVector(objectLight.targetPosition),
|
GameLib.API.Vector3.FromObjectVector(objectLight.targetPosition),
|
||||||
|
|
|
@ -70,4 +70,22 @@ GameLib.D3.API.LookAt = function (
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.LookAt.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.API.LookAt.prototype.constructor = GameLib.D3.API.LookAt;
|
GameLib.D3.API.LookAt.prototype.constructor = GameLib.D3.API.LookAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.LookAt
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.API.LookAt}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.LookAt.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.LookAt(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.currentComponent,
|
||||||
|
objectComponent.targetComponent,
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.targetPositionOffset),
|
||||||
|
objectComponent.rotationSpeed,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -146,18 +146,18 @@ GameLib.D3.API.Material = function(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_MATERIAL,
|
GameLib.Component.COMPONENT_MATERIAL,
|
||||||
{
|
{
|
||||||
alphaMap : GameLib.D3.Texture,
|
'alphaMap' : GameLib.D3.Texture,
|
||||||
aoMap : GameLib.D3.Texture,
|
'aoMap' : GameLib.D3.Texture,
|
||||||
bumpMap : GameLib.D3.Texture,
|
'bumpMap' : GameLib.D3.Texture,
|
||||||
diffuseMap : GameLib.D3.Texture,
|
'diffuseMap' : GameLib.D3.Texture,
|
||||||
displacementMap : GameLib.D3.Texture,
|
'displacementMap' : GameLib.D3.Texture,
|
||||||
emissiveMap : GameLib.D3.Texture,
|
'emissiveMap' : GameLib.D3.Texture,
|
||||||
environmentMap : GameLib.D3.Texture,
|
'environmentMap' : GameLib.D3.Texture,
|
||||||
lightMap : GameLib.D3.Texture,
|
'lightMap' : GameLib.D3.Texture,
|
||||||
metalnessMap : GameLib.D3.Texture,
|
'metalnessMap' : GameLib.D3.Texture,
|
||||||
normalMap : GameLib.D3.Texture,
|
'normalMap' : GameLib.D3.Texture,
|
||||||
roughnessMap : GameLib.D3.Texture,
|
'roughnessMap' : GameLib.D3.Texture,
|
||||||
specularMap : GameLib.D3.Texture
|
'specularMap' : GameLib.D3.Texture
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
@ -194,7 +194,7 @@ GameLib.D3.API.Material = function(
|
||||||
this.transparent = transparent;
|
this.transparent = transparent;
|
||||||
|
|
||||||
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.API.Color(0.06, 0.06, 0.06, 0.06);
|
||||||
}
|
}
|
||||||
this.specular = specular;
|
this.specular = specular;
|
||||||
|
|
||||||
|
@ -209,12 +209,12 @@ GameLib.D3.API.Material = function(
|
||||||
this.aoMapIntensity = aoMapIntensity;
|
this.aoMapIntensity = aoMapIntensity;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(color)) {
|
if (GameLib.Utils.UndefinedOrNull(color)) {
|
||||||
color = new GameLib.D3.API.Color(1, 1, 1, 1)
|
color = new GameLib.API.Color(1, 1, 1, 1)
|
||||||
}
|
}
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(emissive)) {
|
if (GameLib.Utils.UndefinedOrNull(emissive)) {
|
||||||
emissive = new GameLib.D3.API.Color(0, 0, 0, 0);
|
emissive = new GameLib.API.Color(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
this.emissive = emissive;
|
this.emissive = emissive;
|
||||||
|
|
||||||
|
@ -473,6 +473,11 @@ GameLib.D3.API.Material = function(
|
||||||
}
|
}
|
||||||
this.emissiveMap = emissiveMap;
|
this.emissiveMap = emissiveMap;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(environmentMap)) {
|
||||||
|
environmentMap = null;
|
||||||
|
}
|
||||||
|
this.environmentMap = environmentMap;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(lightMap)) {
|
if (GameLib.Utils.UndefinedOrNull(lightMap)) {
|
||||||
lightMap = null;
|
lightMap = null;
|
||||||
}
|
}
|
||||||
|
@ -577,11 +582,11 @@ GameLib.D3.API.Material.FromObjectMaterial = function(objectMaterial) {
|
||||||
objectMaterial.opacity,
|
objectMaterial.opacity,
|
||||||
objectMaterial.side,
|
objectMaterial.side,
|
||||||
objectMaterial.transparent,
|
objectMaterial.transparent,
|
||||||
GameLib.D3.API.Color.FromObjectColor(objectMaterial.specular),
|
GameLib.API.Color.FromObjectColor(objectMaterial.specular),
|
||||||
objectMaterial.lightMapIntensity,
|
objectMaterial.lightMapIntensity,
|
||||||
objectMaterial.aoMapIntensity,
|
objectMaterial.aoMapIntensity,
|
||||||
GameLib.D3.API.Color.FromObjectColor(objectMaterial.color),
|
GameLib.API.Color.FromObjectColor(objectMaterial.color),
|
||||||
GameLib.D3.API.Color.FromObjectColor(objectMaterial.emissive),
|
GameLib.API.Color.FromObjectColor(objectMaterial.emissive),
|
||||||
objectMaterial.emissiveIntensity,
|
objectMaterial.emissiveIntensity,
|
||||||
objectMaterial.combine,
|
objectMaterial.combine,
|
||||||
objectMaterial.shininess,
|
objectMaterial.shininess,
|
||||||
|
|
|
@ -169,3 +169,42 @@ GameLib.D3.API.PathFollowing = function (
|
||||||
|
|
||||||
GameLib.D3.API.PathFollowing.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.PathFollowing.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.API.PathFollowing.prototype.constructor = GameLib.D3.API.PathFollowing;
|
GameLib.D3.API.PathFollowing.prototype.constructor = GameLib.D3.API.PathFollowing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an API path following component from an Object path following component
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.PathFollowing.FromObjectComponent = function(objectComponent) {
|
||||||
|
|
||||||
|
var apiRaycaster = null;
|
||||||
|
|
||||||
|
if (objectComponent.raycaster) {
|
||||||
|
apiRaycaster = GameLib.D3.API.Raycaster.FromObjectRaycaster(objectComponent.raycaster);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GameLib.D3.API.PathFollowing(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.spline,
|
||||||
|
objectComponent.mesh,
|
||||||
|
objectComponent.raytraceMesh,
|
||||||
|
objectComponent.accelleration,
|
||||||
|
objectComponent.maxSpeed,
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.baseOffset),
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.maxOffset),
|
||||||
|
objectComponent.steeringSpeed,
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.targetOffset),
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.currentOffset),
|
||||||
|
objectComponent.currentPathValue,
|
||||||
|
objectComponent.currentSpeed,
|
||||||
|
objectComponent.direction,
|
||||||
|
apiRaycaster,
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.currentPosition),
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.futurePosition),
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectComponent.up),
|
||||||
|
GameLib.API.Matrix4.FromObjectMatrix(objectComponent.rotationMatrix),
|
||||||
|
GameLib.API.Quaternion.FromObjectQuaternion(objectComponent.rotationVector),
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -19,3 +19,15 @@ GameLib.D3.API.Raycaster = function(
|
||||||
}
|
}
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an API raycaster from an Object raycaster
|
||||||
|
* @param objectRaycaster
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Raycaster.FromObjectRaycaster = function(objectRaycaster) {
|
||||||
|
return new GameLib.D3.API.Raycaster(
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectRaycaster.position),
|
||||||
|
GameLib.API.Vector3.FromObjectVector(objectRaycaster.direction)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
/**
|
|
||||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
|
||||||
* @param id String
|
|
||||||
* @param name String
|
|
||||||
* @param visible
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.API.Renderable = function (
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
visible
|
|
||||||
) {
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
|
||||||
this,
|
|
||||||
GameLib.Component.COMPONENT_RENDERABLE
|
|
||||||
);
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
||||||
id = GameLib.Utils.RandomId();
|
|
||||||
}
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = this.constructor.name;
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(visible)) {
|
|
||||||
visible = true;
|
|
||||||
}
|
|
||||||
this.visible = visible;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.API.Renderable.prototype = Object.create(GameLib.Component.prototype);
|
|
||||||
GameLib.D3.API.Renderable.prototype.constructor = GameLib.D3.API.Renderable;
|
|
|
@ -78,3 +78,22 @@ GameLib.D3.API.Renderer = function (
|
||||||
|
|
||||||
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
|
GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Renderer
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Renderer.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Renderer(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.scene,
|
||||||
|
objectComponent.camera,
|
||||||
|
objectComponent.autoClear,
|
||||||
|
objectComponent.localClipping,
|
||||||
|
objectComponent.width,
|
||||||
|
objectComponent.height,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* @param shapes GameLib.D3.API.Shape[]
|
* @param shapes GameLib.D3.API.Shape[]
|
||||||
* @param cameras
|
* @param cameras
|
||||||
* @param activeCameraIndex
|
* @param activeCameraIndex
|
||||||
|
* @param textures GameLib.D3.Texture[] - additional textures
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Scene = function(
|
GameLib.D3.API.Scene = function(
|
||||||
|
@ -30,7 +31,8 @@ GameLib.D3.API.Scene = function(
|
||||||
entityManager,
|
entityManager,
|
||||||
shapes,
|
shapes,
|
||||||
cameras,
|
cameras,
|
||||||
activeCameraIndex
|
activeCameraIndex,
|
||||||
|
textures
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
|
@ -101,6 +103,11 @@ GameLib.D3.API.Scene = function(
|
||||||
activeCameraIndex = 0;
|
activeCameraIndex = 0;
|
||||||
}
|
}
|
||||||
this.activeCameraIndex = activeCameraIndex;
|
this.activeCameraIndex = activeCameraIndex;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(textures)) {
|
||||||
|
textures = [];
|
||||||
|
}
|
||||||
|
this.textures = textures;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,10 +119,20 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
|
|
||||||
var apiEntityManager = null;
|
var apiEntityManager = null;
|
||||||
|
|
||||||
|
var apiTextures = null;
|
||||||
|
|
||||||
if (objectScene.entityManager) {
|
if (objectScene.entityManager) {
|
||||||
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectScene.entityManager);
|
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectScene.entityManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (objectScene.textures) {
|
||||||
|
apiTextures = objectScene.textures.map(
|
||||||
|
function(objectTexture) {
|
||||||
|
return GameLib.D3.API.Texture.FromObjectTexture(objectTexture)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.D3.API.Scene(
|
return new GameLib.D3.API.Scene(
|
||||||
objectScene.id,
|
objectScene.id,
|
||||||
objectScene.path,
|
objectScene.path,
|
||||||
|
@ -142,7 +159,8 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
return GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
|
return GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
objectScene.activeCameraIndex
|
objectScene.activeCameraIndex,
|
||||||
|
apiTextures
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,4 +37,22 @@ GameLib.D3.API.Spline = function(
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.Spline.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Spline.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.API.Spline.prototype.constructor = GameLib.D3.API.Spline;
|
GameLib.D3.API.Spline.prototype.constructor = GameLib.D3.API.Spline;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Spline
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Spline.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Spline(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.vertices.map(
|
||||||
|
function (objectVertex) {
|
||||||
|
return GameLib.API.Vector3.FromObjectVector(objectVertex);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -57,7 +57,7 @@ GameLib.D3.API.Texture = function(
|
||||||
this.typeId = typeId;
|
this.typeId = typeId;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = 'Texture (' + typeId + ')';
|
name = 'Texture (' + id + ')';
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ GameLib.D3.API.Texture = function(
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Texture.FromObjectTexture = function(objectTexture) {
|
GameLib.D3.API.Texture.FromObjectTexture = function(objectTexture) {
|
||||||
new GameLib.D3.API.Texture(
|
return new GameLib.D3.API.Texture(
|
||||||
objectTexture.id,
|
objectTexture.id,
|
||||||
objectTexture.textureType,
|
objectTexture.textureType,
|
||||||
objectTexture.name,
|
objectTexture.name,
|
||||||
|
|
|
@ -28,6 +28,10 @@ GameLib.D3.API.Vertex = function(
|
||||||
GameLib.D3.API.Vertex.FromObjectVertex = function(objectVertex) {
|
GameLib.D3.API.Vertex.FromObjectVertex = function(objectVertex) {
|
||||||
return new GameLib.D3.API.Vertex(
|
return new GameLib.D3.API.Vertex(
|
||||||
GameLib.API.Vector3.FromObjectVector(objectVertex.position),
|
GameLib.API.Vector3.FromObjectVector(objectVertex.position),
|
||||||
objectVertex.boneWeights
|
objectVertex.boneWeights.map(
|
||||||
|
function(boneWeight) {
|
||||||
|
return GameLib.D3.API.BoneWeight.FromObjectBoneWeight(boneWeight);
|
||||||
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiBoneWeight GameLib.D3.API.BoneWeight
|
* @param apiBoneWeight GameLib.D3.API.BoneWeight
|
||||||
*/
|
*/
|
||||||
GameLib.D3.BoneWeight = function RuntimeBoneWeight(
|
GameLib.D3.BoneWeight = function (
|
||||||
graphics,
|
graphics,
|
||||||
apiBoneWeight
|
apiBoneWeight
|
||||||
) {
|
) {
|
||||||
|
@ -16,40 +16,11 @@ GameLib.D3.BoneWeight = function RuntimeBoneWeight(
|
||||||
apiBoneWeight.boneIndex,
|
apiBoneWeight.boneIndex,
|
||||||
apiBoneWeight.weight
|
apiBoneWeight.weight
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.BoneWeight.prototype = Object.create(GameLib.D3.API.BoneWeight.prototype);
|
GameLib.D3.BoneWeight.prototype = Object.create(GameLib.D3.API.BoneWeight.prototype);
|
||||||
GameLib.D3.BoneWeight.prototype.constructor = GameLib.D3.BoneWeight;
|
GameLib.D3.BoneWeight.prototype.constructor = GameLib.D3.BoneWeight;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance boneWeight
|
|
||||||
* @param update boolean
|
|
||||||
*/
|
|
||||||
GameLib.D3.BoneWeight.prototype.createInstance = function(update) {
|
|
||||||
|
|
||||||
var instance = null;
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
//TODO - update instance with boneWeight info
|
|
||||||
instance = this.instance;
|
|
||||||
} else {
|
|
||||||
//TODO - fix this
|
|
||||||
instance = new THREE.Quaternion();
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the instance
|
|
||||||
*/
|
|
||||||
GameLib.D3.BoneWeight.prototype.updateInstance = function() {
|
|
||||||
this.instance = this.createInstance(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a GameLib.D3.BoneWeight to GameLib.D3.API.BoneWeight
|
* Converts a GameLib.D3.BoneWeight to GameLib.D3.API.BoneWeight
|
||||||
* @returns {GameLib.D3.API.BoneWeight}
|
* @returns {GameLib.D3.API.BoneWeight}
|
||||||
|
@ -75,10 +46,7 @@ GameLib.D3.BoneWeight.FromObjectBoneWeight = function(
|
||||||
graphics,
|
graphics,
|
||||||
objectBoneWeight
|
objectBoneWeight
|
||||||
) {
|
) {
|
||||||
var apiBoneWeight = new GameLib.D3.API.BoneWeight(
|
var apiBoneWeight = GameLib.D3.API.BoneWeight.FromObjectBoneWeight(objectBoneWeight);
|
||||||
objectBoneWeight.boneIndex,
|
|
||||||
objectBoneWeight.weight
|
|
||||||
);
|
|
||||||
|
|
||||||
var boneWeight = new GameLib.D3.BoneWeight(
|
var boneWeight = new GameLib.D3.BoneWeight(
|
||||||
graphics,
|
graphics,
|
||||||
|
|
|
@ -1,142 +0,0 @@
|
||||||
/**
|
|
||||||
* Runtime color for updating instance objects
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
|
||||||
* @param parentObject GameLib.D3.*
|
|
||||||
* @param apiColor GameLib.D3.API.Color
|
|
||||||
* @param grain Number
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.Color = function (graphics, parentObject, apiColor, grain) {
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
GameLib.D3.API.Color.call(
|
|
||||||
this,
|
|
||||||
apiColor.r,
|
|
||||||
apiColor.g,
|
|
||||||
apiColor.b,
|
|
||||||
apiColor.a
|
|
||||||
);
|
|
||||||
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
|
||||||
grain = 0.001;
|
|
||||||
}
|
|
||||||
this.grain = grain;
|
|
||||||
|
|
||||||
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
|
|
||||||
* @param update
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Color.prototype.createInstance = function(update) {
|
|
||||||
|
|
||||||
var instance = null;
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
instance = this.instance;
|
|
||||||
instance.r = this.r;
|
|
||||||
instance.g = this.g;
|
|
||||||
instance.b = this.b;
|
|
||||||
} else {
|
|
||||||
instance = THREE.Color(this.r, this.g, this.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the instance color, calls updateInstance on the parent object
|
|
||||||
*/
|
|
||||||
GameLib.D3.Color.prototype.updateInstance = function() {
|
|
||||||
|
|
||||||
this.createInstance(true);
|
|
||||||
|
|
||||||
if (this.parentObject.updateInstance) {
|
|
||||||
this.parentObject.updateInstance();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts runtime color to API Color
|
|
||||||
* @returns {GameLib.D3.API.Color}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Color.prototype.toApiColor = function() {
|
|
||||||
return new GameLib.D3.API.Color(
|
|
||||||
this.r,
|
|
||||||
this.g,
|
|
||||||
this.b,
|
|
||||||
this.a
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the current color to HTML hex format (ex. #ffffff)
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Color.prototype.toHex = function() {
|
|
||||||
|
|
||||||
if (this.r < 0) {
|
|
||||||
this.r = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.g < 0) {
|
|
||||||
this.g = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.b < 0) {
|
|
||||||
this.b = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.r > 1) {
|
|
||||||
this.r = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.g > 1) {
|
|
||||||
this.g = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.b > 1) {
|
|
||||||
this.b = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var rf = Math.floor(this.r >= 1? 255 : this.r * 256.0).toString(16);
|
|
||||||
var gf = Math.floor(this.g >= 1? 255 : this.g * 256.0).toString(16);
|
|
||||||
var bf = Math.floor(this.b >= 1? 255 : this.b * 256.0).toString(16);
|
|
||||||
|
|
||||||
if (rf.length < 2) {
|
|
||||||
rf = '0' + rf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gf.length < 2) {
|
|
||||||
gf = '0' + gf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bf.length < 2) {
|
|
||||||
bf = '0' + bf;
|
|
||||||
}
|
|
||||||
|
|
||||||
return '#' + rf + gf + bf;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets this object color to what the hex value is
|
|
||||||
* @param hex
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Color.prototype.fromHex = function(hex) {
|
|
||||||
|
|
||||||
var matches = hex.match(new RegExp('#+(..)(..)(..)'));
|
|
||||||
|
|
||||||
this.r = parseInt(matches[1], 16) / 255.0;
|
|
||||||
this.g = parseInt(matches[2], 16) / 255.0;
|
|
||||||
this.b = parseInt(matches[3], 16) / 255.0;
|
|
||||||
};
|
|
|
@ -1,13 +1,11 @@
|
||||||
/**
|
/**
|
||||||
* Runtime Follow Component
|
* Runtime Follow Component
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject
|
|
||||||
* @param apiFollow
|
* @param apiFollow
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Follow = function RuntimeFollow(
|
GameLib.D3.Follow = function (
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiFollow
|
apiFollow
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
@ -77,24 +75,10 @@ GameLib.D3.Follow.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
GameLib.D3.Follow.FromObjectComponent = function(graphics, objectComponent) {
|
GameLib.D3.Follow.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
var apiFollow = new GameLib.D3.API.Follow(
|
var apiFollow = GameLib.D3.API.Follow.FromObjectComponent(objectComponent);
|
||||||
objectComponent.id,
|
|
||||||
objectComponent.name,
|
|
||||||
objectComponent.currentComponent,
|
|
||||||
objectComponent.targetComponent,
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.targetPositionOffset.x,
|
|
||||||
objectComponent.targetPositionOffset.y,
|
|
||||||
objectComponent.targetPositionOffset.z
|
|
||||||
),
|
|
||||||
objectComponent.minDistance,
|
|
||||||
objectComponent.moveSpeed,
|
|
||||||
objectComponent.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.Follow(
|
return new GameLib.D3.Follow(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
|
||||||
apiFollow
|
apiFollow
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,20 +5,14 @@
|
||||||
* @param apiInputDrive GameLib.D3.API.Input.Drive
|
* @param apiInputDrive GameLib.D3.API.Input.Drive
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Input.Drive = function RuntimeInputDrive(
|
GameLib.D3.Input.Drive = function (
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiInputDrive
|
apiInputDrive
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
|
||||||
parentObject = null;
|
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.D3.API.Input.Drive.call(
|
GameLib.D3.API.Input.Drive.call(
|
||||||
this,
|
this,
|
||||||
apiInputDrive.id,
|
apiInputDrive.id,
|
||||||
|
@ -89,7 +83,10 @@ GameLib.D3.Input.Drive.prototype.updateInstance = function() {
|
||||||
this.instance = this.createInstance(true);
|
this.instance = this.createInstance(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.toApiComponent = function() {
|
||||||
|
|
||||||
var apiInputDrive = new GameLib.D3.API.Input.Drive(
|
var apiInputDrive = new GameLib.D3.API.Input.Drive(
|
||||||
|
@ -113,25 +110,10 @@ GameLib.D3.Input.Drive.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
GameLib.D3.Input.Drive.FromObjectComponent = function(graphics, objectComponent) {
|
GameLib.D3.Input.Drive.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
var apiInputDrive = new GameLib.D3.API.Input.Drive(
|
var apiInputDrive = GameLib.D3.API.Input.Drive.FromObjectComponent(objectComponent);
|
||||||
objectComponent.id,
|
|
||||||
objectComponent.name,
|
|
||||||
objectComponent.domElementId,
|
|
||||||
objectComponent.pathFollowingComponent,
|
|
||||||
objectComponent.parentEntity,
|
|
||||||
objectComponent.wheelFL,
|
|
||||||
objectComponent.wheelFR,
|
|
||||||
objectComponent.wheelRL,
|
|
||||||
objectComponent.wheelRR,
|
|
||||||
objectComponent.heightOffset,
|
|
||||||
objectComponent.distance,
|
|
||||||
objectComponent.distanceGrain,
|
|
||||||
objectComponent.rotationFactor
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.Input.Drive(
|
return new GameLib.D3.Input.Drive(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
|
||||||
apiInputDrive
|
apiInputDrive
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ GameLib.D3.Light = function Light(
|
||||||
apiLight.parentEntity
|
apiLight.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.color = new GameLib.D3.Color(
|
this.color = new GameLib.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.color,
|
this.color,
|
||||||
|
|
|
@ -1,23 +1,16 @@
|
||||||
/**
|
/**
|
||||||
* Entities with LookAt component looks to targetPosition (default up is 0,1,0)
|
* Entities with LookAt component looks to targetPosition (default up is 0,1,0)
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject
|
|
||||||
* @param apiLookAt GameLib.D3.API.LookAt
|
* @param apiLookAt GameLib.D3.API.LookAt
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.LookAt = function RuntimeLookAt(
|
GameLib.D3.LookAt = function (
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiLookAt
|
apiLookAt
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
|
||||||
parentObject = null;
|
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.D3.API.LookAt.call(
|
GameLib.D3.API.LookAt.call(
|
||||||
this,
|
this,
|
||||||
apiLookAt.id,
|
apiLookAt.id,
|
||||||
|
@ -80,25 +73,16 @@ GameLib.D3.LookAt.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
GameLib.D3.LookAt.FromObjectComponent = function(graphics, objectComponent) {
|
GameLib.D3.LookAt.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
var apiLookAt = new GameLib.D3.API.LookAt(
|
var apiLookAt = GameLib.D3.API.LookAt.FromObjectComponent(objectComponent);
|
||||||
objectComponent.id,
|
|
||||||
objectComponent.name,
|
|
||||||
objectComponent.currentComponent,
|
|
||||||
objectComponent.targetComponent,
|
|
||||||
objectComponent.targetPositionOffset,
|
|
||||||
objectComponent.rotationSpeed,
|
|
||||||
objectComponent.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.LookAt(
|
return new GameLib.D3.LookAt(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
|
||||||
apiLookAt
|
apiLookAt
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the component
|
* Looks at using time
|
||||||
* @param deltaTime
|
* @param deltaTime
|
||||||
*/
|
*/
|
||||||
GameLib.D3.LookAt.prototype.update = function(deltaTime) {
|
GameLib.D3.LookAt.prototype.update = function(deltaTime) {
|
||||||
|
@ -111,14 +95,6 @@ GameLib.D3.LookAt.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
this.targetPosition.updateInstance();
|
this.targetPosition.updateInstance();
|
||||||
|
|
||||||
//
|
|
||||||
// this.currentComponent.instance.lookAt(this.targetPosition);
|
|
||||||
//
|
|
||||||
// this.currentComponent.instance.updateProjectionMatrix();
|
|
||||||
//
|
|
||||||
// // this.currentComponent.updateInstance();
|
|
||||||
// return;
|
|
||||||
|
|
||||||
this.lookAtMatrix.lookAt(
|
this.lookAtMatrix.lookAt(
|
||||||
this.currentComponent.position,
|
this.currentComponent.position,
|
||||||
this.targetPosition,
|
this.targetPosition,
|
||||||
|
|
|
@ -89,120 +89,144 @@ GameLib.D3.Material = function Material(
|
||||||
apiMaterial.parentEntity
|
apiMaterial.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.specular = new GameLib.D3.Color(
|
this.specular = new GameLib.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.specular
|
this.specular
|
||||||
);
|
);
|
||||||
|
|
||||||
this.color = new GameLib.D3.Color(
|
this.color = new GameLib.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.color
|
this.color
|
||||||
);
|
);
|
||||||
|
|
||||||
this.emissive = new GameLib.D3.Color(
|
this.emissive = new GameLib.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
this.emissive
|
this.emissive
|
||||||
);
|
);
|
||||||
|
|
||||||
this.alphaMap = new GameLib.D3.Texture(
|
if (this.alphaMap) {
|
||||||
this.graphics,
|
this.alphaMap = new GameLib.D3.Texture(
|
||||||
this.alphaMap,
|
this.graphics,
|
||||||
this,
|
this.alphaMap,
|
||||||
'alphaMap',
|
this,
|
||||||
imageFactory
|
'alphaMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.aoMap = new GameLib.D3.Texture(
|
if (this.aoMap) {
|
||||||
this.graphics,
|
this.aoMap = new GameLib.D3.Texture(
|
||||||
this.aoMap,
|
this.graphics,
|
||||||
this,
|
this.aoMap,
|
||||||
'aoMap',
|
this,
|
||||||
imageFactory
|
'aoMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.bumpMap = new GameLib.D3.Texture(
|
if (this.bumpMap) {
|
||||||
this.graphics,
|
this.bumpMap = new GameLib.D3.Texture(
|
||||||
this.bumpMap,
|
this.graphics,
|
||||||
this,
|
this.bumpMap,
|
||||||
'bumpMap',
|
this,
|
||||||
imageFactory
|
'bumpMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.diffuseMap = new GameLib.D3.Texture(
|
if (this.diffuseMap) {
|
||||||
this.graphics,
|
this.diffuseMap = new GameLib.D3.Texture(
|
||||||
this.diffuseMap,
|
this.graphics,
|
||||||
this,
|
this.diffuseMap,
|
||||||
'map',
|
this,
|
||||||
imageFactory
|
'map',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.displacementMap = new GameLib.D3.Texture(
|
if (this.displacementMap) {
|
||||||
this.graphics,
|
this.displacementMap = new GameLib.D3.Texture(
|
||||||
this.displacementMap,
|
this.graphics,
|
||||||
this,
|
this.displacementMap,
|
||||||
'displacementMap',
|
this,
|
||||||
imageFactory
|
'displacementMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.emissiveMap = new GameLib.D3.Texture(
|
if (this.emissiveMap) {
|
||||||
this.graphics,
|
this.emissiveMap = new GameLib.D3.Texture(
|
||||||
this.emissiveMap,
|
this.graphics,
|
||||||
this,
|
this.emissiveMap,
|
||||||
'emissiveMap',
|
this,
|
||||||
imageFactory
|
'emissiveMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.environmentMap = new GameLib.D3.Texture(
|
if (this.environmentMap) {
|
||||||
this.graphics,
|
this.environmentMap = new GameLib.D3.Texture(
|
||||||
this.environmentMap,
|
this.graphics,
|
||||||
this,
|
this.environmentMap,
|
||||||
'envMap',
|
this,
|
||||||
imageFactory
|
'envMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.lightMap = new GameLib.D3.Texture(
|
if (this.lightMap) {
|
||||||
this.graphics,
|
this.lightMap = new GameLib.D3.Texture(
|
||||||
this.lightMap,
|
this.graphics,
|
||||||
this,
|
this.lightMap,
|
||||||
'lightMap',
|
this,
|
||||||
imageFactory
|
'lightMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.metalnessMap = new GameLib.D3.Texture(
|
if (this.metalnessMap) {
|
||||||
this.graphics,
|
this.metalnessMap = new GameLib.D3.Texture(
|
||||||
this.metalnessMap,
|
this.graphics,
|
||||||
this,
|
this.metalnessMap,
|
||||||
'metalnessMap',
|
this,
|
||||||
imageFactory
|
'metalnessMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.normalMap = new GameLib.D3.Texture(
|
if (this.normalMap) {
|
||||||
this.graphics,
|
this.normalMap = new GameLib.D3.Texture(
|
||||||
this.normalMap,
|
this.graphics,
|
||||||
this,
|
this.normalMap,
|
||||||
'normalMap',
|
this,
|
||||||
imageFactory
|
'normalMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.roughnessMap = new GameLib.D3.Texture(
|
if (this.roughnessMap) {
|
||||||
this.graphics,
|
this.roughnessMap = new GameLib.D3.Texture(
|
||||||
this.roughnessMap,
|
this.graphics,
|
||||||
this,
|
this.roughnessMap,
|
||||||
'roughnessMap',
|
this,
|
||||||
imageFactory
|
'roughnessMap',
|
||||||
);
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.specularMap) {
|
||||||
|
this.specularMap = new GameLib.D3.Texture(
|
||||||
|
this.graphics,
|
||||||
|
this.specularMap,
|
||||||
|
this,
|
||||||
|
'specularMap',
|
||||||
|
imageFactory
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.specularMap = new GameLib.D3.Texture(
|
|
||||||
this.graphics,
|
|
||||||
this.specularMap,
|
|
||||||
this,
|
|
||||||
'specularMap',
|
|
||||||
imageFactory
|
|
||||||
);
|
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -477,40 +501,64 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
if (instance.hasOwnProperty(property)) {
|
if (instance.hasOwnProperty(property)) {
|
||||||
|
|
||||||
if (property == 'alphaMap') {
|
if (property == 'alphaMap') {
|
||||||
instance.alphaMap = this.alphaMap.instance;
|
if (this.alphaMap) {
|
||||||
|
instance.alphaMap = this.alphaMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'aoMap') {
|
else if (property == 'aoMap') {
|
||||||
instance.aoMap = this.aoMap.instance;
|
if (this.aoMap) {
|
||||||
|
instance.aoMap = this.aoMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'bumpMap') {
|
else if (property == 'bumpMap') {
|
||||||
instance.bumpMap = this.bumpMap.instance;
|
if (this.bumpMap) {
|
||||||
|
instance.bumpMap = this.bumpMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'map') {
|
else if (property == 'map') {
|
||||||
instance.map = this.diffuseMap.instance;
|
if (this.diffuseMap) {
|
||||||
|
instance.map = this.diffuseMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'displacementMap') {
|
else if (property == 'displacementMap') {
|
||||||
instance.displacementMap = this.displacementMap.instance;
|
if (this.displacementMap) {
|
||||||
|
instance.displacementMap = this.displacementMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'emissiveMap') {
|
else if (property == 'emissiveMap') {
|
||||||
instance.emissiveMap = this.emissiveMap.instance;
|
if (this.emissiveMap) {
|
||||||
|
instance.emissiveMap = this.emissiveMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'envMap') {
|
else if (property == 'envMap') {
|
||||||
instance.envMap = this.environmentMap.instance;
|
if (this.environmentMap) {
|
||||||
|
instance.envMap = this.environmentMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'lightMap') {
|
else if (property == 'lightMap') {
|
||||||
instance.lightMap = this.lightMap.instance;
|
if (this.lightMap) {
|
||||||
|
instance.lightMap = this.lightMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'metalnessMap') {
|
else if (property == 'metalnessMap') {
|
||||||
instance.metalnessMap = this.metalnessMap.instance;
|
if (this.metalnessMap) {
|
||||||
|
instance.metalnessMap = this.metalnessMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'normalMap') {
|
else if (property == 'normalMap') {
|
||||||
instance.normalMap = this.normalMap.instance;
|
if (this.normalMap) {
|
||||||
|
instance.normalMap = this.normalMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'roughnessMap') {
|
else if (property == 'roughnessMap') {
|
||||||
instance.roughnessMap = this.roughnessMap.instance;
|
if (this.roughnessMap) {
|
||||||
|
instance.roughnessMap = this.roughnessMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'specularMap') {
|
else if (property == 'specularMap') {
|
||||||
instance.specularMap = this.specularMap.instance;
|
if (this.specularMap) {
|
||||||
|
instance.specularMap = this.specularMap.instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (property == 'size') {
|
else if (property == 'size') {
|
||||||
instance.size = this.pointSize;
|
instance.size = this.pointSize;
|
||||||
|
@ -520,7 +568,7 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
else if (instance[property] instanceof THREE.Color) {
|
else if (instance[property] instanceof THREE.Color) {
|
||||||
instance[property].copy(this[property])
|
instance[property].copy(this[property])
|
||||||
} else {
|
} else if (this.hasOwnProperty(property)) {
|
||||||
instance[property] = this[property];
|
instance[property] = this[property];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,6 +597,66 @@ GameLib.D3.Material.prototype.clone = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Material.prototype.toApiMaterial = function() {
|
GameLib.D3.Material.prototype.toApiMaterial = function() {
|
||||||
|
|
||||||
|
var apiAlphaMap = null;
|
||||||
|
if (this.alphaMap) {
|
||||||
|
apiAlphaMap = this.alphaMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiAoMap = null;
|
||||||
|
if (this.aoMap) {
|
||||||
|
apiAoMap = this.aoMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiBumpMap = null;
|
||||||
|
if (this.bumpMap) {
|
||||||
|
apiBumpMap = this.bumpMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiDiffuseMap = null;
|
||||||
|
if (this.diffuseMap) {
|
||||||
|
apiDiffuseMap = this.diffuseMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiDisplacementMap = null;
|
||||||
|
if (this.displacementMap) {
|
||||||
|
apiDisplacementMap = this.displacementMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiEmissiveMap = null;
|
||||||
|
if (this.emissiveMap) {
|
||||||
|
apiEmissiveMap = this.emissiveMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiEnvironmentMap = null;
|
||||||
|
if (this.environmentMap) {
|
||||||
|
apiEnvironmentMap = this.environmentMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiLightMap = null;
|
||||||
|
if (this.lightMap) {
|
||||||
|
apiLightMap = this.lightMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiMetalnessMap = null;
|
||||||
|
if (this.metalnessMap) {
|
||||||
|
apiMetalnessMap = this.metalnessMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiNormalMap = null;
|
||||||
|
if (this.normalMap) {
|
||||||
|
apiNormalMap = this.normalMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiRoughnessMap = null;
|
||||||
|
if (this.roughnessMap) {
|
||||||
|
apiRoughnessMap = this.roughnessMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiSpecularMap = null;
|
||||||
|
if (this.specularMap) {
|
||||||
|
apiSpecularMap = this.specularMap.toApiTexture();
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.D3.API.Material(
|
return new GameLib.D3.API.Material(
|
||||||
this.id,
|
this.id,
|
||||||
this.materialType,
|
this.materialType,
|
||||||
|
@ -606,18 +714,18 @@ GameLib.D3.Material.prototype.toApiMaterial = function() {
|
||||||
this.pointSizeAttenuation,
|
this.pointSizeAttenuation,
|
||||||
this.spriteRotation,
|
this.spriteRotation,
|
||||||
this.envMapIntensity,
|
this.envMapIntensity,
|
||||||
this.alphaMap.toApiTexture(),
|
apiAlphaMap,
|
||||||
this.aoMap.toApiTexture(),
|
apiAoMap,
|
||||||
this.bumpMap.toApiTexture(),
|
apiBumpMap,
|
||||||
this.diffuseMap.toApiTexture(),
|
apiDiffuseMap,
|
||||||
this.displacementMap.toApiTexture(),
|
apiDisplacementMap,
|
||||||
this.emissiveMap.toApiTexture(),
|
apiEmissiveMap,
|
||||||
this.environmentMap.toApiTexture(),
|
apiEnvironmentMap,
|
||||||
this.lightMap.toApiTexture(),
|
apiLightMap,
|
||||||
this.metalnessMap.toApiTexture(),
|
apiMetalnessMap,
|
||||||
this.normalMap.toApiTexture(),
|
apiNormalMap,
|
||||||
this.roughnessMap.toApiTexture(),
|
apiRoughnessMap,
|
||||||
this.specularMap.toApiTexture(),
|
apiSpecularMap,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,10 +51,13 @@ GameLib.D3.Mesh = function (
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.skeleton = new GameLib.D3.Skeleton(
|
if (this.skeleton) {
|
||||||
this.graphics,
|
this.skeleton = new GameLib.D3.Skeleton(
|
||||||
this.skeleton
|
this.graphics,
|
||||||
);
|
this.skeleton
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
this.vertices = this.vertices.map(
|
this.vertices = this.vertices.map(
|
||||||
function (apiVertex) {
|
function (apiVertex) {
|
||||||
|
|
|
@ -1,24 +1,17 @@
|
||||||
/**
|
/**
|
||||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject
|
|
||||||
* @param apiPathFollowing GameLib.D3.API.PathFollowing
|
* @param apiPathFollowing GameLib.D3.API.PathFollowing
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.PathFollowing = function RuntimePathFollowing(
|
GameLib.D3.PathFollowing = function (
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiPathFollowing
|
apiPathFollowing
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
|
||||||
parentObject = null;
|
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.D3.API.PathFollowing.call(
|
GameLib.D3.API.PathFollowing.call(
|
||||||
this,
|
this,
|
||||||
apiPathFollowing.id,
|
apiPathFollowing.id,
|
||||||
|
@ -71,7 +64,6 @@ GameLib.D3.PathFollowing = function RuntimePathFollowing(
|
||||||
|
|
||||||
this.raycaster = new GameLib.D3.Raycaster(
|
this.raycaster = new GameLib.D3.Raycaster(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
this.raycaster
|
this.raycaster
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -105,7 +97,6 @@ GameLib.D3.PathFollowing = function RuntimePathFollowing(
|
||||||
this.rotationVector
|
this.rotationVector
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.mx = new GameLib.Utils.MovingAverage(10);
|
this.mx = new GameLib.Utils.MovingAverage(10);
|
||||||
this.my = new GameLib.Utils.MovingAverage(10);
|
this.my = new GameLib.Utils.MovingAverage(10);
|
||||||
this.mz = new GameLib.Utils.MovingAverage(10);
|
this.mz = new GameLib.Utils.MovingAverage(10);
|
||||||
|
@ -149,86 +140,19 @@ GameLib.D3.PathFollowing.prototype.toApiComponent = function() {
|
||||||
return apiPathFollowing;
|
return apiPathFollowing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object path following to GameLib.D3.PathFollowing
|
||||||
|
* @param graphics
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.PathFollowing}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
GameLib.D3.PathFollowing.FromObjectComponent = function(graphics, objectComponent) {
|
GameLib.D3.PathFollowing.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
var apiPathFollowing = new GameLib.D3.API.PathFollowing(
|
var apiPathFollowing = GameLib.D3.API.PathFollowing.FromObjectComponent(objectComponent);
|
||||||
objectComponent.id,
|
|
||||||
objectComponent.name,
|
|
||||||
objectComponent.spline,
|
|
||||||
objectComponent.mesh,
|
|
||||||
objectComponent.raytraceMesh,
|
|
||||||
objectComponent.accelleration,
|
|
||||||
objectComponent.maxSpeed,
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.baseOffset.x,
|
|
||||||
objectComponent.baseOffset.y,
|
|
||||||
objectComponent.baseOffset.z
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.maxOffset.x,
|
|
||||||
objectComponent.maxOffset.y,
|
|
||||||
objectComponent.maxOffset.z
|
|
||||||
),
|
|
||||||
objectComponent.steeringSpeed,
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.targetOffset.x,
|
|
||||||
objectComponent.targetOffset.y,
|
|
||||||
objectComponent.targetOffset.z
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.currentOffset.x,
|
|
||||||
objectComponent.currentOffset.y,
|
|
||||||
objectComponent.currentOffset.z
|
|
||||||
),
|
|
||||||
this.currentPathValue,
|
|
||||||
this.currentSpeed,
|
|
||||||
this.direction,
|
|
||||||
new GameLib.D3.API.Raycaster(
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.raycaster.position.x,
|
|
||||||
objectComponent.raycaster.position.y,
|
|
||||||
objectComponent.raycaster.position.z
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.raycaster.direction.x,
|
|
||||||
objectComponent.raycaster.direction.y,
|
|
||||||
objectComponent.raycaster.direction.z
|
|
||||||
)
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.currentPosition.x,
|
|
||||||
objectComponent.currentPosition.y,
|
|
||||||
objectComponent.currentPosition.z
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.futurePosition.x,
|
|
||||||
objectComponent.futurePosition.y,
|
|
||||||
objectComponent.futurePosition.z
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
objectComponent.up.x,
|
|
||||||
objectComponent.up.y,
|
|
||||||
objectComponent.up.z
|
|
||||||
),
|
|
||||||
//TODO : objectComponent rotationVector matrix4
|
|
||||||
new GameLib.API.Matrix4(
|
|
||||||
new GameLib.API.Quaternion(),
|
|
||||||
new GameLib.API.Quaternion(),
|
|
||||||
new GameLib.API.Quaternion(),
|
|
||||||
new GameLib.API.Quaternion()
|
|
||||||
),
|
|
||||||
new GameLib.API.Quaternion(
|
|
||||||
objectComponent.rotationVector.x,
|
|
||||||
objectComponent.rotationVector.y,
|
|
||||||
objectComponent.rotationVector.z,
|
|
||||||
objectComponent.rotationVector.w
|
|
||||||
),
|
|
||||||
objectComponent.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.PathFollowing(
|
return new GameLib.D3.PathFollowing(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
|
||||||
apiPathFollowing
|
apiPathFollowing
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,18 +7,12 @@
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Raycaster = function(
|
GameLib.D3.Raycaster = function(
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiRaycaster
|
apiRaycaster
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
|
||||||
parentObject = null;
|
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.D3.API.Raycaster.call(
|
GameLib.D3.API.Raycaster.call(
|
||||||
this,
|
this,
|
||||||
apiRaycaster.position,
|
apiRaycaster.position,
|
||||||
|
@ -72,6 +66,19 @@ GameLib.D3.Raycaster.prototype.toApiRaycaster = function() {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Raycaster.FromObjectRaycaster = function(graphics, parentObject, objectRaycaster) {
|
||||||
|
|
||||||
|
var apiRaycaster = GameLib.D3.API.Raycaster.FromObjectRaycaster(objectRaycaster);
|
||||||
|
|
||||||
|
var raycaster = new GameLib.D3.Raycaster(
|
||||||
|
graphics,
|
||||||
|
parentObject,
|
||||||
|
apiRaycaster
|
||||||
|
);
|
||||||
|
|
||||||
|
return raycaster;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the direction and position of this raycaster
|
* Sets the direction and position of this raycaster
|
||||||
* @param position GameLib.Vector3
|
* @param position GameLib.Vector3
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
/**
|
|
||||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
|
||||||
* @param parentObject
|
|
||||||
* @param apiRenderable GameLib.D3.API.Renderable
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.Renderable = function RuntimeRenderable(
|
|
||||||
graphics,
|
|
||||||
parentObject,
|
|
||||||
apiRenderable
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
|
||||||
parentObject = null;
|
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.D3.API.Renderable.call(
|
|
||||||
this,
|
|
||||||
apiRenderable.id,
|
|
||||||
apiRenderable.name,
|
|
||||||
apiRenderable.visible
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Renderable.prototype = Object.create(GameLib.D3.API.Renderable.prototype);
|
|
||||||
GameLib.D3.Renderable.prototype.constructor = GameLib.D3.Renderable;
|
|
||||||
|
|
||||||
GameLib.D3.Renderable.prototype.toApiComponent = function() {
|
|
||||||
|
|
||||||
var apiRenderable = new GameLib.D3.API.Renderable(
|
|
||||||
this.id,
|
|
||||||
this.name,
|
|
||||||
this.visible
|
|
||||||
);
|
|
||||||
|
|
||||||
return apiRenderable;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Renderable.FromObjectComponent = function(graphics, objectComponent) {
|
|
||||||
|
|
||||||
var apiRenderable = new GameLib.D3.API.Renderable(
|
|
||||||
objectComponent.id,
|
|
||||||
objectComponent.name,
|
|
||||||
objectComponent.visible
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.Renderable(
|
|
||||||
graphics,
|
|
||||||
this,
|
|
||||||
apiRenderable
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -1,24 +1,17 @@
|
||||||
/**
|
/**
|
||||||
* Renders a scene with a camera
|
* Renders a scene with a camera
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject
|
|
||||||
* @param apiRenderer GameLib.D3.API.Renderer
|
* @param apiRenderer GameLib.D3.API.Renderer
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Renderer = function RuntimeRenderer(
|
GameLib.D3.Renderer = function (
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiRenderer
|
apiRenderer
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
|
||||||
parentObject = null;
|
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.D3.API.Renderer.call(
|
GameLib.D3.API.Renderer.call(
|
||||||
this,
|
this,
|
||||||
apiRenderer.id,
|
apiRenderer.id,
|
||||||
|
@ -85,17 +78,7 @@ GameLib.D3.Renderer.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
|
GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
var apiRenderer = new GameLib.D3.API.Renderer(
|
var apiRenderer = GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
||||||
objectComponent.id,
|
|
||||||
objectComponent.name,
|
|
||||||
objectComponent.scene,
|
|
||||||
objectComponent.camera,
|
|
||||||
objectComponent.autoClear,
|
|
||||||
objectComponent.localClipping,
|
|
||||||
objectComponent.width,
|
|
||||||
objectComponent.height,
|
|
||||||
objectComponent.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.Renderer(
|
return new GameLib.D3.Renderer(
|
||||||
graphics,
|
graphics,
|
||||||
|
@ -104,6 +87,6 @@ GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Renderer.prototype.render = function(deltaTime) {
|
GameLib.D3.Renderer.prototype.render = function() {
|
||||||
this.instance.render(this.scene.instance, this.camera.instance);
|
this.instance.render(this.scene.instance, this.camera.instance);
|
||||||
};
|
};
|
|
@ -18,6 +18,8 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
this.imageFactory = imageFactory;
|
||||||
|
|
||||||
GameLib.D3.API.Scene.call(
|
GameLib.D3.API.Scene.call(
|
||||||
this,
|
this,
|
||||||
apiScene.id,
|
apiScene.id,
|
||||||
|
@ -33,7 +35,8 @@ GameLib.D3.Scene = function Scene(
|
||||||
apiScene.entityManager,
|
apiScene.entityManager,
|
||||||
apiScene.shapes,
|
apiScene.shapes,
|
||||||
apiScene.cameras,
|
apiScene.cameras,
|
||||||
apiScene.activeCameraIndex
|
apiScene.activeCameraIndex,
|
||||||
|
apiScene.textures
|
||||||
);
|
);
|
||||||
|
|
||||||
this.meshes = this.meshes.map(
|
this.meshes = this.meshes.map(
|
||||||
|
@ -56,10 +59,12 @@ GameLib.D3.Scene = function Scene(
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.entityManager = new GameLib.EntityManager(
|
if (this.entityManager) {
|
||||||
this,
|
this.entityManager = new GameLib.EntityManager(
|
||||||
this.entityManager
|
this.graphics,
|
||||||
);
|
this.entityManager
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.cameras = this.cameras.map(
|
this.cameras = this.cameras.map(
|
||||||
function(apiCamera) {
|
function(apiCamera) {
|
||||||
|
@ -70,6 +75,18 @@ GameLib.D3.Scene = function Scene(
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.textures = this.textures.map(
|
||||||
|
function(apiTexture) {
|
||||||
|
return new GameLib.D3.Texture(
|
||||||
|
this.graphics,
|
||||||
|
apiTexture,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
this.imageFactory
|
||||||
|
)
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
|
@ -88,27 +105,23 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.scale
|
this.scale
|
||||||
);
|
);
|
||||||
|
|
||||||
this.entityManager = new GameLib.EntityManager(
|
|
||||||
this,
|
|
||||||
this.entityManager
|
|
||||||
);
|
|
||||||
|
|
||||||
this.progressCallback = progressCallback;
|
this.progressCallback = progressCallback;
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
this.imageFactory = imageFactory;
|
|
||||||
|
|
||||||
this.interestingProperties = [
|
this.interestingProperties = [
|
||||||
"cameras",
|
"cameras",
|
||||||
"meshes",
|
"meshes",
|
||||||
"lights"
|
"lights",
|
||||||
|
"textures"
|
||||||
];
|
];
|
||||||
|
|
||||||
this.idToObject = {};
|
this.idToObject = {};
|
||||||
|
|
||||||
this.idToObject[this.id] = this;
|
this.idToObject[this.id] = this;
|
||||||
|
|
||||||
|
var material = null;
|
||||||
|
|
||||||
for (var p = 0; p < this.interestingProperties.length; p++) {
|
for (var p = 0; p < this.interestingProperties.length; p++) {
|
||||||
property = this.interestingProperties[p];
|
property = this.interestingProperties[p];
|
||||||
if (this.hasOwnProperty(property)) {
|
if (this.hasOwnProperty(property)) {
|
||||||
|
@ -129,6 +142,17 @@ GameLib.D3.Scene = function Scene(
|
||||||
|
|
||||||
this.idToObject[this.meshes[m].skeleton.id] = this.meshes[m].skeleton;
|
this.idToObject[this.meshes[m].skeleton.id] = this.meshes[m].skeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.meshes[m].materials[0]) {
|
||||||
|
|
||||||
|
material = this.meshes[m].materials[0];
|
||||||
|
|
||||||
|
for (var property in material) {
|
||||||
|
if (material.hasOwnProperty(property) && material[property] instanceof GameLib.D3.Texture) {
|
||||||
|
this.idToObject[material[property].id] = material[property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entityManager.entities.map(
|
this.entityManager.entities.map(
|
||||||
|
@ -220,6 +244,12 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
var apiTextures = this.textures.map(
|
||||||
|
function(texture) {
|
||||||
|
return texture.toApiTexture();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return new GameLib.D3.API.Scene(
|
return new GameLib.D3.API.Scene(
|
||||||
this.id,
|
this.id,
|
||||||
this.path,
|
this.path,
|
||||||
|
@ -234,7 +264,8 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
|
||||||
apiEntityManager,
|
apiEntityManager,
|
||||||
apiShapes,
|
apiShapes,
|
||||||
apiCameras,
|
apiCameras,
|
||||||
this.activeCameraIndex
|
this.activeCameraIndex,
|
||||||
|
apiTextures
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -261,7 +292,8 @@ GameLib.D3.Scene.FromObjectScene = function(
|
||||||
graphics,
|
graphics,
|
||||||
progressCallback,
|
progressCallback,
|
||||||
apiScene,
|
apiScene,
|
||||||
imageFactory
|
imageFactory,
|
||||||
|
computeNormals
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,37 @@ GameLib.D3.Skeleton = function Skeleton(
|
||||||
apiSkeleton.boneMatrices,
|
apiSkeleton.boneMatrices,
|
||||||
apiSkeleton.boneTexture
|
apiSkeleton.boneTexture
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.bones = this.bones.map(
|
||||||
|
function(apiBone) {
|
||||||
|
return new GameLib.D3.Bone(
|
||||||
|
this.graphics,
|
||||||
|
apiBone
|
||||||
|
)
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.boneInverses = this.boneInverses.map(
|
||||||
|
function(boneInverse) {
|
||||||
|
return new GameLib.Matrix4(
|
||||||
|
this.graphics,
|
||||||
|
this,
|
||||||
|
boneInverse
|
||||||
|
);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
this.boneMatrices = this.boneMatrices.map(
|
||||||
|
function(boneMatrices) {
|
||||||
|
return new GameLib.Matrix4(
|
||||||
|
this.graphics,
|
||||||
|
this,
|
||||||
|
boneMatrices
|
||||||
|
);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @param apiSpline GameLib.D3.API.Spline
|
* @param apiSpline GameLib.D3.API.Spline
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Spline = function RuntimeSpline(
|
GameLib.D3.Spline = function (
|
||||||
graphics,
|
graphics,
|
||||||
apiSpline
|
apiSpline
|
||||||
) {
|
) {
|
||||||
|
@ -61,21 +61,6 @@ GameLib.D3.Spline.prototype.updateInstance = function() {
|
||||||
this.instance = this.createInstance(true);
|
this.instance = this.createInstance(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the current point from the spline at the proper value
|
|
||||||
* @param proper Number (fraction between 0 and 1 indicating position on spline)
|
|
||||||
* @returns {*}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Spline.prototype.getPointAt = function(proper) {
|
|
||||||
var point = this.instance.getPointAt(proper);
|
|
||||||
return new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
this,
|
|
||||||
new GameLib.API.Vector3(point.x, point.y, point.z),
|
|
||||||
0.1
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a GameLib.D3.Spline to GameLib.D3.API.Spline
|
* Converts a GameLib.D3.Spline to GameLib.D3.API.Spline
|
||||||
* @returns {GameLib.D3.API.Spline}
|
* @returns {GameLib.D3.API.Spline}
|
||||||
|
@ -106,23 +91,25 @@ GameLib.D3.Spline.FromObjectComponent = function(
|
||||||
graphics,
|
graphics,
|
||||||
objectComponent
|
objectComponent
|
||||||
) {
|
) {
|
||||||
var apiSpline = new GameLib.D3.API.Spline(
|
var apiSpline = GameLib.D3.API.Spline.FromObjectComponent(objectComponent);
|
||||||
objectComponent.id,
|
|
||||||
objectComponent.name,
|
|
||||||
objectComponent.vertices.map(
|
|
||||||
function (objectVertex) {
|
|
||||||
return new GameLib.API.Vector3(
|
|
||||||
objectVertex.x,
|
|
||||||
objectVertex.y,
|
|
||||||
objectVertex.z
|
|
||||||
)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
objectComponent.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.Spline(
|
return new GameLib.D3.Spline(
|
||||||
graphics,
|
graphics,
|
||||||
apiSpline
|
apiSpline
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current point from the spline at the proper value
|
||||||
|
* @param proper Number (fraction between 0 and 1 indicating position on spline)
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Spline.prototype.getPointAt = function(proper) {
|
||||||
|
var point = this.instance.getPointAt(proper);
|
||||||
|
return new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this,
|
||||||
|
new GameLib.API.Vector3(point.x, point.y, point.z),
|
||||||
|
0.1
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@ GameLib.D3.Texture = function Texture(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
GameLib.API.Texture.call(
|
GameLib.D3.API.Texture.call(
|
||||||
this,
|
this,
|
||||||
apiTexture.id,
|
apiTexture.id,
|
||||||
apiTexture.typeId,
|
apiTexture.typeId,
|
||||||
|
@ -177,29 +177,31 @@ GameLib.D3.Texture.TEXTURE_TYPE_SPECULAR = 'specular';
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.createInstance = function(update) {
|
GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
// var instance = null;
|
||||||
|
//
|
||||||
|
// if (update) {
|
||||||
|
// instance = this.instance;
|
||||||
|
// instance.mapping = this.mapping;
|
||||||
|
// instance.wrapS = this.wrapS;
|
||||||
|
// instance.wrapT = this.wrapT;
|
||||||
|
// instance.magFilter = this.magFilter;
|
||||||
|
// instance.minFilter = this.minFilter;
|
||||||
|
// instance.anisotropy = this.anisotropy;
|
||||||
|
// } else {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
if (update) {
|
var instance = new THREE.Texture(
|
||||||
instance = this.instance;
|
this.imageInstance,
|
||||||
instance.mapping = this.mapping;
|
this.mapping,
|
||||||
instance.wrapS = this.wrapS;
|
this.wrapS,
|
||||||
instance.wrapT = this.wrapT;
|
this.wrapT,
|
||||||
instance.magFilter = this.magFilter;
|
this.magFilter,
|
||||||
instance.minFilter = this.minFilter;
|
this.minFilter,
|
||||||
instance.anisotropy = this.anisotropy;
|
undefined, //format and textureType is different on different archs
|
||||||
} else {
|
undefined,
|
||||||
instance = new this.graphics.instance.Texture(
|
this.anisotropy
|
||||||
this.imageInstance,
|
);
|
||||||
this.mapping,
|
|
||||||
this.wrapS,
|
|
||||||
this.wrapT,
|
|
||||||
this.magFilter,
|
|
||||||
this.minFilter,
|
|
||||||
undefined, //format and textureType is different on different archs
|
|
||||||
undefined,
|
|
||||||
this.anisotropy
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.name = this.name;
|
instance.name = this.name;
|
||||||
instance.flipY = this.flipY;
|
instance.flipY = this.flipY;
|
||||||
|
@ -212,6 +214,13 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
instance.unpackAlignment = this.unpackAlignment;
|
instance.unpackAlignment = this.unpackAlignment;
|
||||||
instance.premultiplyAlpha = this.premultiplyAlpha;
|
instance.premultiplyAlpha = this.premultiplyAlpha;
|
||||||
instance.textureType = this.textureType;
|
instance.textureType = this.textureType;
|
||||||
|
|
||||||
|
if (this.parentMaterial &&
|
||||||
|
this.parentMaterial.instance &&
|
||||||
|
this.parentMaterialInstanceMapId) {
|
||||||
|
this.parentMaterial.instance[this.parentMaterialInstanceMapId] = instance;
|
||||||
|
}
|
||||||
|
|
||||||
instance.needsUpdate = true;
|
instance.needsUpdate = true;
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
|
|
@ -34,15 +34,15 @@ GameLib.D3.TriangleFace = function TriangleFace(
|
||||||
this.v1uv = v1uv;
|
this.v1uv = v1uv;
|
||||||
this.v2uv = v2uv;
|
this.v2uv = v2uv;
|
||||||
if (!color) {
|
if (!color) {
|
||||||
color = new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff);
|
color = new GameLib.API.Color(0xff, 0xff, 0xff, 0xff);
|
||||||
}
|
}
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
||||||
if (!vertexColors) {
|
if (!vertexColors) {
|
||||||
vertexColors = [
|
vertexColors = [
|
||||||
new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff),
|
new GameLib.API.Color(0xff, 0xff, 0xff, 0xff),
|
||||||
new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff),
|
new GameLib.API.Color(0xff, 0xff, 0xff, 0xff),
|
||||||
new GameLib.D3.API.Color(0xff, 0xff, 0xff, 0xff)
|
new GameLib.API.Color(0xff, 0xff, 0xff, 0xff)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
this.vertexColors = vertexColors;
|
this.vertexColors = vertexColors;
|
||||||
|
|
|
@ -23,42 +23,19 @@ GameLib.D3.Vertex = function Vertex(
|
||||||
this.position
|
this.position
|
||||||
);
|
);
|
||||||
|
|
||||||
//TODO: GameLib.D3.BoneWeight implementation
|
this.boneWeights = this.boneWeights.map(
|
||||||
|
function(apiBoneWeight) {
|
||||||
this.instance = this.createInstance();
|
return new GameLib.D3.BoneWeight(
|
||||||
|
this.graphics,
|
||||||
|
apiBoneWeight
|
||||||
|
)
|
||||||
|
}.bind(this)
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Vertex.prototype = Object.create(GameLib.D3.API.Vertex.prototype);
|
GameLib.D3.Vertex.prototype = Object.create(GameLib.D3.API.Vertex.prototype);
|
||||||
GameLib.D3.Vertex.prototype.constructor = GameLib.D3.Vertex;
|
GameLib.D3.Vertex.prototype.constructor = GameLib.D3.Vertex;
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance vertex
|
|
||||||
* @param update boolean
|
|
||||||
*/
|
|
||||||
GameLib.D3.Vertex.prototype.createInstance = function(update) {
|
|
||||||
|
|
||||||
var instance = null;
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
instance = this.instance;
|
|
||||||
} else {
|
|
||||||
instance = new THREE.Vector3();
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.x = this.position.x;
|
|
||||||
instance.y = this.position.y;
|
|
||||||
instance.z = this.position.z;
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the instance
|
|
||||||
*/
|
|
||||||
GameLib.D3.Vertex.prototype.updateInstance = function() {
|
|
||||||
this.instance = this.createInstance(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a GameLib.D3.Vertex to GameLib.D3.API.Vertex
|
* Converts a GameLib.D3.Vertex to GameLib.D3.API.Vertex
|
||||||
* @returns {GameLib.D3.API.Vertex}
|
* @returns {GameLib.D3.API.Vertex}
|
||||||
|
@ -67,7 +44,9 @@ GameLib.D3.Vertex.prototype.toApiVertex = function() {
|
||||||
|
|
||||||
return new GameLib.D3.API.Vertex(
|
return new GameLib.D3.API.Vertex(
|
||||||
this.position.toApiVector(),
|
this.position.toApiVector(),
|
||||||
this.boneWeights
|
this.boneWeights.map(function(boneWeight){
|
||||||
|
return boneWeight.toApiBoneWeight();
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
/**
|
/**
|
||||||
* GameLib.EntityManager
|
* GameLib.EntityManager
|
||||||
* @param parentObject
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiEntityManager GameLib.API.EntityManager
|
* @param apiEntityManager GameLib.API.EntityManager
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager = function(
|
GameLib.EntityManager = function(
|
||||||
parentObject,
|
graphics,
|
||||||
apiEntityManager
|
apiEntityManager
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
this.graphics = graphics;
|
||||||
parentObject = null;
|
this.graphics.isNotThreeThrow();
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.API.EntityManager.call(
|
GameLib.API.EntityManager.call(
|
||||||
this,
|
this,
|
||||||
|
@ -22,11 +20,10 @@ GameLib.EntityManager = function(
|
||||||
this.entities = this.entities.map(
|
this.entities = this.entities.map(
|
||||||
function(apiEntity) {
|
function(apiEntity) {
|
||||||
return new GameLib.Entity(
|
return new GameLib.Entity(
|
||||||
this,
|
this.graphics,
|
||||||
this,
|
|
||||||
apiEntity
|
apiEntity
|
||||||
)
|
)
|
||||||
}
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
@ -54,7 +51,7 @@ GameLib.EntityManager.prototype.createEntity = function(name) {
|
||||||
|
|
||||||
var apiEntity = new GameLib.API.Entity(null, name);
|
var apiEntity = new GameLib.API.Entity(null, name);
|
||||||
|
|
||||||
var entity = new GameLib.Entity(this, this, apiEntity);
|
var entity = new GameLib.Entity(this.graphics, apiEntity);
|
||||||
|
|
||||||
this.entities.push(entity);
|
this.entities.push(entity);
|
||||||
|
|
||||||
|
@ -167,25 +164,17 @@ GameLib.EntityManager.prototype.toApiEntityManager = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns an EntityManager from an Object entity manager
|
||||||
* @param graphics
|
* @param graphics
|
||||||
* @param objectEntities Object
|
* @param objectEntityManager Object
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntities) {
|
GameLib.EntityManager.FromObjectEntityManager = function(graphics, objectEntityManager) {
|
||||||
|
|
||||||
var apiEntities = objectEntities.entities.map(
|
var apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectEntityManager);
|
||||||
function (objectEntity) {
|
|
||||||
return GameLib.API.Entity.FromObjectEntity(objectEntity);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var apiEntityManager = new GameLib.API.EntityManager(
|
|
||||||
apiEntities
|
|
||||||
);
|
|
||||||
|
|
||||||
var entityManager = new GameLib.EntityManager(
|
var entityManager = new GameLib.EntityManager(
|
||||||
this,
|
graphics,
|
||||||
apiEntityManager
|
apiEntityManager
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,16 @@
|
||||||
/**
|
/**
|
||||||
* Entity Runtime
|
* Runtime Entity
|
||||||
* @constructor
|
* @param graphics GameLib.D3.Graphics
|
||||||
*/
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param entityManager GameLib.D3.EntityManager
|
|
||||||
* @param parentObject
|
|
||||||
* @param apiEntity GameLib.D3.API.Entity
|
* @param apiEntity GameLib.D3.API.Entity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Entity = function RuntimeEntity(
|
GameLib.Entity = function (
|
||||||
entityManager,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiEntity
|
apiEntity
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
|
|
||||||
throw new Error('You cannot create entities without an entity manager')
|
|
||||||
}
|
|
||||||
this.entityManager = entityManager;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
this.graphics = graphics;
|
||||||
parentObject = null;
|
this.graphics.isNotThreeThrow();
|
||||||
}
|
|
||||||
this.parentObject = parentObject;
|
|
||||||
|
|
||||||
GameLib.API.Entity.call(
|
GameLib.API.Entity.call(
|
||||||
this,
|
this,
|
||||||
|
@ -32,36 +20,35 @@ GameLib.Entity = function RuntimeEntity(
|
||||||
);
|
);
|
||||||
|
|
||||||
this.components = this.components.map(
|
this.components = this.components.map(
|
||||||
function (component) {
|
|
||||||
if (component instanceof Object) {
|
|
||||||
|
|
||||||
component.constructor.FromObjectComponent(entityManager.graphics, component);
|
function (apiComponent) {
|
||||||
//
|
|
||||||
// if (component.componentType === GameLib.Component.COMPONENT_TYPE_PATH_FOLLOWING) {
|
if (apiComponent instanceof GameLib.D3.API.PathFollowing) {
|
||||||
// return GameLib.D3.PathFollowing.FromObjectComponent(entityManager.graphics, component);
|
return new GameLib.D3.PathFollowing(this.graphics, apiComponent);
|
||||||
// } 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (apiComponent instanceof GameLib.D3.API.Renderer) {
|
||||||
|
return new GameLib.D3.Renderer(this.graphics, apiComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiComponent instanceof GameLib.D3.API.LookAt) {
|
||||||
|
return new GameLib.D3.LookAt(this.graphics, apiComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiComponent instanceof GameLib.D3.API.Follow) {
|
||||||
|
return new GameLib.D3.Follow(this.graphics, apiComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiComponent instanceof GameLib.D3.API.Input.Drive) {
|
||||||
|
return new GameLib.D3.Input.Drive(this.graphics, apiComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiComponent instanceof GameLib.D3.API.Spline) {
|
||||||
|
return new GameLib.D3.Spline(this.graphics, apiComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiComponent;
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -138,17 +125,16 @@ GameLib.Entity.prototype.toApiEntity = function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param entityManager GameLib.EntityManager
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param objectEntity Object
|
* @param objectEntity Object
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Entity.FromObjectEntity = function(entityManager, objectEntity) {
|
GameLib.Entity.FromObjectEntity = function(graphics, objectEntity) {
|
||||||
|
|
||||||
var apiEntity = GameLib.API.Entity.FromObjectEntity(objectEntity);
|
var apiEntity = GameLib.API.Entity.FromObjectEntity(objectEntity);
|
||||||
|
|
||||||
return new GameLib.Entity(
|
return new GameLib.Entity(
|
||||||
entityManager,
|
graphics,
|
||||||
this,
|
|
||||||
apiEntity
|
apiEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Quaternion = function RuntimeQuaternion(
|
GameLib.Quaternion = function (
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
parentObject,
|
||||||
apiQuaternion,
|
apiQuaternion,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Vector2 = function RuntimeVector2(graphics, parentObject, apiVector2, grain) {
|
GameLib.Vector2 = function (graphics, parentObject, apiVector2, grain) {
|
||||||
|
|
||||||
for (var property in apiVector2) {
|
for (var property in apiVector2) {
|
||||||
if (apiVector2.hasOwnProperty(property)) {
|
if (apiVector2.hasOwnProperty(property)) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Vector3 = function RuntimeVector3(graphics, parentObject, apiVector3, grain) {
|
GameLib.Vector3 = function (graphics, parentObject, apiVector3, grain) {
|
||||||
|
|
||||||
for (var property in apiVector3) {
|
for (var property in apiVector3) {
|
||||||
if (apiVector3.hasOwnProperty(property)) {
|
if (apiVector3.hasOwnProperty(property)) {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Vector4 = function RuntimeVector4(graphics, parentObject, apiVector4, grain) {
|
GameLib.Vector4 = function (graphics, parentObject, apiVector4, grain) {
|
||||||
|
|
||||||
GameLib.API.Vector4.call(
|
GameLib.API.Vector4.call(
|
||||||
this,
|
this,
|
||||||
|
|
Loading…
Reference in New Issue