cameras and meshes are now 3d objects
parent
6819ba95c0
commit
c1334bbb00
|
@ -262,7 +262,7 @@ GameLib.Component.STATS = 0x1d;
|
|||
GameLib.Component.GUI = 0x1e;
|
||||
GameLib.Component.IMAGE = 0x1f;
|
||||
GameLib.Component.ENTITY = 0x20;
|
||||
//GameLib.Component.MESH_SPHERE = 0x21;
|
||||
GameLib.Component.OBJECT = 0x21;
|
||||
//GameLib.Component.MESH_PLANE = 0x22;
|
||||
//GameLib.Component.MESH_CURVE = 0x23;
|
||||
GameLib.Component.PHYSICS_WORLD = 0x24;
|
||||
|
@ -613,12 +613,12 @@ GameLib.Component.GetComponentInfo = function(number) {
|
|||
constructor : GameLib.Entity,
|
||||
apiConstructor : GameLib.API.Entity
|
||||
};
|
||||
case 0x21 : return null;/*return {
|
||||
name : 'GameLib.D3.Mesh.Sphere',
|
||||
case 0x21 : return {
|
||||
name : 'GameLib.D3.Object',
|
||||
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||
constructor : GameLib.D3.Mesh.Sphere,
|
||||
apiConstructor : GameLib.D3.API.Mesh
|
||||
};*/
|
||||
constructor : GameLib.D3.Object,
|
||||
apiConstructor : GameLib.D3.API.Object
|
||||
};
|
||||
case 0x22 : return null;/*{
|
||||
name : 'GameLib.D3.Mesh.Plane',
|
||||
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||
|
@ -1504,6 +1504,27 @@ GameLib.Component.prototype.toApiObject = function() {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets all children components of this Object (all linked objects only - no object references i.e. string ids)
|
||||
* @returns {Array}
|
||||
*/
|
||||
GameLib.Component.prototype.getChildrenComponents = function() {
|
||||
|
||||
var components = [];
|
||||
|
||||
this.buildIdToObject();
|
||||
|
||||
Object.keys(this.idToObject).map(
|
||||
function (objectId) {
|
||||
if (this.id !== objectId) {
|
||||
components.push(this.idToObject[objectId]);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
return components;
|
||||
};
|
||||
|
||||
GameLib.Component.prototype.processComponent = function(object) {
|
||||
if (object instanceof GameLib.Component) {
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ GameLib.Canvas.prototype.updateInstance = function(property) {
|
|||
|
||||
if (property === 'id') {
|
||||
this.instance.setAttribute('id', this.id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'autoUpdateSize' ||
|
||||
|
@ -107,11 +108,15 @@ GameLib.Canvas.prototype.updateInstance = function(property) {
|
|||
this.instance.width = this.width;
|
||||
this.instance.height = this.height;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'texts') {
|
||||
this.writeText();
|
||||
return;
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
/**
|
||||
* GameLib.D3.API.Object
|
||||
* @param id
|
||||
* @param name
|
||||
* @param objectType
|
||||
* @param parentEntity
|
||||
* @param useQuaternion
|
||||
* @param position
|
||||
* @param quaternion
|
||||
* @param rotation
|
||||
* @param scale
|
||||
* @param up
|
||||
* @param lookAt
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Object = function(
|
||||
id,
|
||||
name,
|
||||
objectType,
|
||||
parentEntity,
|
||||
useQuaternion,
|
||||
position,
|
||||
quaternion,
|
||||
rotation,
|
||||
scale,
|
||||
up,
|
||||
lookAt
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(objectType)) {
|
||||
objectType = 0;
|
||||
}
|
||||
this.objectType = objectType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
switch (this.objectType) {
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_NONE :
|
||||
name = 'Object';
|
||||
break;
|
||||
/**
|
||||
* Cameras
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA :
|
||||
name = 'Camera';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC :
|
||||
name = 'Camera Orthographic';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE :
|
||||
name = 'Camera Perspective';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE :
|
||||
name = 'Camera Cube';
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO :
|
||||
name = 'Camera Stereo';
|
||||
break;
|
||||
/**
|
||||
* Meshes
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_MESH :
|
||||
name = 'Mesh';
|
||||
break;
|
||||
}
|
||||
name += ' (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(useQuaternion)) {
|
||||
useQuaternion = true;
|
||||
}
|
||||
this.useQuaternion = useQuaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3();
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotation)) {
|
||||
rotation = new GameLib.API.Vector3();
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
|
||||
lookAt = new GameLib.API.Vector3();
|
||||
}
|
||||
this.lookAt = lookAt;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
this,
|
||||
GameLib.D3.API.Object.GetComponentType(this.objectType),
|
||||
parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Object.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Object.prototype.constructor = GameLib.D3.API.Object;
|
||||
|
||||
GameLib.D3.API.Object.GetComponentType = function(objectType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (objectType) {
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_NONE :
|
||||
componentType = GameLib.Component.OBJECT;
|
||||
break;
|
||||
/**
|
||||
* Cameras
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA :
|
||||
componentType = GameLib.Component.CAMERA;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE :
|
||||
componentType = GameLib.Component.CAMERA_PERSPECTIVE;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC :
|
||||
componentType = GameLib.Component.CAMERA_ORTHOGRAPHIC;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO :
|
||||
componentType = GameLib.Component.CAMERA_STEREO;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE :
|
||||
componentType = GameLib.Component.CAMERA_CUBE;
|
||||
break;
|
||||
/**
|
||||
* Meshes
|
||||
*/
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_MESH :
|
||||
componentType = GameLib.Component.MESH;
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported camera type: ' + objectType);
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_NONE = 0x0;
|
||||
|
||||
/**
|
||||
* Cameras
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA = 0x11;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE = 0x12;//0x1;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC = 0x13;//0x2;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO = 0x14;//0x3;
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE = 0x15;//0x4;
|
||||
|
||||
/**
|
||||
* Meshes
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.D3.API.Object.OBJECT_TYPE_MESH = 0x21;
|
|
@ -1,133 +1,52 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera
|
||||
* @param id
|
||||
* @param name
|
||||
* @param cameraType GameLib.D3.API.Camera.CAMERA_TYPE_*
|
||||
* @param apiD3Object
|
||||
* @param aspect
|
||||
* @param position GameLib.API.Vector3
|
||||
* @param rotation
|
||||
* @param quaternion
|
||||
* @param lookAt GameLib.API.Vector3
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Camera = function(
|
||||
id,
|
||||
name,
|
||||
cameraType,
|
||||
aspect,
|
||||
position,
|
||||
rotation,
|
||||
quaternion,
|
||||
lookAt,
|
||||
parentEntity
|
||||
apiD3Object,
|
||||
aspect
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object)) {
|
||||
apiD3Object = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA
|
||||
};
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(cameraType)) {
|
||||
throw new Error('No camera type specified - do not call this constructor directly');
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object.objectType)) {
|
||||
apiD3Object.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA;
|
||||
}
|
||||
this.cameraType = cameraType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
|
||||
switch (this.cameraType) {
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC :
|
||||
name = 'Camera Orthographic';
|
||||
break;
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE :
|
||||
name = 'Camera Perspective';
|
||||
break;
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_CUBE :
|
||||
name = 'Camera Cube';
|
||||
break;
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_STEREO :
|
||||
name = 'Camera Stereo';
|
||||
break;
|
||||
default :
|
||||
console.warn('no nice name for camera');
|
||||
name = 'Camera';
|
||||
}
|
||||
|
||||
name += ' (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(aspect)) {
|
||||
aspect = 1;
|
||||
}
|
||||
this.aspect = aspect;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3(
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object.position)) {
|
||||
apiD3Object.position = new GameLib.API.Vector3(
|
||||
15,
|
||||
15,
|
||||
15
|
||||
);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(lookAt)) {
|
||||
lookAt = new GameLib.API.Vector3(
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
this.lookAt = lookAt;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotation)) {
|
||||
rotation = new GameLib.API.Vector3();
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
GameLib.D3.API.Object.call(
|
||||
this,
|
||||
GameLib.D3.API.Camera.GetComponentType(this.cameraType),
|
||||
parentEntity
|
||||
apiD3Object.id,
|
||||
apiD3Object.name,
|
||||
apiD3Object.objectType,
|
||||
apiD3Object.parentEntity,
|
||||
apiD3Object.useQuaternion,
|
||||
apiD3Object.position,
|
||||
apiD3Object.quaternion,
|
||||
apiD3Object.rotation,
|
||||
apiD3Object.scale,
|
||||
apiD3Object.up,
|
||||
apiD3Object.lookAt
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Camera.prototype = Object.create(GameLib.D3.API.Object.prototype);
|
||||
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
|
||||
|
||||
GameLib.D3.API.Camera.GetComponentType = function(cameraType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (cameraType) {
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE :
|
||||
componentType = GameLib.Component.CAMERA_PERSPECTIVE;
|
||||
break;
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC :
|
||||
componentType = GameLib.Component.CAMERA_ORTHOGRAPHIC;
|
||||
break;
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_STEREO :
|
||||
componentType = GameLib.Component.CAMERA_STEREO;
|
||||
break;
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_CUBE :
|
||||
componentType = GameLib.Component.CAMERA_CUBE;
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported camera type: ' + cameraType);
|
||||
}
|
||||
|
||||
return componentType;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE = 0x1;
|
||||
GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC = 0x2;
|
||||
GameLib.D3.API.Camera.CAMERA_TYPE_STEREO = 0x3;
|
||||
GameLib.D3.API.Camera.CAMERA_TYPE_CUBE = 0x4;
|
||||
|
||||
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera.Cube
|
||||
* @constructor
|
||||
* @param apiCamera
|
||||
* @param apiD3ObjectCamera
|
||||
* @param near
|
||||
* @param far
|
||||
* @param cubeResolution
|
||||
* @param renderTarget
|
||||
*/
|
||||
GameLib.D3.API.Camera.Cube = function(
|
||||
apiCamera,
|
||||
apiD3ObjectCamera,
|
||||
near,
|
||||
far,
|
||||
cubeResolution,
|
||||
renderTarget
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
|
||||
apiCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_CUBE
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
|
||||
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_CUBE;
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
|
@ -50,17 +50,10 @@ GameLib.D3.API.Camera.Cube = function(
|
|||
*/
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiCamera.id,
|
||||
apiCamera.name,
|
||||
apiCamera.cameraType,
|
||||
1,
|
||||
apiCamera.position,
|
||||
apiCamera.rotation,
|
||||
apiCamera.quaternion,
|
||||
apiCamera.lookAt,
|
||||
apiCamera.parentEntity
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.API.Camera.Cube.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
||||
GameLib.D3.API.Camera.Cube.prototype.constructor = GameLib.D3.API.Camera.Cube;
|
||||
GameLib.D3.API.Camera.Cube.prototype.constructor = GameLib.D3.API.Camera.Cube;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Also - the offset is always respected
|
||||
*
|
||||
* @constructor
|
||||
* @param apiCamera
|
||||
* @param apiD3ObjectCamera
|
||||
* @param aspectRatioMode
|
||||
* @param minWidth
|
||||
* @param minHeight
|
||||
|
@ -31,7 +31,7 @@
|
|||
* @param zoom
|
||||
*/
|
||||
GameLib.D3.API.Camera.Orthographic = function(
|
||||
apiCamera,
|
||||
apiD3ObjectCamera,
|
||||
aspectRatioMode,
|
||||
minWidth,
|
||||
minHeight,
|
||||
|
@ -46,22 +46,22 @@ GameLib.D3.API.Camera.Orthographic = function(
|
|||
zoom
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
|
||||
apiCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
|
||||
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC;
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera.position)) {
|
||||
apiCamera.position = new GameLib.API.Vector3(0,0,10);
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.position)) {
|
||||
apiD3ObjectCamera.position = new GameLib.API.Vector3(0,0,10);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera.lookAt)) {
|
||||
apiCamera.lookAt = new GameLib.API.Vector3(0,0,-1);
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.lookAt)) {
|
||||
apiD3ObjectCamera.lookAt = new GameLib.API.Vector3(0,0,-10);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(aspectRatioMode)) {
|
||||
|
@ -131,15 +131,8 @@ GameLib.D3.API.Camera.Orthographic = function(
|
|||
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiCamera.id,
|
||||
apiCamera.name,
|
||||
apiCamera.cameraType,
|
||||
apiCamera.aspect,
|
||||
apiCamera.position,
|
||||
apiCamera.rotation,
|
||||
apiCamera.quaternion,
|
||||
apiCamera.lookAt,
|
||||
apiCamera.parentEntity
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera.Perspective
|
||||
* @constructor
|
||||
* @param apiCamera
|
||||
* @param apiD3ObjectCamera
|
||||
* @param fov
|
||||
* @param near
|
||||
* @param far
|
||||
|
@ -11,7 +11,7 @@
|
|||
* @param zoom
|
||||
*/
|
||||
GameLib.D3.API.Camera.Perspective = function(
|
||||
apiCamera,
|
||||
apiD3ObjectCamera,
|
||||
near,
|
||||
far,
|
||||
fov,
|
||||
|
@ -21,14 +21,14 @@ GameLib.D3.API.Camera.Perspective = function(
|
|||
zoom
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
|
||||
apiCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
|
||||
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE;
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(near)) {
|
||||
|
@ -75,15 +75,8 @@ GameLib.D3.API.Camera.Perspective = function(
|
|||
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiCamera.id,
|
||||
apiCamera.name,
|
||||
apiCamera.cameraType,
|
||||
apiCamera.aspect,
|
||||
apiCamera.position,
|
||||
apiCamera.rotation,
|
||||
apiCamera.quaternion,
|
||||
apiCamera.lookAt,
|
||||
apiCamera.parentEntity
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
/**
|
||||
* GameLib.D3.API.Camera.Stereo
|
||||
* @constructor
|
||||
* @param apiCamera
|
||||
* @param apiD3ObjectCamera
|
||||
* @param stereoMode
|
||||
*/
|
||||
GameLib.D3.API.Camera.Stereo = function(
|
||||
apiCamera,
|
||||
apiD3ObjectCamera,
|
||||
stereoMode
|
||||
) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
|
||||
apiCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_STEREO
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO
|
||||
};
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera.cameraType)) {
|
||||
apiCamera.cameraType = GameLib.D3.API.Camera.CAMERA_TYPE_STEREO;
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) {
|
||||
apiD3ObjectCamera.objectType = GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO;
|
||||
}
|
||||
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(stereoMode)) {
|
||||
stereoMode = GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO;
|
||||
}
|
||||
|
@ -26,15 +27,8 @@ GameLib.D3.API.Camera.Stereo = function(
|
|||
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiCamera.id,
|
||||
apiCamera.name,
|
||||
apiCamera.cameraType,
|
||||
apiCamera.aspect,
|
||||
apiCamera.position,
|
||||
apiCamera.rotation,
|
||||
apiCamera.quaternion,
|
||||
apiCamera.lookAt,
|
||||
apiCamera.parentEntity
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,22 +1,13 @@
|
|||
/**
|
||||
* GameLib.D3.API.Mesh
|
||||
* @param id
|
||||
* @param name
|
||||
* @param meshType
|
||||
* @param parentEntity
|
||||
* @param apiD3Object
|
||||
* @param geometry
|
||||
* @param materials
|
||||
* @param parentMesh
|
||||
* @param parentScene
|
||||
* @param excludeFromEnvironment
|
||||
* @param skeleton
|
||||
* @param position
|
||||
* @param quaternion
|
||||
* @param rotation
|
||||
* @param scale
|
||||
* @param up
|
||||
* @param renderOrder
|
||||
* @param useQuaternion
|
||||
* @param visible
|
||||
* @param castShadow
|
||||
* @param receiveShadow
|
||||
|
@ -26,23 +17,14 @@
|
|||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Mesh = function(
|
||||
id,
|
||||
name,
|
||||
meshType,
|
||||
parentEntity,
|
||||
apiD3Object,
|
||||
geometry,
|
||||
materials,
|
||||
parentMesh,
|
||||
parentScene,
|
||||
excludeFromEnvironment,
|
||||
skeleton,
|
||||
position,
|
||||
quaternion,
|
||||
rotation,
|
||||
scale,
|
||||
up,
|
||||
renderOrder,
|
||||
useQuaternion,
|
||||
visible,
|
||||
castShadow,
|
||||
receiveShadow,
|
||||
|
@ -50,54 +32,15 @@ GameLib.D3.API.Mesh = function(
|
|||
morphTargetInfluences,
|
||||
morphTargetDictionary
|
||||
) {
|
||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||
id = GameLib.Utils.RandomId();
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object)) {
|
||||
apiD3Object = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_MESH
|
||||
};
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(meshType)) {
|
||||
meshType = GameLib.D3.API.Mesh.MESH_TYPE_NORMAL;
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3Object.objectType)) {
|
||||
apiD3Object.objectType = GameLib.D3.API.Object.OBJECT_TYPE_MESH;
|
||||
}
|
||||
this.meshType = meshType;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||
|
||||
switch (this.meshType) {
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_NORMAL :
|
||||
name = 'Mesh';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_BOX :
|
||||
name = 'Mesh Box';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_TEXT :
|
||||
name = 'Mesh Text';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_CURVE :
|
||||
name = 'Mesh Curve';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_LINE :
|
||||
name = 'Mesh Line';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_SPHERE :
|
||||
name = 'Mesh Sphere';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER :
|
||||
name = 'Mesh Cylinder';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_PLANE :
|
||||
name = 'Mesh Plane';
|
||||
break;
|
||||
case GameLib.D3.API.Mesh.MESH_TYPE_SKINNED :
|
||||
name = 'Mesh Skinned';
|
||||
break;
|
||||
default :
|
||||
console.warn('no nice name for mesh');
|
||||
name = 'Mesh';
|
||||
}
|
||||
|
||||
name += ' (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(geometry)) {
|
||||
geometry = null;
|
||||
|
@ -131,41 +74,11 @@ GameLib.D3.API.Mesh = function(
|
|||
}
|
||||
this.skeleton = skeleton;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.API.Quaternion();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(rotation)) {
|
||||
rotation = new GameLib.API.Vector3(0,0,0);
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.API.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.API.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(renderOrder)) {
|
||||
renderOrder = 0;
|
||||
}
|
||||
this.renderOrder = renderOrder;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(useQuaternion)) {
|
||||
useQuaternion = true;
|
||||
}
|
||||
this.useQuaternion = useQuaternion;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(visible)) {
|
||||
visible = true;
|
||||
}
|
||||
|
@ -196,57 +109,27 @@ GameLib.D3.API.Mesh = function(
|
|||
}
|
||||
this.morphTargetDictionary = morphTargetDictionary;
|
||||
|
||||
var componentType = GameLib.Component.MESH;
|
||||
|
||||
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) {
|
||||
componentType = GameLib.Component.MESH_PLANE
|
||||
}
|
||||
|
||||
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_BOX) {
|
||||
componentType = GameLib.Component.MESH_BOX
|
||||
}
|
||||
|
||||
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER) {
|
||||
componentType = GameLib.Component.MESH_CYLINDER
|
||||
}
|
||||
|
||||
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_SPHERE) {
|
||||
componentType = GameLib.Component.MESH_SPHERE
|
||||
}
|
||||
|
||||
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_LINE) {
|
||||
componentType = GameLib.Component.MESH_LINE
|
||||
}
|
||||
|
||||
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) {
|
||||
componentType = GameLib.Component.MESH_TEXT;
|
||||
}
|
||||
|
||||
GameLib.API.Component.call(
|
||||
GameLib.D3.API.Object.call(
|
||||
this,
|
||||
componentType,
|
||||
parentEntity
|
||||
apiD3Object.id,
|
||||
apiD3Object.name,
|
||||
apiD3Object.objectType,
|
||||
apiD3Object.parentEntity,
|
||||
apiD3Object.useQuaternion,
|
||||
apiD3Object.position,
|
||||
apiD3Object.quaternion,
|
||||
apiD3Object.rotation,
|
||||
apiD3Object.scale,
|
||||
apiD3Object.up,
|
||||
apiD3Object.lookAt
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.API.Mesh.prototype = Object.create(GameLib.API.Component.prototype);
|
||||
GameLib.D3.API.Mesh.prototype = Object.create(GameLib.D3.API.Object.prototype);
|
||||
GameLib.D3.API.Mesh.prototype.constructor = GameLib.D3.API.Mesh;
|
||||
|
||||
|
||||
/**
|
||||
* Mesh Type
|
||||
* @type {number}
|
||||
*/
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_NORMAL = 0x0;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_SKINNED = 0x1;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_CURVE = 0x2;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_SPHERE = 0x3;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_PLANE = 0x4;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_BOX = 0x5;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER = 0x6;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_TEXT = 0x7;
|
||||
GameLib.D3.API.Mesh.MESH_TYPE_LINE = 0x8;
|
||||
|
||||
/**
|
||||
* Draw Modes
|
||||
* @type {number}
|
||||
|
|
|
@ -0,0 +1,324 @@
|
|||
/**
|
||||
* GameLib.D3.Object
|
||||
* @param graphics
|
||||
* @param apiObject
|
||||
* @property objectType
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Object = function (
|
||||
graphics,
|
||||
apiObject
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiObject)) {
|
||||
apiObject = {
|
||||
objectType: GameLib.D3.API.Object.OBJECT_TYPE_NONE
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Object.call(
|
||||
this,
|
||||
apiObject.id,
|
||||
apiObject.name,
|
||||
apiObject.objectType,
|
||||
apiObject.parentEntity,
|
||||
apiObject.useQuaternion,
|
||||
apiObject.position,
|
||||
apiObject.quaternion,
|
||||
apiObject.rotation,
|
||||
apiObject.scale,
|
||||
apiObject.up,
|
||||
apiObject.lookAt
|
||||
);
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotation = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.rotation,
|
||||
this
|
||||
);
|
||||
|
||||
this.scale = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.scale,
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.up,
|
||||
this
|
||||
);
|
||||
|
||||
this.lookAt = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.lookAt,
|
||||
this
|
||||
);
|
||||
|
||||
GameLib.Component.call(
|
||||
this,
|
||||
GameLib.D3.Object.GetLinkedObjects(this.objectType)
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Object.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.Object.prototype.constructor = GameLib.D3.Object;
|
||||
|
||||
/**
|
||||
* Get Linked Objects
|
||||
* @param objectType
|
||||
* @returns {{}}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Object.GetLinkedObjects = function(objectType) {
|
||||
var linkedObjects = {};
|
||||
|
||||
switch (objectType) {
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE :
|
||||
linkedObjects.renderTarget = GameLib.D3.RenderTarget;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO :
|
||||
linkedObjects.effect = GameLib.D3.Effect;
|
||||
break;
|
||||
case GameLib.D3.API.Object.OBJECT_TYPE_MESH :
|
||||
linkedObjects.parentMesh = GameLib.D3.Mesh;
|
||||
linkedObjects.parentScene = GameLib.D3.Scene;
|
||||
linkedObjects.materials = [GameLib.D3.Material];
|
||||
linkedObjects.geometry = GameLib.D3.Geometry;
|
||||
linkedObjects.skeleton = GameLib.D3.Skeleton;
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return linkedObjects;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a mesh instance or updates it
|
||||
*/
|
||||
GameLib.D3.Object.prototype.createInstance = function() {
|
||||
|
||||
if (!this.instance) {
|
||||
console.warn('do not call the GameLib.D3.Object constructor directly');
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateInstance('position');
|
||||
|
||||
if (this instanceof GameLib.D3.Camera) {
|
||||
|
||||
if (
|
||||
this.objectType === GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE ||
|
||||
this.objectType === GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO
|
||||
) {
|
||||
this.updateInstance('lookAt');
|
||||
}
|
||||
|
||||
} else {
|
||||
/**
|
||||
* We ignore 'lookAt' - since it updates the rotation etc.. We assume that after lookAt we have our orientation
|
||||
* and store /use these values instead - lookAt is more a 'runtime' thing
|
||||
*/
|
||||
this.updateInstance('rotation');
|
||||
}
|
||||
|
||||
this.updateInstance('scale');
|
||||
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the mesh instance
|
||||
*/
|
||||
GameLib.D3.Object.prototype.updateInstance = function(property) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||
console.warn('3d object instance not ready');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'objectType') {
|
||||
var componentType = GameLib.D3.API.Object.GetComponentType(this.objectType);
|
||||
this.replace(componentType);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'useQuaternion' ||
|
||||
property === 'quaternion' ||
|
||||
property === 'rotation'
|
||||
) {
|
||||
if (this.useQuaternion) {
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.quaternion)) {
|
||||
|
||||
this.quaternion.axis.instance.x = this.quaternion.axis.x;
|
||||
this.quaternion.axis.instance.y = this.quaternion.axis.y;
|
||||
this.quaternion.axis.instance.z = this.quaternion.axis.z;
|
||||
|
||||
this.instance.quaternion.x = this.quaternion.x;
|
||||
this.instance.quaternion.y = this.quaternion.y;
|
||||
this.instance.quaternion.z = this.quaternion.z;
|
||||
this.instance.quaternion.w = this.quaternion.w;
|
||||
this.instance.quaternion.setFromAxisAngle(
|
||||
this.quaternion.axis.instance,
|
||||
this.quaternion.angle
|
||||
);
|
||||
|
||||
this.rotation.x = this.instance.rotation.x;
|
||||
this.rotation.y = this.instance.rotation.y;
|
||||
this.rotation.z = this.instance.rotation.z;
|
||||
|
||||
this.rotation.instance.x = this.rotation.x;
|
||||
this.rotation.instance.y = this.rotation.y;
|
||||
this.rotation.instance.z = this.rotation.z;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.rotation)) {
|
||||
|
||||
this.rotation.instance.x = this.rotation.x;
|
||||
this.rotation.instance.y = this.rotation.y;
|
||||
this.rotation.instance.z = this.rotation.z;
|
||||
|
||||
this.instance.rotation.x = this.rotation.x;
|
||||
this.instance.rotation.y = this.rotation.y;
|
||||
this.instance.rotation.z = this.rotation.z;
|
||||
|
||||
this.quaternion.x = this.instance.quaternion.x;
|
||||
this.quaternion.y = this.instance.quaternion.y;
|
||||
this.quaternion.z = this.instance.quaternion.z;
|
||||
this.quaternion.w = this.instance.quaternion.w;
|
||||
|
||||
this.quaternion.instance.x = this.quaternion.x;
|
||||
this.quaternion.instance.y = this.quaternion.y;
|
||||
this.quaternion.instance.z = this.quaternion.z;
|
||||
this.quaternion.instance.w = this.quaternion.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (property === 'position') {
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.position)) {
|
||||
|
||||
this.position.instance.x = this.position.x;
|
||||
this.position.instance.y = this.position.y;
|
||||
this.position.instance.z = this.position.z;
|
||||
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
}
|
||||
}
|
||||
|
||||
if (property === 'scale') {
|
||||
|
||||
this.scale.instance.x = this.scale.x;
|
||||
this.scale.instance.y = this.scale.y;
|
||||
this.scale.instance.z = this.scale.z;
|
||||
|
||||
this.instance.scale.x = this.scale.x;
|
||||
this.instance.scale.y = this.scale.y;
|
||||
this.instance.scale.z = this.scale.z;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'up' ||
|
||||
property === 'lookAt'
|
||||
) {
|
||||
|
||||
this.up.instance.x = this.up.x;
|
||||
this.up.instance.y = this.up.y;
|
||||
this.up.instance.z = this.up.z;
|
||||
|
||||
this.instance.up.x = this.up.x;
|
||||
this.instance.up.y = this.up.y;
|
||||
this.instance.up.z = this.up.z;
|
||||
|
||||
this.lookAt.instance.x = this.lookAt.x;
|
||||
this.lookAt.instance.y = this.lookAt.y;
|
||||
this.lookAt.instance.z = this.lookAt.z;
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.lookAt)) {
|
||||
this.instance.lookAt(this.lookAt.instance);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
|
||||
this.instance.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
GameLib.D3.Object.prototype.updateFromInstance.call(this, 'rotation');
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update GameLib.D3.Object from its instance
|
||||
* @param property
|
||||
*/
|
||||
GameLib.D3.Object.prototype.updateFromInstance = function(property) {
|
||||
if (
|
||||
property === 'rotation' ||
|
||||
property === 'quaternion'
|
||||
) {
|
||||
this.rotation.x = this.instance.rotation.x;
|
||||
this.rotation.y = this.instance.rotation.y;
|
||||
this.rotation.z = this.instance.rotation.z;
|
||||
|
||||
this.quaternion.x = this.instance.quaternion.x;
|
||||
this.quaternion.y = this.instance.quaternion.y;
|
||||
this.quaternion.z = this.instance.quaternion.z;
|
||||
this.quaternion.w = this.instance.quaternion.w;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Object to a GameLib.D3.API.Object
|
||||
* @returns {GameLib.D3.API.Object}
|
||||
*/
|
||||
GameLib.D3.Object.prototype.toApiObject = function() {
|
||||
|
||||
var apiObject = new GameLib.D3.API.Object(
|
||||
this.id,
|
||||
this.name,
|
||||
this.objectType,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
this.useQuaternion,
|
||||
this.position.toApiObject(),
|
||||
this.quaternion.toApiObject(),
|
||||
this.rotation.toApiObject(),
|
||||
this.scale.toApiObject(),
|
||||
this.up.toApiObject(),
|
||||
this.lookAt.toApiObject()
|
||||
);
|
||||
|
||||
return apiObject;
|
||||
};
|
||||
|
||||
GameLib.D3.Object.prototype.translate = function(vector3) {
|
||||
|
||||
this.position.x += vector3.x;
|
||||
this.position.y += vector3.y;
|
||||
this.position.z += vector3.z;
|
||||
|
||||
this.updateInstance('position');
|
||||
};
|
|
@ -1,78 +1,37 @@
|
|||
/**
|
||||
* GameLib.D3.Camera
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiCamera GameLib.D3.API.Camera
|
||||
* @param apiD3ObjectCamera GGameLib.D3.API.Object
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Camera = function(
|
||||
graphics,
|
||||
apiCamera
|
||||
apiD3ObjectCamera
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCamera)) {
|
||||
apiCamera = {};
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCamera)) {
|
||||
apiD3ObjectCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Camera.call(
|
||||
this,
|
||||
apiCamera.id,
|
||||
apiCamera.name,
|
||||
apiCamera.cameraType,
|
||||
apiCamera.aspect,
|
||||
apiCamera.position,
|
||||
apiCamera.rotation,
|
||||
apiCamera.quaternion,
|
||||
apiCamera.lookAt,
|
||||
apiCamera.parentEntity
|
||||
apiD3ObjectCamera,
|
||||
apiD3ObjectCamera.aspect
|
||||
);
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
graphics,
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.lookAt = new GameLib.Vector3(
|
||||
graphics,
|
||||
this.lookAt,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotation = new GameLib.Vector3(
|
||||
graphics,
|
||||
this.rotation,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
graphics,
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
var linkedObjects = {};
|
||||
|
||||
switch (apiCamera.cameraType) {
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_CUBE :
|
||||
linkedObjects.renderTarget = GameLib.D3.RenderTarget;
|
||||
break;
|
||||
case GameLib.D3.API.Camera.CAMERA_TYPE_STEREO :
|
||||
linkedObjects.effect = GameLib.D3.Effect;
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
GameLib.Component.call(
|
||||
GameLib.D3.Object.call(
|
||||
this,
|
||||
linkedObjects
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Camera.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.Camera.prototype = Object.create(GameLib.D3.Object.prototype);
|
||||
GameLib.D3.Camera.prototype.constructor = GameLib.D3.Camera;
|
||||
|
||||
/**
|
||||
|
@ -81,29 +40,6 @@ GameLib.D3.Camera.prototype.constructor = GameLib.D3.Camera;
|
|||
*/
|
||||
GameLib.D3.Camera.prototype.createInstance = function() {
|
||||
|
||||
/**
|
||||
* Not all implementations of camera has a position (Stereo camera gets its position on update)
|
||||
*/
|
||||
if (GameLib.Utils.Defined(this.instance.position)) {
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.rotation)) {
|
||||
this.instance.rotation.x = this.rotation.x;
|
||||
this.instance.rotation.y = this.rotation.y;
|
||||
this.instance.rotation.z = this.rotation.z;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.quaternion)) {
|
||||
this.instance.quaternion.x = this.quaternion.x;
|
||||
this.instance.quaternion.y = this.quaternion.y;
|
||||
this.instance.quaternion.z = this.quaternion.z;
|
||||
this.instance.quaternion.w = this.quaternion.w;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Not all implementations of camera has aspect ratio, we, however do have an aspect ratio for all our cameras
|
||||
*/
|
||||
|
@ -116,21 +52,7 @@ GameLib.D3.Camera.prototype.createInstance = function() {
|
|||
this.instance.aspect = this.aspect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only do lookAt for stereo and cube cameras
|
||||
*/
|
||||
if (
|
||||
this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_STEREO ||
|
||||
this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE
|
||||
) {
|
||||
this.instance.lookAt(this.lookAt.instance);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
|
||||
this.instance.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
GameLib.D3.Object.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -138,38 +60,6 @@ GameLib.D3.Camera.prototype.createInstance = function() {
|
|||
*/
|
||||
GameLib.D3.Camera.prototype.updateInstance = function(property) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(property)) {
|
||||
console.warn('no camera property specified for : ' + this.name);
|
||||
}
|
||||
|
||||
if (property === 'cameraType') {
|
||||
|
||||
this.remove();
|
||||
|
||||
var args = [this.graphics, {
|
||||
id : this.id,
|
||||
name : this.name
|
||||
}];
|
||||
|
||||
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_STEREO) {
|
||||
GameLib.D3.Camera.Stereo.apply(this, args);
|
||||
}
|
||||
|
||||
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_CUBE) {
|
||||
GameLib.D3.Camera.Cube.apply(this, args);
|
||||
}
|
||||
|
||||
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE) {
|
||||
GameLib.D3.Camera.Perspective.apply(this, args);
|
||||
}
|
||||
|
||||
if (this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC) {
|
||||
GameLib.D3.Camera.Orthographic.apply(this, args);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'aspect') {
|
||||
if (GameLib.Utils.Defined(this.instance.aspect)) {
|
||||
this.instance.aspect = this.aspect;
|
||||
|
@ -182,92 +72,12 @@ GameLib.D3.Camera.prototype.updateInstance = function(property) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (property === 'position') {
|
||||
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
|
||||
this.instance.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'rotation') {
|
||||
|
||||
this.instance.rotation.x = this.rotation.x;
|
||||
this.instance.rotation.y = this.rotation.y;
|
||||
this.instance.rotation.z = this.rotation.z;
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
|
||||
this.instance.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'quaternion') {
|
||||
|
||||
console.log('todo: update quaternion');
|
||||
|
||||
// return;
|
||||
// if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
|
||||
// this.instance.updateProjectionMatrix();
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'lookAt') {
|
||||
|
||||
this.lookAt.instance.x = this.lookAt.x;
|
||||
this.lookAt.instance.y = this.lookAt.y;
|
||||
this.lookAt.instance.z = this.lookAt.z;
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.lookAt)) {
|
||||
this.instance.lookAt(this.lookAt.instance);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {
|
||||
this.instance.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
GameLib.D3.Object.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Resize default
|
||||
* @param width
|
||||
* @param height
|
||||
* Update GameLib.D3.Camera from instance
|
||||
*/
|
||||
// GameLib.D3.Camera.prototype.resize = function(width, height) {
|
||||
// camera.aspect = width / height;
|
||||
// camera.updateInstance();
|
||||
// };
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Camera to a new GameLib.D3.API.Camera
|
||||
* @returns {GameLib.D3.API.Camera}
|
||||
*/
|
||||
GameLib.D3.Camera.prototype.toApiObject = function() {
|
||||
|
||||
return new GameLib.D3.API.Camera(
|
||||
this.id,
|
||||
this.name,
|
||||
this.cameraType,
|
||||
this.aspect,
|
||||
this.position.toApiObject(),
|
||||
this.lookAt.toApiObject(),
|
||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Camera.prototype.updateFromInstance = function() {
|
||||
|
||||
this.aspect = this.instance.aspect;
|
||||
|
@ -283,4 +93,18 @@ GameLib.D3.Camera.prototype.updateFromInstance = function() {
|
|||
} else {
|
||||
console.warn('todo: update lookAt somehow...');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Camera to a new GameLib.D3.API.Camera
|
||||
* @returns {GameLib.D3.API.Camera}
|
||||
*/
|
||||
GameLib.D3.Camera.prototype.toApiObject = function() {
|
||||
|
||||
var apiD3Object = GameLib.D3.Object.prototype.toApiObject.call(this);
|
||||
|
||||
return new GameLib.D3.API.Camera(
|
||||
apiD3Object,
|
||||
this.aspect
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
/**
|
||||
* GameLib.D3.Camera.Cube
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiCubeCamera
|
||||
* @param apiD3ObjectCubeCamera
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Camera.Cube = function(
|
||||
graphics,
|
||||
apiCubeCamera
|
||||
apiD3ObjectCubeCamera
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiCubeCamera)) {
|
||||
apiCubeCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_CUBE
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectCubeCamera)) {
|
||||
apiD3ObjectCubeCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Camera.Cube.call(
|
||||
this,
|
||||
apiCubeCamera,
|
||||
apiCubeCamera.near,
|
||||
apiCubeCamera.far,
|
||||
apiCubeCamera.cubeResolution,
|
||||
apiCubeCamera.renderTarget
|
||||
apiD3ObjectCubeCamera,
|
||||
apiD3ObjectCubeCamera.near,
|
||||
apiD3ObjectCubeCamera.far,
|
||||
apiD3ObjectCubeCamera.cubeResolution,
|
||||
apiD3ObjectCubeCamera.renderTarget
|
||||
);
|
||||
|
||||
if (this.renderTarget instanceof GameLib.D3.API.RenderTarget.Cube) {
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
/**
|
||||
* GameLib.D3.Camera.Orthographic
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiOrthographicCamera
|
||||
* @param apiD3OBjectOrthographicCamera
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Camera.Orthographic = function(
|
||||
graphics,
|
||||
apiOrthographicCamera
|
||||
apiD3OBjectOrthographicCamera
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiOrthographicCamera)) {
|
||||
apiOrthographicCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC,
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3OBjectOrthographicCamera)) {
|
||||
apiD3OBjectOrthographicCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC,
|
||||
position : GameLib.API.Vector3(0,0,10),
|
||||
lookAt: GameLib.API.Vector3(0,0,-1)
|
||||
lookAt: GameLib.API.Vector3(0,0,-10)
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Camera.Orthographic.call(
|
||||
this,
|
||||
apiOrthographicCamera,
|
||||
apiOrthographicCamera.aspectRatioMode,
|
||||
apiOrthographicCamera.minWidth,
|
||||
apiOrthographicCamera.minHeight,
|
||||
apiOrthographicCamera.width,
|
||||
apiOrthographicCamera.height,
|
||||
apiOrthographicCamera.near,
|
||||
apiOrthographicCamera.far,
|
||||
apiOrthographicCamera.left,
|
||||
apiOrthographicCamera.right,
|
||||
apiOrthographicCamera.top,
|
||||
apiOrthographicCamera.bottom,
|
||||
apiOrthographicCamera.zoom
|
||||
apiD3OBjectOrthographicCamera,
|
||||
apiD3OBjectOrthographicCamera.aspectRatioMode,
|
||||
apiD3OBjectOrthographicCamera.minWidth,
|
||||
apiD3OBjectOrthographicCamera.minHeight,
|
||||
apiD3OBjectOrthographicCamera.width,
|
||||
apiD3OBjectOrthographicCamera.height,
|
||||
apiD3OBjectOrthographicCamera.near,
|
||||
apiD3OBjectOrthographicCamera.far,
|
||||
apiD3OBjectOrthographicCamera.left,
|
||||
apiD3OBjectOrthographicCamera.right,
|
||||
apiD3OBjectOrthographicCamera.top,
|
||||
apiD3OBjectOrthographicCamera.bottom,
|
||||
apiD3OBjectOrthographicCamera.zoom
|
||||
);
|
||||
|
||||
GameLib.D3.Camera.call(
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
/**
|
||||
* GameLib.D3.Camera.Perspective
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiPerspectiveCamera
|
||||
* @param apiD3ObjectPerspectiveCamera
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Camera.Perspective = function(
|
||||
graphics,
|
||||
apiPerspectiveCamera
|
||||
apiD3ObjectPerspectiveCamera
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiPerspectiveCamera)) {
|
||||
apiPerspectiveCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectPerspectiveCamera)) {
|
||||
apiD3ObjectPerspectiveCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Camera.Perspective.call(
|
||||
this,
|
||||
apiPerspectiveCamera,
|
||||
apiPerspectiveCamera.near,
|
||||
apiPerspectiveCamera.far,
|
||||
apiPerspectiveCamera.fov,
|
||||
apiPerspectiveCamera.filmGauge,
|
||||
apiPerspectiveCamera.filmOffset,
|
||||
apiPerspectiveCamera.focus,
|
||||
apiPerspectiveCamera.zoom
|
||||
apiD3ObjectPerspectiveCamera,
|
||||
apiD3ObjectPerspectiveCamera.near,
|
||||
apiD3ObjectPerspectiveCamera.far,
|
||||
apiD3ObjectPerspectiveCamera.fov,
|
||||
apiD3ObjectPerspectiveCamera.filmGauge,
|
||||
apiD3ObjectPerspectiveCamera.filmOffset,
|
||||
apiD3ObjectPerspectiveCamera.focus,
|
||||
apiD3ObjectPerspectiveCamera.zoom
|
||||
);
|
||||
|
||||
GameLib.D3.Camera.call(
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/**
|
||||
* GameLib.D3.Camera.Stereo
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiStereoCamera
|
||||
* @param apiD3ObjectStereoCamera
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Camera.Stereo = function(
|
||||
graphics,
|
||||
apiStereoCamera
|
||||
apiD3ObjectStereoCamera
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiStereoCamera)) {
|
||||
apiStereoCamera = {
|
||||
cameraType : GameLib.D3.API.Camera.CAMERA_TYPE_STEREO
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectStereoCamera)) {
|
||||
apiD3ObjectStereoCamera = {
|
||||
objectType : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Camera.Stereo.call(
|
||||
this,
|
||||
apiStereoCamera,
|
||||
apiStereoCamera.stereoMode
|
||||
apiD3ObjectStereoCamera,
|
||||
apiD3ObjectStereoCamera.stereoMode
|
||||
);
|
||||
|
||||
GameLib.D3.Camera.call(
|
||||
|
|
|
@ -218,3 +218,4 @@ GameLib.D3.Geometry.prototype.updateFromInstance = function() {
|
|||
console.warn('the child class should take care of updating from instance');
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
|
@ -468,4 +468,32 @@ GameLib.D3.Geometry.Normal.prototype.applyToInstance = function(property) {
|
|||
GameLib.D3.Geometry.Normal.prototype.computeVertexNormals = function() {
|
||||
console.log('re-computing vertex normals');
|
||||
this.instance.computeVertexNormals();
|
||||
};
|
||||
|
||||
/**
|
||||
* Invert winding order
|
||||
*/
|
||||
GameLib.D3.Geometry.Normal.prototype.invertWindingOrder = function() {
|
||||
|
||||
this.faces.forEach(
|
||||
function (face) {
|
||||
|
||||
var tmpV1 = face.v1;
|
||||
face.v1 = face.v2;
|
||||
face.v2 = tmpV1;
|
||||
|
||||
var tmpV1uv = face.v1uv;
|
||||
face.v1uv = face.v2uv;
|
||||
face.v2uv = tmpV1uv;
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
if (this.instance) {
|
||||
this.instance.computeVertexNormals();
|
||||
this.instance.computeFaceNormals();
|
||||
this.instance.elementsNeedUpdate = true;
|
||||
this.instance.normalsNeedUpdate = true;
|
||||
}
|
||||
|
||||
};
|
|
@ -41,7 +41,7 @@ GameLib.D3.Helper = function(
|
|||
|
||||
if (
|
||||
object instanceof GameLib.D3.Mesh &&
|
||||
object.meshType !== GameLib.D3.API.Mesh.MESH_TYPE_CURVE
|
||||
object.meshType !== GameLib.D3.API.Object.OBJECT_TYPE_MESH_CURVE
|
||||
) {
|
||||
helperType = GameLib.D3.Helper.HELPER_TYPE_EDGES;
|
||||
}
|
||||
|
|
|
@ -1,48 +1,39 @@
|
|||
/**
|
||||
* GameLib.D3.Mesh
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param apiMesh GameLib.D3.API.Mesh
|
||||
* @param apiD3ObjectMesh GameLib.D3.API.Mesh
|
||||
* @property geometry
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Mesh = function (
|
||||
graphics,
|
||||
apiMesh
|
||||
apiD3ObjectMesh
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType: GameLib.D3.API.Mesh.MESH_TYPE_NORMAL
|
||||
if (GameLib.Utils.UndefinedOrNull(apiD3ObjectMesh)) {
|
||||
apiD3ObjectMesh = {
|
||||
objectType: GameLib.D3.API.Object.OBJECT_TYPE_MESH
|
||||
};
|
||||
}
|
||||
|
||||
GameLib.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.parentEntity,
|
||||
apiMesh.geometry,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.drawMode,
|
||||
apiMesh.morphTargetInfluences,
|
||||
apiMesh.morphTargetDictionary
|
||||
apiD3ObjectMesh,
|
||||
apiD3ObjectMesh.geometry,
|
||||
apiD3ObjectMesh.materials,
|
||||
apiD3ObjectMesh.parentMesh,
|
||||
apiD3ObjectMesh.parentScene,
|
||||
apiD3ObjectMesh.excludeFromEnvironment,
|
||||
apiD3ObjectMesh.skeleton,
|
||||
apiD3ObjectMesh.renderOrder,
|
||||
apiD3ObjectMesh.visible,
|
||||
apiD3ObjectMesh.castShadow,
|
||||
apiD3ObjectMesh.receiveShadow,
|
||||
apiD3ObjectMesh.drawMode,
|
||||
apiD3ObjectMesh.morphTargetInfluences,
|
||||
apiD3ObjectMesh.morphTargetDictionary
|
||||
);
|
||||
|
||||
if (
|
||||
|
@ -71,71 +62,22 @@ GameLib.D3.Mesh = function (
|
|||
);
|
||||
}
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.position,
|
||||
this
|
||||
);
|
||||
|
||||
this.quaternion = new GameLib.Quaternion(
|
||||
this.graphics,
|
||||
this.quaternion,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotation = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.rotation,
|
||||
this
|
||||
);
|
||||
|
||||
this.scale = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.scale,
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.up,
|
||||
this
|
||||
);
|
||||
|
||||
var linkedObjects = {
|
||||
'parentMesh' : GameLib.D3.Mesh,
|
||||
'parentScene' : GameLib.D3.Scene,
|
||||
'materials' : [GameLib.D3.Material],
|
||||
'geometry' : GameLib.D3.Geometry,
|
||||
'skeleton' : GameLib.D3.Skeleton
|
||||
};
|
||||
|
||||
if (apiMesh.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) {
|
||||
linkedObjects.dotObject = GameLib.D3.Mesh;
|
||||
}
|
||||
|
||||
if (apiMesh.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) {
|
||||
linkedObjects.font = GameLib.D3.Font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime meshes have helpers too
|
||||
* @type {null}
|
||||
*/
|
||||
this.helper = null;
|
||||
|
||||
this.updateRotationFromAxisAngle = true;
|
||||
|
||||
GameLib.Component.call(
|
||||
GameLib.D3.Object.call(
|
||||
this,
|
||||
linkedObjects
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype = Object.create(GameLib.Component.prototype);
|
||||
GameLib.D3.Mesh.prototype = Object.create(GameLib.D3.Object.prototype);
|
||||
GameLib.D3.Mesh.prototype.constructor = GameLib.D3.Mesh;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a mesh instance or updates it
|
||||
*/
|
||||
|
@ -197,37 +139,6 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
this.parentScene.addObject(this);
|
||||
}
|
||||
|
||||
this.instance.position.x = this.position.x;
|
||||
this.instance.position.y = this.position.y;
|
||||
this.instance.position.z = this.position.z;
|
||||
|
||||
if (this.useQuaternion) {
|
||||
this.instance.quaternion.x = this.quaternion.x;
|
||||
this.instance.quaternion.y = this.quaternion.y;
|
||||
this.instance.quaternion.z = this.quaternion.z;
|
||||
this.instance.quaternion.w = this.quaternion.w;
|
||||
this.instance.quaternion.setFromAxisAngle(
|
||||
new THREE.Vector3(
|
||||
this.quaternion.axis.x,
|
||||
this.quaternion.axis.y,
|
||||
this.quaternion.axis.z
|
||||
),
|
||||
this.quaternion.angle
|
||||
);
|
||||
} else {
|
||||
this.instance.rotation.x = this.rotation.x;
|
||||
this.instance.rotation.y = this.rotation.y;
|
||||
this.instance.rotation.z = this.rotation.z;
|
||||
}
|
||||
|
||||
this.instance.scale.x = this.scale.x;
|
||||
this.instance.scale.y = this.scale.y;
|
||||
this.instance.scale.z = this.scale.z;
|
||||
|
||||
this.instance.up.x = this.up.x;
|
||||
this.instance.up.y = this.up.y;
|
||||
this.instance.up.z = this.up.z;
|
||||
|
||||
this.instance.renderOrder = this.renderOrder;
|
||||
|
||||
this.instance.visible = this.visible;
|
||||
|
@ -243,8 +154,8 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
*/
|
||||
this.morphTargetInfluences = this.instance.morphTargetInfluences;
|
||||
this.morphTargetDictionary = this.instance.morphTargetDictionary;
|
||||
|
||||
GameLib.Component.prototype.createInstance.call(this);
|
||||
|
||||
GameLib.D3.Object.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -335,17 +246,10 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
|||
)
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'rotation' ||
|
||||
property === 'quaternion' ||
|
||||
property === 'useQuaternion'
|
||||
) {
|
||||
this.updateInstanceRotation();
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
}
|
||||
return;
|
||||
if (property === 'parentScene') {
|
||||
/**
|
||||
* This is handled by LinkingSystem - probably will change soon
|
||||
*/
|
||||
}
|
||||
|
||||
if (property === 'parentMesh') {
|
||||
|
@ -418,35 +322,12 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
|||
this.instance.parent = this.parentMesh.instance;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'scale') {
|
||||
this.updateInstanceScale();
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'position') {
|
||||
this.updateInstancePosition();
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'up') {
|
||||
this.instance.up.x = this.up.x;
|
||||
this.instance.up.y = this.up.y;
|
||||
this.instance.up.z = this.up.z;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -475,230 +356,40 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
|||
return;
|
||||
}
|
||||
|
||||
GameLib.D3.Object.prototype.updateInstance.call(this, property);
|
||||
|
||||
/**
|
||||
* 'parentScene' is handled by LinkingSystem
|
||||
* Update our helper (if any)
|
||||
*/
|
||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
|
||||
GameLib.D3.Mesh.prototype.lookAt = function(vector) {
|
||||
|
||||
this.instance.lookAt(
|
||||
new THREE.Vector3(
|
||||
vector.x,
|
||||
vector.y,
|
||||
vector.z
|
||||
)
|
||||
);
|
||||
|
||||
this.rotation.x = this.instance.rotation.x;
|
||||
this.rotation.y = this.instance.rotation.y;
|
||||
this.rotation.z = this.instance.rotation.z;
|
||||
|
||||
this.quaternion.x = this.instance.quaternion.x;
|
||||
this.quaternion.y = this.instance.quaternion.y;
|
||||
this.quaternion.z = this.instance.quaternion.z;
|
||||
this.quaternion.w = this.instance.quaternion.w;
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.invertWindingOrder = function() {
|
||||
|
||||
this.faces.forEach(
|
||||
function (face) {
|
||||
|
||||
var tmpV1 = face.v1;
|
||||
face.v1 = face.v2;
|
||||
face.v2 = tmpV1;
|
||||
|
||||
var tmpV1uv = face.v1uv;
|
||||
face.v1uv = face.v2uv;
|
||||
face.v2uv = tmpV1uv;
|
||||
|
||||
if (
|
||||
property === 'useQuaternion' ||
|
||||
property === 'position' ||
|
||||
property === 'rotation' ||
|
||||
property === 'quaternion' ||
|
||||
property === 'scale' ||
|
||||
property === 'up' ||
|
||||
property === 'lookAt'
|
||||
) {
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
}
|
||||
);
|
||||
|
||||
if (this.instance) {
|
||||
this.instance.geometry.computeVertexNormals();
|
||||
this.instance.geometry.computeFaceNormals();
|
||||
this.instance.geometry.normalsNeedUpdate = true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.applyBones = function(geometry) {
|
||||
|
||||
/**
|
||||
* Setup Bone Indexes
|
||||
*/
|
||||
this.skinIndices.map(
|
||||
function(skinIndex) {
|
||||
geometry.skinIndices.push(
|
||||
new THREE.Vector4(
|
||||
skinIndex.x,
|
||||
skinIndex.y,
|
||||
skinIndex.z,
|
||||
skinIndex.w
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Setup Bone Weights
|
||||
*/
|
||||
this.skinWeights.map(
|
||||
function(skinWeight) {
|
||||
geometry.skinWeights.push(
|
||||
new THREE.Vector4(
|
||||
skinWeight.x,
|
||||
skinWeight.y,
|
||||
skinWeight.z,
|
||||
skinWeight.w
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a child instance to this instance
|
||||
* @param childInstance
|
||||
* @param child
|
||||
*/
|
||||
// GameLib.D3.Mesh.prototype.addChild = function(childInstance, child) {
|
||||
//
|
||||
// if (!this.instance) {
|
||||
// throw new Error('mesh instance not loaded yet : ' + this.name);
|
||||
// }
|
||||
//
|
||||
// if (GameLib.Utils.UndefinedOrNull(childInstance)) {
|
||||
// throw new Error('no child mesh instance');
|
||||
// }
|
||||
//
|
||||
// if (GameLib.Utils.UndefinedOrNull(child)) {
|
||||
// throw new Error('no child mesh');
|
||||
// }
|
||||
//
|
||||
// this.instance.add(childInstance);
|
||||
//
|
||||
// childInstance.parent = this.instance;
|
||||
//
|
||||
// child.parentMesh = this;
|
||||
// };
|
||||
|
||||
/**
|
||||
* Sets a parent for this mesh
|
||||
* @param parentMesh
|
||||
*/
|
||||
// GameLib.D3.Mesh.prototype.setParentMesh = function(parentMesh) {
|
||||
//
|
||||
// /**
|
||||
// * Are we removing this child from the parent?
|
||||
// */
|
||||
// if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
|
||||
//
|
||||
// if (this.instance && this.instance.parent && this.parentScene.instance) {
|
||||
//
|
||||
// /**
|
||||
// * Update the parent matrix world
|
||||
// */
|
||||
// this.instance.parent.updateMatrixWorld();
|
||||
//
|
||||
// /**
|
||||
// * Copy the child world position into a temporary vector
|
||||
// * @type {THREE.Vector3}
|
||||
// */
|
||||
// var vector = new THREE.Vector3();
|
||||
// vector.setFromMatrixPosition(this.instance.matrixWorld);
|
||||
//
|
||||
// /**
|
||||
// * Detach child from parent within this scene
|
||||
// */
|
||||
// THREE.SceneUtils.detach(
|
||||
// this.instance,
|
||||
// this.instance.parent,
|
||||
// this.parentScene.instance
|
||||
// );
|
||||
//
|
||||
// /**
|
||||
// * We remember from now on that we have no parent mesh
|
||||
// * @type {null}
|
||||
// */
|
||||
// this.parentMesh = null;
|
||||
//
|
||||
// /**
|
||||
// * We store the world position back to the child
|
||||
// */
|
||||
// this.position.x = vector.x;
|
||||
// this.position.y = vector.y;
|
||||
// this.position.z = vector.z;
|
||||
//
|
||||
// /**
|
||||
// * Update the instance position
|
||||
// */
|
||||
// this.updateInstancePosition();
|
||||
//
|
||||
// /**
|
||||
// * Don't touch this instance parent - since it is now probably a scene object
|
||||
// */
|
||||
//
|
||||
// /**
|
||||
// * TODO: do we apply rotation somehow?
|
||||
// */
|
||||
//
|
||||
// } else {
|
||||
// throw new Error('Not enough information to detach')
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// if (!this.instance) {
|
||||
// throw new Error('No valid instance at time of adding to parent for mesh ' + this.name);
|
||||
// }
|
||||
//
|
||||
// if (!(parentMesh instanceof GameLib.D3.Mesh)) {
|
||||
// throw new Error('Not a valid parent mesh');
|
||||
// }
|
||||
//
|
||||
// this.parentMesh = parentMesh;
|
||||
//
|
||||
// /**
|
||||
// * Add this as a child to the parent
|
||||
// */
|
||||
// this.parentMesh.addChild(this.instance, this);
|
||||
// }
|
||||
//
|
||||
// };
|
||||
|
||||
// GameLib.D3.Mesh.prototype.getBoundingBox = function() {
|
||||
//
|
||||
// this.instance.geometry.computeBoundingBox();
|
||||
//
|
||||
// return new GameLib.Vector3(
|
||||
// this.graphics,
|
||||
// new GameLib.API.Vector3(
|
||||
// this.instance.geometry.boundingBox.max.x - this.instance.geometry.boundingBox.min.x,
|
||||
// this.instance.geometry.boundingBox.max.y - this.instance.geometry.boundingBox.min.y,
|
||||
// this.instance.geometry.boundingBox.max.z - this.instance.geometry.boundingBox.min.z
|
||||
// )
|
||||
// );
|
||||
//
|
||||
// };
|
||||
|
||||
/**
|
||||
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
|
||||
* TODO: morph stuff
|
||||
* @returns {GameLib.D3.API.Mesh}
|
||||
*/
|
||||
GameLib.D3.Mesh.prototype.toApiObject = function() {
|
||||
|
||||
var apiD3Object = GameLib.D3.Object.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMesh = new GameLib.D3.API.Mesh(
|
||||
this.id,
|
||||
this.name,
|
||||
this.meshType,
|
||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||
apiD3Object,
|
||||
|
||||
GameLib.Utils.IdOrNull(this.geometry),
|
||||
this.materials.map(
|
||||
function(material) {
|
||||
|
@ -709,19 +400,13 @@ GameLib.D3.Mesh.prototype.toApiObject = function() {
|
|||
GameLib.Utils.IdOrNull(this.parentScene),
|
||||
this.excludeFromEnvironment,
|
||||
GameLib.Utils.IdOrNull(this.skeleton),
|
||||
this.position.toApiObject(),
|
||||
this.quaternion.toApiObject(),
|
||||
this.rotation.toApiObject(),
|
||||
this.scale.toApiObject(),
|
||||
this.up.toApiObject(),
|
||||
this.renderOrder,
|
||||
this.useQuaternion,
|
||||
this.visible,
|
||||
this.castShadow,
|
||||
this.receiveShadow,
|
||||
this.drawMode
|
||||
// this.morphTargetInfluences,
|
||||
// this.morphTargetDictionary
|
||||
//morphTargetInfluences,
|
||||
//morphTargetDictionary
|
||||
);
|
||||
|
||||
return apiMesh;
|
||||
|
@ -753,86 +438,6 @@ GameLib.D3.Mesh.prototype.centerAroundOrigin = function() {
|
|||
return position;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.applyAxisAngleToPosition = function(axis, angle) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(axis)) {
|
||||
axis = this.quaternion.axis;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(angle)) {
|
||||
angle = this.quaternion.angle;
|
||||
}
|
||||
|
||||
this.position.applyAxisAngle(axis, angle);
|
||||
this.updateInstancePosition();
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.applyAxisAngleToUvs = function(axis, angle) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(axis)) {
|
||||
axis = this.quaternion.axis;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(angle)) {
|
||||
angle = this.quaternion.angle;
|
||||
}
|
||||
|
||||
// this.instance.geometry.faceVertexUvs[0].map(
|
||||
// function(uvs) {
|
||||
// uvs.map(function(uv) {
|
||||
//
|
||||
// var x = uv.x;
|
||||
//
|
||||
// uv.x = uv.y;
|
||||
// uv.y = x;
|
||||
//
|
||||
// //var v = new THREE.Vector3(uv.x, uv.y, 0);
|
||||
// //v.applyAxisAngle(axis, angle);
|
||||
// //uv.x = v.x;
|
||||
// //uv.y = v.u;
|
||||
// });
|
||||
// }
|
||||
// );
|
||||
|
||||
this.instance.geometry.uvsNeedUpdate = true;
|
||||
//
|
||||
// this.faces.map(
|
||||
// function(face) {
|
||||
// face.uvs.map(function(uvs){
|
||||
// uvs.map(
|
||||
// function(uv) {
|
||||
// var v = new GameLib.Vector3(this.graphics, new GameLib.API.Vector3(uv.x, uv.y, 0));
|
||||
// v.applyAxisAngle(axis, angle);
|
||||
// uv.x = v.x;
|
||||
// uv.y = v.y;
|
||||
// }
|
||||
// )
|
||||
// });
|
||||
// }
|
||||
// )
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.translate = function(vector3) {
|
||||
|
||||
this.position.x += vector3.x;
|
||||
this.position.y += vector3.y;
|
||||
this.position.z += vector3.z;
|
||||
|
||||
this.updateInstancePosition();
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.getDistanceFromCenter = function() {
|
||||
var position = this.instance.geometry.center();
|
||||
return new GameLib.Vector3(
|
||||
this.graphics,
|
||||
new GameLib.API.Vector3(
|
||||
position.x,
|
||||
position.y,
|
||||
position.z
|
||||
)
|
||||
)
|
||||
};
|
||||
|
||||
/**
|
||||
* Applies position, rotation and scale to the object vertice data, resets scale, rotation and sets position to origin.
|
||||
*/
|
||||
|
@ -841,6 +446,7 @@ GameLib.D3.Mesh.prototype.applyPositionRotationScale = function() {
|
|||
this.instance.updateMatrix();
|
||||
|
||||
this.instance.geometry.applyMatrix(this.instance.matrix);
|
||||
this.geometry.instance.updateFromInstance();
|
||||
|
||||
/**
|
||||
* Reset position
|
||||
|
@ -883,90 +489,6 @@ GameLib.D3.Mesh.prototype.applyPositionRotationScale = function() {
|
|||
* Update our instance matrix
|
||||
*/
|
||||
this.instance.updateMatrix();
|
||||
|
||||
/**
|
||||
* Let this reflect back to our vertices
|
||||
*/
|
||||
this.updateVerticesFromGeometryInstance(this.instance.geometry);
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.updateInstanceRotationFromAxisAngle = function(axis, angle) {
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(axis)) {
|
||||
axis = this.quaternion.axis;
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(angle)) {
|
||||
angle = this.quaternion.angle;
|
||||
}
|
||||
|
||||
this.quaternion.axis.instance.x = axis.x;
|
||||
this.quaternion.axis.instance.y = axis.y;
|
||||
this.quaternion.axis.instance.z = axis.z;
|
||||
this.quaternion.instance.setFromAxisAngle(this.quaternion.axis.instance, angle);
|
||||
this.instance.quaternion.copy(this.quaternion.instance);
|
||||
this.quaternion.x = this.quaternion.instance.x;
|
||||
this.quaternion.y = this.quaternion.instance.y;
|
||||
this.quaternion.z = this.quaternion.instance.z;
|
||||
this.quaternion.w = this.quaternion.instance.w;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.updateInstanceRotation = function() {
|
||||
|
||||
if (this.useQuaternion) {
|
||||
|
||||
this.updateInstanceRotationFromAxisAngle();
|
||||
|
||||
} else {
|
||||
|
||||
this.rotation.instance.set(
|
||||
this.rotation.x,
|
||||
this.rotation.y,
|
||||
this.rotation.z
|
||||
);
|
||||
|
||||
this.instance.rotation.set(
|
||||
this.rotation.x,
|
||||
this.rotation.y,
|
||||
this.rotation.z
|
||||
);
|
||||
}
|
||||
|
||||
if (this.helper) {
|
||||
this.helper.updateInstance();
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.updateInstancePosition = function() {
|
||||
|
||||
this.position.instance.set(
|
||||
this.position.x,
|
||||
this.position.y,
|
||||
this.position.z
|
||||
);
|
||||
|
||||
this.instance.position.copy(this.position.instance);
|
||||
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.prototype.updateInstanceScale = function() {
|
||||
|
||||
this.scale.instance.set(
|
||||
this.scale.x,
|
||||
this.scale.y,
|
||||
this.scale.z
|
||||
);
|
||||
|
||||
this.instance.scale.copy(this.scale.instance);
|
||||
|
||||
if (this.helper) {
|
||||
this.removeHelper();
|
||||
this.createHelper();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -975,92 +497,35 @@ GameLib.D3.Mesh.prototype.updateInstanceScale = function() {
|
|||
*/
|
||||
GameLib.D3.Mesh.prototype.getChildrenComponents = function() {
|
||||
|
||||
var components = [];
|
||||
var children = GameLib.Component.prototype.getChildrenComponents.call(this);
|
||||
|
||||
this.buildIdToObject();
|
||||
|
||||
Object.keys(this.idToObject).map(
|
||||
function(objectId) {
|
||||
if (this.id !== objectId) {
|
||||
components.push(this.idToObject[objectId]);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
return components;
|
||||
/*
|
||||
|
||||
this.materials.map(
|
||||
function (material) {
|
||||
|
||||
if (material instanceof GameLib.D3.Material) {
|
||||
GameLib.Utils.PushUnique(components, material);
|
||||
|
||||
for (var property in material.linkedObjects) {
|
||||
if (
|
||||
material.linkedObjects.hasOwnProperty(property) &&
|
||||
material.hasOwnProperty(property) &&
|
||||
material[property] &&
|
||||
typeof material[property] !== 'string' &&
|
||||
property !== 'parentEntity'
|
||||
) {
|
||||
GameLib.Utils.PushUnique(components, material[property]);
|
||||
for (var tProperty in material[property].linkedObjects) {
|
||||
if (
|
||||
material[property].linkedObjects.hasOwnProperty(tProperty) &&
|
||||
material[property].hasOwnProperty(tProperty) &&
|
||||
material[property][tProperty] &&
|
||||
typeof material[property][tProperty] !== 'string' &&
|
||||
tProperty !== 'parentEntity'
|
||||
) {
|
||||
|
||||
if (material[property][tProperty] instanceof Array) {
|
||||
material[property][tProperty].map(
|
||||
function(object) {
|
||||
GameLib.Utils.PushUnique(components, object);
|
||||
}
|
||||
)
|
||||
} else {
|
||||
GameLib.Utils.PushUnique(components, material[property][tProperty]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
*/
|
||||
/**
|
||||
* Push RigidBodies
|
||||
*/
|
||||
/* var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RIGID_BODY);
|
||||
rigidBodies.map(
|
||||
function(rigidBody) {
|
||||
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RIGID_BODY).map(
|
||||
function(rigidBody) {
|
||||
|
||||
if (rigidBody.parentMesh === this) {
|
||||
GameLib.Utils.PushUnique(components, rigidBody);
|
||||
if (rigidBody.parentMesh === this) {
|
||||
GameLib.Utils.PushUnique(children, rigidBody);
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
*/
|
||||
|
||||
/**
|
||||
* Push Shapes
|
||||
*/
|
||||
/* var shapes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SHAPE);
|
||||
shapes.map(
|
||||
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SHAPE).map(
|
||||
function(shape) {
|
||||
|
||||
if (shape.parentMesh === this) {
|
||||
GameLib.Utils.PushUnique(components, shape);
|
||||
GameLib.Utils.PushUnique(children, shape);
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
*/
|
||||
// return components;
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1099,18 +564,6 @@ GameLib.D3.Mesh.prototype.createHelper = function() {
|
|||
|
||||
};
|
||||
|
||||
// GameLib.D3.Mesh.prototype.addMaterial = function(material) {
|
||||
// if (this.materials.length === 1) {
|
||||
// this.instance.material = material.instance;
|
||||
// } else {
|
||||
// this.instance.material = this.materials.map(
|
||||
// function(material) {
|
||||
// return material.instance;
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// };
|
||||
|
||||
/**
|
||||
* Convenience function for removing a helper for this Mesh - should be called from Systems only
|
||||
*/
|
||||
|
|
|
@ -1158,14 +1158,14 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
object,
|
||||
property,
|
||||
{
|
||||
'normal' : GameLib.D3.API.Mesh.MESH_TYPE_NORMAL,
|
||||
'curve' : GameLib.D3.API.Mesh.MESH_TYPE_CURVE,
|
||||
'skinned' : GameLib.D3.API.Mesh.MESH_TYPE_SKINNED,
|
||||
'plane' : GameLib.D3.API.Mesh.MESH_TYPE_PLANE,
|
||||
'sphere' : GameLib.D3.API.Mesh.MESH_TYPE_SPHERE,
|
||||
'box' : GameLib.D3.API.Mesh.MESH_TYPE_BOX,
|
||||
'cylinder' : GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER,
|
||||
'text' : GameLib.D3.API.Mesh.MESH_TYPE_TEXT
|
||||
'normal' : GameLib.D3.API.Object.OBJECT_TYPE_MESH,
|
||||
'curve' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_CURVE,
|
||||
'skinned' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_SKINNED,
|
||||
'plane' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_PLANE,
|
||||
'sphere' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_SPHERE,
|
||||
'box' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_BOX,
|
||||
'cylinder' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_CYLINDER,
|
||||
'text' : GameLib.D3.API.Object.OBJECT_TYPE_MESH_TEXT
|
||||
}
|
||||
)
|
||||
);
|
||||
|
@ -1175,10 +1175,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
|||
object,
|
||||
property,
|
||||
{
|
||||
'perspective' : GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE,
|
||||
'orthographic' : GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC,
|
||||
'stereo' : GameLib.D3.API.Camera.CAMERA_TYPE_STEREO,
|
||||
'cube' : GameLib.D3.API.Camera.CAMERA_TYPE_CUBE
|
||||
'perspective' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE,
|
||||
'orthographic' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC,
|
||||
'stereo' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO,
|
||||
'cube' : GameLib.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE
|
||||
}
|
||||
)
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue