constructor updates - inheritance getting stable
parent
c98c75bd6e
commit
d0ac06f2b6
|
@ -56,6 +56,40 @@ GameLib.API.Matrix4 = function ApiMatrix4(
|
||||||
this.up = new GameLib.API.Vector4();
|
this.up = new GameLib.API.Vector4();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an API matrix from an Object matrix
|
||||||
|
* @param objectMatrix
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Matrix4.FromObjectMatrix = function(objectMatrix) {
|
||||||
|
return new GameLib.API.Matrix4(
|
||||||
|
new GameLib.API.Vector4(
|
||||||
|
objectMatrix.rows[0].x,
|
||||||
|
objectMatrix.rows[0].y,
|
||||||
|
objectMatrix.rows[0].z,
|
||||||
|
objectMatrix.rows[0].w
|
||||||
|
),
|
||||||
|
new GameLib.API.Vector4(
|
||||||
|
objectMatrix.rows[1].x,
|
||||||
|
objectMatrix.rows[1].y,
|
||||||
|
objectMatrix.rows[1].z,
|
||||||
|
objectMatrix.rows[1].w
|
||||||
|
),
|
||||||
|
new GameLib.API.Vector4(
|
||||||
|
objectMatrix.rows[2].x,
|
||||||
|
objectMatrix.rows[2].y,
|
||||||
|
objectMatrix.rows[2].z,
|
||||||
|
objectMatrix.rows[2].w
|
||||||
|
),
|
||||||
|
new GameLib.API.Vector4(
|
||||||
|
objectMatrix.rows[3].x,
|
||||||
|
objectMatrix.rows[3].y,
|
||||||
|
objectMatrix.rows[3].z,
|
||||||
|
objectMatrix.rows[3].w
|
||||||
|
)
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.API.Matrix4.prototype.rotationMatrixX = function (radians) {
|
GameLib.API.Matrix4.prototype.rotationMatrixX = function (radians) {
|
||||||
this.identity();
|
this.identity();
|
||||||
this.rows[1] = new GameLib.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0);
|
this.rows[1] = new GameLib.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0);
|
||||||
|
@ -130,37 +164,3 @@ GameLib.API.Matrix4.prototype.identity = function () {
|
||||||
new GameLib.API.Vector4(0, 0, 0, 1)
|
new GameLib.API.Vector4(0, 0, 0, 1)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an API matrix from an Object matrix
|
|
||||||
* @param objectMatrix
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.API.Matrix4.FromObjectMatrix = function(objectMatrix) {
|
|
||||||
return new GameLib.API.Matrix4(
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[0].x,
|
|
||||||
objectMatrix.rows[0].y,
|
|
||||||
objectMatrix.rows[0].z,
|
|
||||||
objectMatrix.rows[0].w
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[1].x,
|
|
||||||
objectMatrix.rows[1].y,
|
|
||||||
objectMatrix.rows[1].z,
|
|
||||||
objectMatrix.rows[1].w
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[2].x,
|
|
||||||
objectMatrix.rows[2].y,
|
|
||||||
objectMatrix.rows[2].z,
|
|
||||||
objectMatrix.rows[2].w
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[3].x,
|
|
||||||
objectMatrix.rows[3].y,
|
|
||||||
objectMatrix.rows[3].z,
|
|
||||||
objectMatrix.rows[3].w
|
|
||||||
)
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,4 +1,21 @@
|
||||||
GameLib.API.Quaternion = function (x, y, z, w, axis, angle) {
|
/**
|
||||||
|
* Quaternion
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param z
|
||||||
|
* @param w
|
||||||
|
* @param axis
|
||||||
|
* @param angle
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Quaternion = function (
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
w,
|
||||||
|
axis,
|
||||||
|
angle
|
||||||
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -202,16 +219,19 @@ GameLib.API.Quaternion.prototype.slerp = function (quaternion, t) {
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Quaternion.FromObjectQuaternion = function (objectQuaternion) {
|
GameLib.API.Quaternion.FromObjectQuaternion = function (objectQuaternion) {
|
||||||
|
|
||||||
|
var apiAxis = null;
|
||||||
|
|
||||||
|
if (objectQuaternion.axis) {
|
||||||
|
apiAxis = GameLib.API.Vector3.FromObjectVector(objectQuaternion.axis);
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.API.Quaternion(
|
return new GameLib.API.Quaternion(
|
||||||
objectQuaternion.x,
|
objectQuaternion.x,
|
||||||
objectQuaternion.y,
|
objectQuaternion.y,
|
||||||
objectQuaternion.z,
|
objectQuaternion.z,
|
||||||
objectQuaternion.w,
|
objectQuaternion.w,
|
||||||
new GameLib.API.Vector3(
|
apiAxis,
|
||||||
objectQuaternion.axis.x,
|
|
||||||
objectQuaternion.axis.y,
|
|
||||||
objectQuaternion.axis.z
|
|
||||||
),
|
|
||||||
objectQuaternion.angle
|
objectQuaternion.angle
|
||||||
)
|
)
|
||||||
};
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
GameLib.API.Vector2 = function ApiVector2(x, y) {
|
GameLib.API.Vector2 = function (x, y) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(x)) {
|
if (GameLib.Utils.UndefinedOrNull(x)) {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
|
|
@ -6,11 +6,20 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Color = function (graphics, parentObject, apiColor, grain) {
|
GameLib.Color = function (
|
||||||
|
graphics,
|
||||||
|
apiColor,
|
||||||
|
parentObject,
|
||||||
|
grain
|
||||||
|
) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiColor)) {
|
||||||
|
apiColor = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.API.Color.call(
|
GameLib.API.Color.call(
|
||||||
this,
|
this,
|
||||||
apiColor.r,
|
apiColor.r,
|
||||||
|
@ -19,6 +28,9 @@ GameLib.Color = function (graphics, parentObject, apiColor, grain) {
|
||||||
apiColor.a
|
apiColor.a
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
|
}
|
||||||
this.parentObject = parentObject;
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||||
|
@ -60,7 +72,8 @@ GameLib.Color.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
if (this.parentObject.updateInstance) {
|
if (this.parentObject &&
|
||||||
|
this.parentObject.updateInstance) {
|
||||||
this.parentObject.updateInstance();
|
this.parentObject.updateInstance();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
* @param heightOffset
|
* @param heightOffset
|
||||||
* @param containerWidthOffset
|
* @param containerWidthOffset
|
||||||
* @param containerHeightOffset
|
* @param containerHeightOffset
|
||||||
|
* @param selectDelayMs
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -24,6 +25,7 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
heightOffset,
|
heightOffset,
|
||||||
containerWidthOffset,
|
containerWidthOffset,
|
||||||
containerHeightOffset,
|
containerHeightOffset,
|
||||||
|
selectDelayMs,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
|
@ -86,6 +88,11 @@ GameLib.D3.API.Input.Editor = function (
|
||||||
containerHeightOffset = 80;
|
containerHeightOffset = 80;
|
||||||
}
|
}
|
||||||
this.containerHeightOffset = containerHeightOffset;
|
this.containerHeightOffset = containerHeightOffset;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(selectDelayMs)) {
|
||||||
|
selectDelayMs = 300;
|
||||||
|
}
|
||||||
|
this.selectDelayMs = selectDelayMs;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
@ -109,6 +116,7 @@ GameLib.D3.API.Input.Editor.FromObjectComponent = function(objectComponent) {
|
||||||
objectComponent.heightOffset,
|
objectComponent.heightOffset,
|
||||||
objectComponent.containerWidthOffset,
|
objectComponent.containerWidthOffset,
|
||||||
objectComponent.containerHeightOffset,
|
objectComponent.containerHeightOffset,
|
||||||
|
objectComponent.selectDelayMs,
|
||||||
objectComponent.parentEntity
|
objectComponent.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,26 +29,26 @@ GameLib.D3.Bone = function (
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.position,
|
||||||
this.position
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.quaternion = new GameLib.Quaternion(
|
this.quaternion = new GameLib.Quaternion(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.quaternion,
|
||||||
this.quaternion
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scale = new GameLib.Vector3(
|
this.scale = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.scale,
|
||||||
this.scale
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.up = new GameLib.Vector3(
|
this.up = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.up,
|
||||||
this.up
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
|
@ -41,20 +41,20 @@ GameLib.D3.Camera = function(
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.position,
|
||||||
this.position
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.quaternion = new GameLib.Quaternion(
|
this.quaternion = new GameLib.Quaternion(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.quaternion,
|
||||||
this.quaternion
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lookAt = new GameLib.Vector3(
|
this.lookAt = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.lookAt,
|
||||||
this.lookAt
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
|
@ -29,32 +29,32 @@ GameLib.D3.Follow = function (
|
||||||
|
|
||||||
this.targetPositionOffset = new GameLib.Vector3(
|
this.targetPositionOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.targetPositionOffset,
|
||||||
this.targetPositionOffset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.target = new GameLib.Vector3(
|
this.target = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.target,
|
||||||
this.target
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.targetToParent = new GameLib.Vector3(
|
this.targetToParent = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.targetToParent,
|
||||||
this.targetToParent
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.rotatedTargetOffset = new GameLib.Vector3(
|
this.rotatedTargetOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.rotatedTargetOffset,
|
||||||
this.rotatedTargetOffset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.rotated = new GameLib.Quaternion(
|
this.rotated = new GameLib.Quaternion(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.rotated,
|
||||||
this.rotated
|
this
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ GameLib.D3.Input.Editor = function (
|
||||||
apiInputEditor.heightOffset,
|
apiInputEditor.heightOffset,
|
||||||
apiInputEditor.containerWidthOffset,
|
apiInputEditor.containerWidthOffset,
|
||||||
apiInputEditor.containerHeightOffset,
|
apiInputEditor.containerHeightOffset,
|
||||||
|
apiInputEditor.selectDelayMs,
|
||||||
apiInputEditor.parentEntity
|
apiInputEditor.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -58,6 +59,10 @@ GameLib.D3.Input.Editor = function (
|
||||||
this.keyPress = this.onKeyPress.bind(this);
|
this.keyPress = this.onKeyPress.bind(this);
|
||||||
this.contextMenu = this.onContextMenu.bind(this);
|
this.contextMenu = this.onContextMenu.bind(this);
|
||||||
|
|
||||||
|
this.raycaster = new GameLib.D3.Raycaster(
|
||||||
|
this.graphics
|
||||||
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -145,6 +150,7 @@ GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
|
||||||
this.heightOffset,
|
this.heightOffset,
|
||||||
this.containerWidthOffset,
|
this.containerWidthOffset,
|
||||||
this.containerHeightOffset,
|
this.containerHeightOffset,
|
||||||
|
this.selectDelayMs,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -206,8 +212,9 @@ GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
|
||||||
|
|
||||||
this.editor.allSelected = !this.editor.allSelected;
|
this.editor.allSelected = !this.editor.allSelected;
|
||||||
|
|
||||||
if (this.editor.allSelected) {
|
this.editor.selectedObjects = [];
|
||||||
|
|
||||||
|
if (this.editor.allSelected) {
|
||||||
this.editor.games.map(
|
this.editor.games.map(
|
||||||
function(game) {
|
function(game) {
|
||||||
|
|
||||||
|
@ -224,13 +231,10 @@ GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
|
||||||
this.editor.selectedObjects = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.editor.onSelectionChange) {
|
if (this.editor.onSelectionChanged) {
|
||||||
this.editor.onSelectionChange(this.editor);
|
this.editor.onSelectionChanged(this.editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,20 +304,27 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
var meshInstances = [];
|
var meshCollections = this.editor.game.scenes.map(
|
||||||
|
function(scene) {
|
||||||
for (var m = 0; m < this.scene.meshes.length; m++) {
|
return scene.meshes;
|
||||||
meshInstances.push(this.scene.meshes[m].instance);
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
var intersects = this.scene.raycaster.instance.intersectObjects(meshInstances);
|
var meshes = meshCollections.reduce(
|
||||||
|
function(result, meshCollection) {
|
||||||
|
return result.concat(meshCollection);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
var intersects = this.raycaster.getIntersectedObjects(meshes);
|
||||||
|
|
||||||
if (intersects.length > 0) {
|
if (intersects.length > 0) {
|
||||||
|
|
||||||
var index = -1;
|
var index = -1;
|
||||||
|
|
||||||
for (var s = 0; s < this.selectedObjects.length; s++) {
|
for (var s = 0; s < this.editor.selectedObjects.length; s++) {
|
||||||
if (this.selectedObjects[s].object.instance == intersects[0].object) {
|
if (this.editor.selectedObjects[s].object == intersects[0]) {
|
||||||
index = s;
|
index = s;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -323,26 +334,21 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
|
||||||
/**
|
/**
|
||||||
* The object is not selected, select it
|
* The object is not selected, select it
|
||||||
*/
|
*/
|
||||||
this.selectObject(intersects[0].object.gameLibObject);
|
this.selectObject(intersects[0]);
|
||||||
|
|
||||||
this.buildSelectedObjects();
|
|
||||||
|
|
||||||
this.buildGUI();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* De-select the objec
|
* De-select the objec
|
||||||
*/
|
*/
|
||||||
var delta = Date.now() - this.selectedObjects[index].lastUpdate;
|
var delta = Date.now() - this.editor.selectedObjects[index].lastUpdate;
|
||||||
if (delta > 300) {
|
if (delta > this.selectDelayMs) {
|
||||||
|
this.unselectObject(intersects[0]);
|
||||||
this.unselectObject(intersects[0].object.gameLibObject);
|
|
||||||
|
|
||||||
this.buildSelectedObjects();
|
|
||||||
|
|
||||||
this.buildGUI();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.editor.onSelectionChanged) {
|
||||||
|
this.editor.onSelectionChanged(this.editor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -363,9 +369,10 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Input.Editor.prototype.onMouseMove = function(event) {
|
GameLib.D3.Input.Editor.prototype.onMouseMove = function(event) {
|
||||||
var clientX = event.clientX - 400;
|
|
||||||
|
|
||||||
this.scene.mouse.x = ((clientX/ (window.innerWidth - 400))) * 2 - 1;
|
var clientX = event.clientX - this.widthOffset;
|
||||||
|
|
||||||
|
this.scene.mouse.x = ((clientX / (window.innerWidth - this.widthOffset))) * 2 - 1;
|
||||||
this.scene.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
this.scene.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||||
|
|
||||||
this.scene.raycaster.instance.setFromCamera(
|
this.scene.raycaster.instance.setFromCamera(
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Light = function Light(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLight)) {
|
||||||
|
apiLight = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Light.call(
|
GameLib.D3.API.Light.call(
|
||||||
this,
|
this,
|
||||||
apiLight.id,
|
apiLight.id,
|
||||||
|
@ -33,33 +37,32 @@ GameLib.D3.Light = function Light(
|
||||||
|
|
||||||
this.color = new GameLib.Color(
|
this.color = new GameLib.Color(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
|
||||||
this.color,
|
this.color,
|
||||||
0.01
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.position,
|
||||||
this.position
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.targetPosition = new GameLib.Vector3(
|
this.targetPosition = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.targetPosition,
|
||||||
this.targetPosition
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scale = new GameLib.Vector3(
|
this.scale = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.scale,
|
||||||
this.scale
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.quaternion = new GameLib.Quaternion(
|
this.quaternion = new GameLib.Quaternion(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.quaternion,
|
||||||
this.quaternion
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
@ -92,21 +95,21 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
||||||
instance = new this.graphics.instance.AmbientLight(
|
instance = new THREE.AmbientLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||||
instance = new this.graphics.instance.DirectionalLight(
|
instance = new THREE.DirectionalLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||||||
instance = new this.graphics.instance.PointLight(
|
instance = new THREE.PointLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
|
@ -115,7 +118,7 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
||||||
instance = new this.graphics.instance.SpotLight(
|
instance = new THREE.SpotLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.LookAt = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiLookAt)) {
|
||||||
|
apiLookAt = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.LookAt.call(
|
GameLib.D3.API.LookAt.call(
|
||||||
this,
|
this,
|
||||||
apiLookAt.id,
|
apiLookAt.id,
|
||||||
|
@ -24,32 +28,32 @@ GameLib.D3.LookAt = function (
|
||||||
|
|
||||||
this.targetPositionOffset = new GameLib.Vector3(
|
this.targetPositionOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.targetPositionOffset,
|
||||||
this.targetPositionOffset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lookAtMatrix = new GameLib.Matrix4(
|
this.lookAtMatrix = new GameLib.Matrix4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.lookAtMatrix,
|
||||||
this.lookAtMatrix
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.up = new GameLib.Vector3(
|
this.up = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.up,
|
||||||
this.up
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.currentRotation = new GameLib.Quaternion(
|
this.currentRotation = new GameLib.Quaternion(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.currentRotation,
|
||||||
this.currentRotation
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.targetPosition = new GameLib.Vector3(
|
this.targetPosition = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.targetPosition,
|
||||||
this.targetPosition
|
this
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,15 @@ GameLib.D3.Material = function Material(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiMaterial)) {
|
||||||
|
apiMaterial = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||||
|
console.warn('Cannot create a material without specifying an ImageFactory');
|
||||||
|
throw new Error('Cannot create a material without specifying an ImageFactory');
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Material.call(
|
GameLib.D3.API.Material.call(
|
||||||
this,
|
this,
|
||||||
apiMaterial.id,
|
apiMaterial.id,
|
||||||
|
|
|
@ -15,6 +15,20 @@ GameLib.D3.Mesh = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
|
||||||
|
apiMesh = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(computeNormals)) {
|
||||||
|
computeNormals = true;
|
||||||
|
}
|
||||||
|
this.computeNormals = computeNormals;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||||
|
console.warn('Cannot create a mesh without specifying an ImageFactory');
|
||||||
|
throw new Error('Cannot create a mesh without specifying an ImageFactory');
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Mesh.call(
|
GameLib.D3.API.Mesh.call(
|
||||||
this,
|
this,
|
||||||
apiMesh.id,
|
apiMesh.id,
|
||||||
|
@ -43,11 +57,18 @@ GameLib.D3.Mesh = function (
|
||||||
|
|
||||||
this.materials = this.materials.map(
|
this.materials = this.materials.map(
|
||||||
function (apiMaterial) {
|
function (apiMaterial) {
|
||||||
|
|
||||||
|
if (apiMaterial instanceof GameLib.D3.API.Material) {
|
||||||
return new GameLib.D3.Material(
|
return new GameLib.D3.Material(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiMaterial,
|
apiMaterial,
|
||||||
imageFactory
|
imageFactory
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
console.warn('API material not of instance API.Material');
|
||||||
|
throw new Error('API material not of instance API.Material');
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -70,57 +91,52 @@ GameLib.D3.Mesh = function (
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
this.position,
|
this.position,
|
||||||
0.001
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scale = new GameLib.Vector3(
|
this.scale = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
this.scale,
|
this.scale,
|
||||||
0.001
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.up = new GameLib.Vector3(
|
this.up = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
this.up,
|
this.up,
|
||||||
0.001
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.quaternion = new GameLib.Quaternion(
|
this.quaternion = new GameLib.Quaternion(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.quaternion,
|
||||||
this.quaternion
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.localPosition = new GameLib.Vector3(
|
this.localPosition = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.localPosition,
|
||||||
this.localPosition
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.localRotation = new GameLib.Vector3(
|
this.localRotation = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.localRotation,
|
||||||
this.localRotation
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.localScale = new GameLib.Vector3(
|
this.localScale = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.localScale,
|
||||||
this.localScale
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.modelMatrix = new GameLib.Matrix4(
|
this.modelMatrix = new GameLib.Matrix4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.modelMatrix,
|
||||||
this.modelMatrix
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.computeNormals = computeNormals;
|
|
||||||
|
|
||||||
this.instance = this.createInstance(false);
|
this.instance = this.createInstance(false);
|
||||||
|
|
||||||
this.instance.geometry.computeBoundingBox();
|
this.instance.geometry.computeBoundingBox();
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Pass = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiPass)) {
|
||||||
|
apiPass = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Pass.call(
|
GameLib.D3.API.Pass.call(
|
||||||
this,
|
this,
|
||||||
apiPass.id,
|
apiPass.id,
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.PathFollowing = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiPathFollowing)) {
|
||||||
|
apiPathFollowing = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.PathFollowing.call(
|
GameLib.D3.API.PathFollowing.call(
|
||||||
this,
|
this,
|
||||||
apiPathFollowing.id,
|
apiPathFollowing.id,
|
||||||
|
@ -40,26 +44,26 @@ GameLib.D3.PathFollowing = function (
|
||||||
|
|
||||||
this.baseOffset = new GameLib.Vector3(
|
this.baseOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.baseOffset,
|
||||||
this.baseOffset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.maxOffset = new GameLib.Vector3(
|
this.maxOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.maxOffset,
|
||||||
this.maxOffset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.targetOffset = new GameLib.Vector3(
|
this.targetOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.targetOffset,
|
||||||
this.targetOffset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.currentOffset = new GameLib.Vector3(
|
this.currentOffset = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.currentOffset,
|
||||||
this.currentOffset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.raycaster = new GameLib.D3.Raycaster(
|
this.raycaster = new GameLib.D3.Raycaster(
|
||||||
|
@ -69,42 +73,38 @@ GameLib.D3.PathFollowing = function (
|
||||||
|
|
||||||
this.currentPosition = new GameLib.Vector3(
|
this.currentPosition = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.currentPosition,
|
||||||
this.currentPosition
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.futurePosition = new GameLib.Vector3(
|
this.futurePosition = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.futurePosition,
|
||||||
this.futurePosition
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.up = new GameLib.Vector3(
|
this.up = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.up,
|
||||||
this.up
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.rotationMatrix = new GameLib.Matrix4(
|
this.rotationMatrix = new GameLib.Matrix4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.rotationMatrix,
|
||||||
this.rotationMatrix
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.rotationVector = new GameLib.Quaternion(
|
this.rotationVector = new GameLib.Quaternion(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.rotationVector,
|
||||||
this.rotationVector
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
this.posx = new GameLib.Utils.MovingAverage(10);
|
|
||||||
this.posy = new GameLib.Utils.MovingAverage(10);
|
|
||||||
this.posz = new GameLib.Utils.MovingAverage(10);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
|
GameLib.D3.PathFollowing.prototype = Object.create(GameLib.D3.API.PathFollowing.prototype);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Raycaster for GameLib.D3
|
* Raycaster for GameLib.D3
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject
|
|
||||||
* @param apiRaycaster
|
* @param apiRaycaster
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -13,6 +12,10 @@ GameLib.D3.Raycaster = function(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiRaycaster)) {
|
||||||
|
apiRaycaster = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Raycaster.call(
|
GameLib.D3.API.Raycaster.call(
|
||||||
this,
|
this,
|
||||||
apiRaycaster.id,
|
apiRaycaster.id,
|
||||||
|
@ -23,14 +26,14 @@ GameLib.D3.Raycaster = function(
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.position,
|
||||||
this.position
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.direction = new GameLib.Vector3(
|
this.direction = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
this.direction,
|
||||||
this.direction
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
@ -61,6 +64,10 @@ GameLib.D3.Raycaster.prototype.createInstance = function(update) {
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Raycaster.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.D3.Raycaster.prototype.toApiRaycaster = function() {
|
GameLib.D3.Raycaster.prototype.toApiRaycaster = function() {
|
||||||
return new GameLib.D3.API.Raycaster(
|
return new GameLib.D3.API.Raycaster(
|
||||||
this.id,
|
this.id,
|
||||||
|
@ -76,7 +83,6 @@ GameLib.D3.Raycaster.FromObjectRaycaster = function(graphics, parentObject, obje
|
||||||
|
|
||||||
var raycaster = new GameLib.D3.Raycaster(
|
var raycaster = new GameLib.D3.Raycaster(
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiRaycaster
|
apiRaycaster
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -102,8 +108,6 @@ GameLib.D3.Raycaster.prototype.set = function(
|
||||||
|
|
||||||
this.position.updateInstance();
|
this.position.updateInstance();
|
||||||
this.direction.updateInstance();
|
this.direction.updateInstance();
|
||||||
|
|
||||||
this.createInstance(true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,8 +122,6 @@ GameLib.D3.Raycaster.prototype.setDirection = function(
|
||||||
this.direction.z = direction.z;
|
this.direction.z = direction.z;
|
||||||
|
|
||||||
this.direction.updateInstance();
|
this.direction.updateInstance();
|
||||||
|
|
||||||
this.createInstance(true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,10 +136,36 @@ GameLib.D3.Raycaster.prototype.setPosition = function(
|
||||||
this.position.z = position.z;
|
this.position.z = position.z;
|
||||||
|
|
||||||
this.position.updateInstance();
|
this.position.updateInstance();
|
||||||
|
|
||||||
this.createInstance(true);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all interesected GameLib.D3.Mesh objects
|
||||||
|
* @param meshes [GameLib.D3.Mesh]
|
||||||
|
*/
|
||||||
|
GameLib.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) {
|
||||||
|
|
||||||
|
var meshInstances = meshes.map(
|
||||||
|
function (mesh) {
|
||||||
|
return mesh.instance;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
var instanceIdToMesh = meshes.reduce(
|
||||||
|
function (result, mesh) {
|
||||||
|
result[mesh.instance.id] = mesh;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
var intersects = this.instance.intersectObjects(meshInstances);
|
||||||
|
|
||||||
|
return intersects.map(function (intersect) {
|
||||||
|
return instanceIdToMesh[intersect.object.id];
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the face normal (if any) of an intersection between current ray position, direction and a provided mesh
|
* Returns the face normal (if any) of an intersection between current ray position, direction and a provided mesh
|
||||||
* @param mesh GameLib.D3.Mesh
|
* @param mesh GameLib.D3.Mesh
|
||||||
|
@ -152,14 +180,15 @@ GameLib.D3.Raycaster.prototype.getFaceNormal = function(mesh) {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (intersect && intersect.length > 0) {
|
if (intersect && intersect.length > 0) {
|
||||||
|
|
||||||
normal = new GameLib.Vector3(
|
normal = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
new GameLib.API.Vector3(
|
new GameLib.API.Vector3(
|
||||||
intersect[0].face.normal.x,
|
intersect[0].face.normal.x,
|
||||||
intersect[0].face.normal.y,
|
intersect[0].face.normal.y,
|
||||||
intersect[0].face.normal.z
|
intersect[0].face.normal.z
|
||||||
)
|
),
|
||||||
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,12 +211,12 @@ GameLib.D3.Raycaster.prototype.getIntersectPoint = function(mesh) {
|
||||||
if (intersect && intersect.length > 0) {
|
if (intersect && intersect.length > 0) {
|
||||||
point = new GameLib.Vector3(
|
point = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
new GameLib.API.Vector3(
|
new GameLib.API.Vector3(
|
||||||
intersect[0].point.x,
|
intersect[0].point.x,
|
||||||
intersect[0].point.y,
|
intersect[0].point.y,
|
||||||
intersect[0].point.z
|
intersect[0].point.z
|
||||||
)
|
),
|
||||||
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.RenderTarget = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiRenderTarget)) {
|
||||||
|
apiRenderTarget = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.RenderTarget.call(
|
GameLib.D3.API.RenderTarget.call(
|
||||||
this,
|
this,
|
||||||
apiRenderTarget.id,
|
apiRenderTarget.id,
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Renderer = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiRenderer)) {
|
||||||
|
apiRenderer = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Renderer.call(
|
GameLib.D3.API.Renderer.call(
|
||||||
this,
|
this,
|
||||||
apiRenderer.id,
|
apiRenderer.id,
|
||||||
|
|
|
@ -16,6 +16,23 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiScene)) {
|
||||||
|
apiScene = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||||
|
imageFactory = GameLib.D3.ImageFactory(
|
||||||
|
this.graphics,
|
||||||
|
this.baseUrl
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.imageFactory = imageFactory;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(computeNormals)) {
|
||||||
|
computeNormals = true;
|
||||||
|
}
|
||||||
|
this.computeNormals = computeNormals;
|
||||||
|
|
||||||
GameLib.D3.API.Scene.call(
|
GameLib.D3.API.Scene.call(
|
||||||
this,
|
this,
|
||||||
apiScene.id,
|
apiScene.id,
|
||||||
|
@ -33,14 +50,6 @@ GameLib.D3.Scene = function Scene(
|
||||||
apiScene.parentEntity
|
apiScene.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
|
||||||
imageFactory = GameLib.D3.ImageFactory(
|
|
||||||
this.graphics,
|
|
||||||
this.baseUrl
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.imageFactory = imageFactory;
|
|
||||||
|
|
||||||
this.idToObject = {};
|
this.idToObject = {};
|
||||||
|
|
||||||
this.meshes = this.meshes.map(
|
this.meshes = this.meshes.map(
|
||||||
|
@ -49,7 +58,7 @@ GameLib.D3.Scene = function Scene(
|
||||||
var mesh = new GameLib.D3.Mesh(
|
var mesh = new GameLib.D3.Mesh(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiMesh,
|
apiMesh,
|
||||||
computeNormals,
|
this.computeNormals,
|
||||||
imageFactory
|
imageFactory
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -72,25 +81,27 @@ GameLib.D3.Scene = function Scene(
|
||||||
);
|
);
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
this.graphics,
|
||||||
this,
|
this.position,
|
||||||
this.position
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.quaternion = new GameLib.Quaternion(
|
this.quaternion = new GameLib.Quaternion(
|
||||||
graphics,
|
this.graphics,
|
||||||
this,
|
this.quaternion,
|
||||||
this.quaternion
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.scale = new GameLib.Vector3(
|
this.scale = new GameLib.Vector3(
|
||||||
graphics,
|
this.graphics,
|
||||||
this,
|
this.scale,
|
||||||
this.scale
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.lights = this.lights.map(
|
this.lights = this.lights.map(
|
||||||
function(apiLight) {
|
function(apiLight) {
|
||||||
|
|
||||||
|
if (apiLight instanceof GameLib.D3.API.Light) {
|
||||||
var light = new GameLib.D3.Light(
|
var light = new GameLib.D3.Light(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiLight
|
apiLight
|
||||||
|
@ -99,11 +110,16 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.idToObject[light.id] = light;
|
this.idToObject[light.id] = light;
|
||||||
|
|
||||||
return light;
|
return light;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.materials = this.materials.map(
|
this.materials = this.materials.map(
|
||||||
function(apiMaterial) {
|
function(apiMaterial) {
|
||||||
|
if (apiMaterial instanceof GameLib.D3.API.Material) {
|
||||||
var material = new GameLib.D3.Material(
|
var material = new GameLib.D3.Material(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiMaterial,
|
apiMaterial,
|
||||||
|
@ -113,12 +129,17 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.idToObject[material.id] = material;
|
this.idToObject[material.id] = material;
|
||||||
|
|
||||||
return material;
|
return material;
|
||||||
|
} else {
|
||||||
|
console.warn('apiMaterial not an instance of API.Material');
|
||||||
|
throw new Error('apiMaterial not an instance of API.Material');
|
||||||
|
}
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.textures = this.textures.map(
|
this.textures = this.textures.map(
|
||||||
function(apiTexture) {
|
function(apiTexture) {
|
||||||
|
if (apiTexture instanceof GameLib.D3.API.Texture) {
|
||||||
var texture = new GameLib.D3.Texture(
|
var texture = new GameLib.D3.Texture(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiTexture,
|
apiTexture,
|
||||||
|
@ -128,6 +149,10 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.idToObject[texture.id] = texture;
|
this.idToObject[texture.id] = texture;
|
||||||
|
|
||||||
return texture;
|
return texture;
|
||||||
|
} else {
|
||||||
|
console.warn('apiTexture not an instance of API.Texture');
|
||||||
|
throw new Error('apiTexture not an instance of API.Texture');
|
||||||
|
}
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Skeleton = function Skeleton(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSkeleton)) {
|
||||||
|
apiSkeleton = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Skeleton.call(
|
GameLib.D3.API.Skeleton.call(
|
||||||
this,
|
this,
|
||||||
apiSkeleton.id,
|
apiSkeleton.id,
|
||||||
|
@ -26,31 +30,51 @@ GameLib.D3.Skeleton = function Skeleton(
|
||||||
|
|
||||||
this.bones = this.bones.map(
|
this.bones = this.bones.map(
|
||||||
function(apiBone) {
|
function(apiBone) {
|
||||||
|
|
||||||
|
if (apiBone instanceof GameLib.D3.API.Bone) {
|
||||||
return new GameLib.D3.Bone(
|
return new GameLib.D3.Bone(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiBone
|
apiBone
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
console.warn('apiBone not an instance of API.Bone');
|
||||||
|
throw new Error('apiBone not an instance of API.Bone');
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.boneInverses = this.boneInverses.map(
|
this.boneInverses = this.boneInverses.map(
|
||||||
function(boneInverse) {
|
function(boneInverse) {
|
||||||
|
|
||||||
|
if (boneInverse instanceof GameLib.API.Matrix4) {
|
||||||
return new GameLib.Matrix4(
|
return new GameLib.Matrix4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
boneInverse,
|
||||||
boneInverse
|
this
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
console.warn('boneInverse not an instance of API.Matrix4');
|
||||||
|
throw new Error('boneInverse not an instance of API.Matrix4');
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.boneMatrices = this.boneMatrices.map(
|
this.boneMatrices = this.boneMatrices.map(
|
||||||
function(boneMatrices) {
|
function(boneMatrices) {
|
||||||
|
if (boneMatrices instanceof GameLib.API.Matrix4) {
|
||||||
return new GameLib.Matrix4(
|
return new GameLib.Matrix4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
boneMatrices,
|
||||||
boneMatrices
|
this
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
console.warn('boneMatrices not an instance of API.Matrix4');
|
||||||
|
throw new Error('boneMatrices not an instance of API.Matrix4');
|
||||||
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Spline = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSpline)) {
|
||||||
|
apiSpline = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Spline.call(
|
GameLib.D3.API.Spline.call(
|
||||||
this,
|
this,
|
||||||
apiSpline.id,
|
apiSpline.id,
|
||||||
|
@ -23,8 +27,8 @@ GameLib.D3.Spline = function (
|
||||||
function (vertex) {
|
function (vertex) {
|
||||||
return new GameLib.Vector3(
|
return new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
vertex,
|
||||||
vertex
|
this
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -108,8 +112,8 @@ GameLib.D3.Spline.prototype.getPointAt = function(proper) {
|
||||||
var point = this.instance.getPointAt(proper);
|
var point = this.instance.getPointAt(proper);
|
||||||
return new GameLib.Vector3(
|
return new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
new GameLib.API.Vector3(point.x, point.y, point.z),
|
new GameLib.API.Vector3(point.x, point.y, point.z),
|
||||||
|
this,
|
||||||
0.1
|
0.1
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,15 @@ GameLib.D3.Texture = function Texture(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiTexture)) {
|
||||||
|
apiTexture = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||||
|
console.warn('Cannot create a material without specifying an ImageFactory');
|
||||||
|
throw new Error('Cannot create a material without specifying an ImageFactory');
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Texture.call(
|
GameLib.D3.API.Texture.call(
|
||||||
this,
|
this,
|
||||||
apiTexture.id,
|
apiTexture.id,
|
||||||
|
@ -43,14 +52,14 @@ GameLib.D3.Texture = function Texture(
|
||||||
|
|
||||||
this.offset = new GameLib.Vector2(
|
this.offset = new GameLib.Vector2(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.offset,
|
||||||
this.offset
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.repeat = new GameLib.Vector2(
|
this.repeat = new GameLib.Vector2(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this.repeat,
|
||||||
this.repeat
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
// this.parentMaterial = parentMaterial;
|
// this.parentMaterial = parentMaterial;
|
||||||
|
|
|
@ -11,6 +11,10 @@ GameLib.D3.Vertex = function Vertex(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiVertex)) {
|
||||||
|
apiVertex = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Vertex.call(
|
GameLib.D3.API.Vertex.call(
|
||||||
this,
|
this,
|
||||||
apiVertex.position,
|
apiVertex.position,
|
||||||
|
@ -19,8 +23,8 @@ GameLib.D3.Vertex = function Vertex(
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
null,
|
this.position,
|
||||||
this.position
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
this.boneWeights = this.boneWeights.map(
|
this.boneWeights = this.boneWeights.map(
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.D3.Viewport = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiViewport)) {
|
||||||
|
apiViewport = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.API.Viewport.call(
|
GameLib.D3.API.Viewport.call(
|
||||||
this,
|
this,
|
||||||
apiViewport.id,
|
apiViewport.id,
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.EntityManager = function(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiEntityManager)) {
|
||||||
|
apiEntityManager = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.API.EntityManager.call(
|
GameLib.API.EntityManager.call(
|
||||||
this,
|
this,
|
||||||
apiEntityManager.entities
|
apiEntityManager.entities
|
||||||
|
|
|
@ -12,6 +12,10 @@ GameLib.Entity = function (
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiEntity)) {
|
||||||
|
apiEntity = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.API.Entity.call(
|
GameLib.API.Entity.call(
|
||||||
this,
|
this,
|
||||||
apiEntity.id,
|
apiEntity.id,
|
||||||
|
|
|
@ -8,11 +8,18 @@
|
||||||
*/
|
*/
|
||||||
GameLib.Matrix4 = function(
|
GameLib.Matrix4 = function(
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiMatrix4,
|
apiMatrix4,
|
||||||
|
parentObject,
|
||||||
grain
|
grain
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiMatrix4)) {
|
||||||
|
apiMatrix4 = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.API.Matrix4.call(
|
GameLib.API.Matrix4.call(
|
||||||
this,
|
this,
|
||||||
apiMatrix4.rows[0],
|
apiMatrix4.rows[0],
|
||||||
|
@ -21,10 +28,9 @@ GameLib.Matrix4 = function(
|
||||||
apiMatrix4.rows[3]
|
apiMatrix4.rows[3]
|
||||||
);
|
);
|
||||||
|
|
||||||
this.graphics = graphics;
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
this.graphics.isNotThreeThrow();
|
}
|
||||||
|
|
||||||
this.parentObject = parentObject;
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||||
|
@ -32,53 +38,41 @@ GameLib.Matrix4 = function(
|
||||||
}
|
}
|
||||||
this.grain = grain;
|
this.grain = grain;
|
||||||
|
|
||||||
this.rows[0] = new GameLib.Vector4(
|
this.rows = this.rows.map(
|
||||||
|
function(row) {
|
||||||
|
if (row instanceof GameLib.API.Vector4) {
|
||||||
|
return new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
|
row,
|
||||||
this,
|
this,
|
||||||
this.rows[0],
|
this.grain
|
||||||
grain
|
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
this.rows[1] = new GameLib.Vector4(
|
console.warn('Attempted conversion of wrong instance');
|
||||||
this.graphics,
|
throw new Error('Attempted conversion of wrong instance');
|
||||||
this,
|
}
|
||||||
this.rows[1],
|
}.bind(this)
|
||||||
grain
|
|
||||||
);
|
|
||||||
|
|
||||||
this.rows[2] = new GameLib.Vector4(
|
|
||||||
this.graphics,
|
|
||||||
this,
|
|
||||||
this.rows[2],
|
|
||||||
grain
|
|
||||||
);
|
|
||||||
|
|
||||||
this.rows[3] = new GameLib.Vector4(
|
|
||||||
this.graphics,
|
|
||||||
this,
|
|
||||||
this.rows[3],
|
|
||||||
grain
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.forward = new GameLib.Vector4(
|
this.forward = new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
this.forward,
|
this.forward,
|
||||||
grain
|
this,
|
||||||
|
this.grain
|
||||||
);
|
);
|
||||||
|
|
||||||
this.left = new GameLib.Vector4(
|
this.left = new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
this.left,
|
this.left,
|
||||||
grain
|
this,
|
||||||
|
this.grain
|
||||||
);
|
);
|
||||||
|
|
||||||
this.up = new GameLib.Vector4(
|
this.up = new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
this.up,
|
this.up,
|
||||||
grain
|
this,
|
||||||
|
this.grain
|
||||||
);
|
);
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
@ -136,11 +130,10 @@ GameLib.Matrix4.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
if (this.parentObject) {
|
if (this.parentObject &&
|
||||||
if (this.parentObject.updateInstance) {
|
this.parentObject.updateInstance) {
|
||||||
this.parentObject.updateInstance();
|
this.parentObject.updateInstance();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,12 +141,18 @@ GameLib.Matrix4.prototype.updateInstance = function() {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.Matrix4.prototype.toApiMatrix = function () {
|
GameLib.Matrix4.prototype.toApiMatrix = function () {
|
||||||
return new GameLib.API.Matrix4(
|
|
||||||
this.rows[0].toApiVector(),
|
return this.rows.map(
|
||||||
this.rows[1].toApiVector(),
|
function(row) {
|
||||||
this.rows[2].toApiVector(),
|
if (row instanceof GameLib.Vector4) {
|
||||||
this.rows[3].toApiVector()
|
return row.toApiVector();
|
||||||
)
|
} else {
|
||||||
|
console.warn('Incompatible conversion to API matrix for vector: ', row);
|
||||||
|
throw new Error('Incompatible conversion to API matrix for a vector');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,40 +165,7 @@ GameLib.Matrix4.prototype.toApiMatrix = function () {
|
||||||
*/
|
*/
|
||||||
GameLib.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject) {
|
GameLib.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(objectMatrix)) {
|
var apiMatrix = new GameLib.API.Matrix4.FromObjectMatrix(objectMatrix);
|
||||||
return new GameLib.Matrix4(
|
|
||||||
graphics,
|
|
||||||
parentObject,
|
|
||||||
new GameLib.API.Matrix4()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var apiMatrix = new GameLib.API.Matrix4(
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[0].x,
|
|
||||||
objectMatrix.rows[0].y,
|
|
||||||
objectMatrix.rows[0].z,
|
|
||||||
objectMatrix.rows[0].w
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[1].x,
|
|
||||||
objectMatrix.rows[1].y,
|
|
||||||
objectMatrix.rows[1].z,
|
|
||||||
objectMatrix.rows[1].w
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[2].x,
|
|
||||||
objectMatrix.rows[2].y,
|
|
||||||
objectMatrix.rows[2].z,
|
|
||||||
objectMatrix.rows[2].w
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector4(
|
|
||||||
objectMatrix.rows[3].x,
|
|
||||||
objectMatrix.rows[3].y,
|
|
||||||
objectMatrix.rows[3].z,
|
|
||||||
objectMatrix.rows[3].w
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.Matrix4(
|
return new GameLib.Matrix4(
|
||||||
graphics,
|
graphics,
|
||||||
|
@ -208,6 +174,13 @@ GameLib.Matrix4.FromObjectMatrix = function(graphics, objectMatrix, parentObject
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookat
|
||||||
|
* @param position
|
||||||
|
* @param target
|
||||||
|
* @param up
|
||||||
|
* @returns {GameLib.Matrix4}
|
||||||
|
*/
|
||||||
GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
|
GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
|
||||||
|
|
||||||
var pv = new GameLib.API.Vector3(position.x, position.y, position.z);
|
var pv = new GameLib.API.Vector3(position.x, position.y, position.z);
|
||||||
|
@ -256,35 +229,42 @@ GameLib.Matrix4.prototype.lookAt = function (position, target, up) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identity
|
||||||
|
*/
|
||||||
GameLib.Matrix4.prototype.identity = function () {
|
GameLib.Matrix4.prototype.identity = function () {
|
||||||
this.rows = [
|
this.rows = [
|
||||||
new GameLib.Vector4(
|
new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
new GameLib.API.Vector4(1,0,0,0),
|
new GameLib.API.Vector4(1,0,0,0),
|
||||||
|
this,
|
||||||
this.grain
|
this.grain
|
||||||
),
|
),
|
||||||
new GameLib.Vector4(
|
new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
new GameLib.API.Vector4(0,1,0,0),
|
new GameLib.API.Vector4(0,1,0,0),
|
||||||
|
this,
|
||||||
this.grain
|
this.grain
|
||||||
),
|
),
|
||||||
new GameLib.Vector4(
|
new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
new GameLib.API.Vector4(0,0,1,0),
|
new GameLib.API.Vector4(0,0,1,0),
|
||||||
|
this,
|
||||||
this.grain
|
this.grain
|
||||||
),
|
),
|
||||||
new GameLib.Vector4(
|
new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this,
|
|
||||||
new GameLib.API.Vector4(0,0,0,1),
|
new GameLib.API.Vector4(0,0,0,1),
|
||||||
|
this,
|
||||||
this.grain
|
this.grain
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transpose
|
||||||
|
* @returns {GameLib.Matrix4}
|
||||||
|
*/
|
||||||
GameLib.Matrix4.prototype.transpose = function () {
|
GameLib.Matrix4.prototype.transpose = function () {
|
||||||
|
|
||||||
this.temp[0].x = this.rows[0].x;
|
this.temp[0].x = this.rows[0].x;
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
/**
|
/**
|
||||||
* Runtime mouse for updating instance objects
|
* Runtime mouse for updating instance objects
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject GameLib.D3.*
|
|
||||||
* @param apiMouse GameLib.API.Mouse
|
* @param apiMouse GameLib.API.Mouse
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Mouse = function (graphics, parentObject, apiMouse) {
|
GameLib.Mouse = function (graphics, apiMouse) {
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GameLib.API.Mouse.call(
|
GameLib.API.Mouse.call(
|
||||||
this,
|
this,
|
||||||
apiMouse.id,
|
apiMouse.id,
|
||||||
|
|
|
@ -8,39 +8,39 @@
|
||||||
*/
|
*/
|
||||||
GameLib.Quaternion = function (
|
GameLib.Quaternion = function (
|
||||||
graphics,
|
graphics,
|
||||||
parentObject,
|
|
||||||
apiQuaternion,
|
apiQuaternion,
|
||||||
|
parentObject,
|
||||||
grain
|
grain
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiQuaternion)) {
|
||||||
|
apiQuaternion = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.API.Quaternion.call(
|
GameLib.API.Quaternion.call(
|
||||||
this,
|
this,
|
||||||
apiQuaternion.x,
|
apiQuaternion.x,
|
||||||
apiQuaternion.y,
|
apiQuaternion.y,
|
||||||
apiQuaternion.z,
|
apiQuaternion.z,
|
||||||
apiQuaternion.w,
|
apiQuaternion.w,
|
||||||
new GameLib.API.Vector3(
|
apiQuaternion.axis,
|
||||||
apiQuaternion.axis.x,
|
|
||||||
apiQuaternion.axis.y,
|
|
||||||
apiQuaternion.axis.z
|
|
||||||
),
|
|
||||||
apiQuaternion.angle
|
apiQuaternion.angle
|
||||||
);
|
);
|
||||||
|
|
||||||
this.axis = new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
this,
|
|
||||||
this.axis,
|
|
||||||
0.001
|
|
||||||
);
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
parentObject = null;
|
parentObject = null;
|
||||||
}
|
}
|
||||||
this.parentObject = parentObject;
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
|
this.axis = new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
this.axis,
|
||||||
|
this,
|
||||||
|
this.grain
|
||||||
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||||
grain = 0.001;
|
grain = 0.001;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,12 @@ GameLib.Quaternion.prototype.createInstance = function(update) {
|
||||||
instance.z = this.z;
|
instance.z = this.z;
|
||||||
instance.w = this.w;
|
instance.w = this.w;
|
||||||
} else {
|
} else {
|
||||||
instance = new THREE.Quaternion(this.x, this.y, this.z, this.w);
|
instance = new THREE.Quaternion(
|
||||||
|
this.x,
|
||||||
|
this.y,
|
||||||
|
this.z,
|
||||||
|
this.w
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -81,7 +86,8 @@ GameLib.Quaternion.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
if (this.parentObject.updateInstance) {
|
if (this.parentObject &&
|
||||||
|
this.parentObject.updateInstance) {
|
||||||
this.parentObject.updateInstance();
|
this.parentObject.updateInstance();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,20 +6,28 @@
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Vector2 = function (graphics, parentObject, apiVector2, grain) {
|
GameLib.Vector2 = function (
|
||||||
|
graphics,
|
||||||
for (var property in apiVector2) {
|
apiVector2,
|
||||||
if (apiVector2.hasOwnProperty(property)) {
|
parentObject,
|
||||||
this[property] = apiVector2[property];
|
grain
|
||||||
}
|
) {
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.Utils.Extend(GameLib.Vector2, GameLib.API.Vector2);
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiVector2)) {
|
||||||
|
apiVector2 = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.Vector2.call(
|
||||||
|
this,
|
||||||
|
apiVector2.x,
|
||||||
|
apiVector2.y
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
|
}
|
||||||
this.parentObject = parentObject;
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||||
|
@ -30,6 +38,10 @@ GameLib.Vector2 = function (graphics, parentObject, apiVector2, grain) {
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.Vector2.prototype = Object.create(GameLib.API.Vector2.prototype);
|
||||||
|
GameLib.Vector2.prototype.constructor = GameLib.Vector2;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance vector2
|
* Creates an instance vector2
|
||||||
* @param update
|
* @param update
|
||||||
|
@ -44,7 +56,7 @@ GameLib.Vector2.prototype.createInstance = function(update) {
|
||||||
instance.x = this.x;
|
instance.x = this.x;
|
||||||
instance.y = this.y;
|
instance.y = this.y;
|
||||||
} else {
|
} else {
|
||||||
instance = new this.graphics.instance.Vector2(this.x, this.y);
|
instance = new THREE.Vector2(this.x, this.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -57,7 +69,8 @@ GameLib.Vector2.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
if (this.parentObject.updateInstance) {
|
if (this.parentObject &&
|
||||||
|
this.parentObject.updateInstance) {
|
||||||
this.parentObject.updateInstance();
|
this.parentObject.updateInstance();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -73,99 +86,209 @@ GameLib.Vector2.prototype.toApiVector = function() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy
|
||||||
|
* TODO: Test
|
||||||
|
* @param v optional
|
||||||
|
* @returns {GameLib.Vector2}
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.copy = function (v) {
|
GameLib.Vector2.prototype.copy = function (v) {
|
||||||
if (!GameLib.Utils.UndefinedOrNull(v)) {
|
|
||||||
this.x = v.x;
|
if (GameLib.Utils.UndefinedOrNull(v)) {
|
||||||
this.y = v.y;
|
|
||||||
return this;
|
|
||||||
} else {
|
|
||||||
return new GameLib.Vector2(
|
return new GameLib.Vector2(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Vector2(
|
||||||
this.x,
|
this.x,
|
||||||
this.y
|
this.y
|
||||||
|
),
|
||||||
|
this.parentObject,
|
||||||
|
this.grain
|
||||||
);
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
this.x = v.x;
|
||||||
|
this.y = v.y;
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Equals
|
||||||
|
* TODO: Test
|
||||||
|
* @param v
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.equals = function(v) {
|
GameLib.Vector2.prototype.equals = function(v) {
|
||||||
return (((this.x == v.x) &&
|
|
||||||
(this.y == v.y)) ||
|
if ((this.x == v.x) &&
|
||||||
((this.y == v.x) &&
|
(this.y == v.y)) {
|
||||||
(this.x == v.y)));
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add
|
||||||
|
* TODO: Test
|
||||||
|
* @param v
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.add = function(v) {
|
GameLib.Vector2.prototype.add = function(v) {
|
||||||
return new GameLib.Vector2(
|
|
||||||
this.x + v.x,
|
if (
|
||||||
this.y + v.y
|
v instanceof GameLib.API.Vector2 ||
|
||||||
);
|
v instanceof GameLib.API.Vector3 ||
|
||||||
|
v instanceof GameLib.API.Vector4 ||
|
||||||
|
v instanceof GameLib.API.Quaternion
|
||||||
|
) {
|
||||||
|
this.x += v.x;
|
||||||
|
this.y += v.y;
|
||||||
|
} else {
|
||||||
|
console.warn('Could not add Vector2');
|
||||||
|
throw new Error('Could not add Vector2');
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subtract
|
||||||
|
* TODO: Test
|
||||||
|
* @param v
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.subtract = function(v) {
|
GameLib.Vector2.prototype.subtract = function(v) {
|
||||||
return new GameLib.Vector2(
|
|
||||||
this.x - v.x,
|
if (
|
||||||
this.y - v.y
|
v instanceof GameLib.API.Vector2 ||
|
||||||
);
|
v instanceof GameLib.API.Vector3 ||
|
||||||
|
v instanceof GameLib.API.Vector4 ||
|
||||||
|
v instanceof GameLib.API.Quaternion
|
||||||
|
) {
|
||||||
|
this.x -= v.x;
|
||||||
|
this.y -= v.y;
|
||||||
|
} else {
|
||||||
|
console.warn('Could not subtract Vector2');
|
||||||
|
throw new Error('Could not subtract Vector2');
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiply
|
||||||
|
* TODO: Test
|
||||||
|
* @param v
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.multiply = function(v) {
|
GameLib.Vector2.prototype.multiply = function(v) {
|
||||||
if (v instanceof GameLib.Vector2) {
|
|
||||||
return new GameLib.Vector2(
|
if (
|
||||||
this.x * v.x,
|
v instanceof GameLib.API.Vector2 ||
|
||||||
this.y * v.y
|
v instanceof GameLib.API.Vector3 ||
|
||||||
);
|
v instanceof GameLib.API.Vector4 ||
|
||||||
} else if (isNumber(v)) {
|
v instanceof GameLib.API.Quaternion
|
||||||
return new GameLib.Vector2(
|
) {
|
||||||
this.x * v,
|
this.x *= v.x;
|
||||||
this.y * v
|
this.y *= v.y;
|
||||||
);
|
} else if (typeof v == 'number') {
|
||||||
|
this.x *= v;
|
||||||
|
this.y *= v;
|
||||||
|
} else {
|
||||||
|
console.warn('Could not multiply Vector2');
|
||||||
|
throw new Error('Could not multiply Vector2');
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Divide
|
||||||
|
* TODO: Test
|
||||||
|
* @param v
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.divide = function(v) {
|
GameLib.Vector2.prototype.divide = function(v) {
|
||||||
if (v instanceof GameLib.Vector2) {
|
|
||||||
return new GameLib.Vector2(
|
if (
|
||||||
this.x * (1.0 / v.x),
|
v instanceof GameLib.API.Vector2 ||
|
||||||
this.y * (1.0 / v.y)
|
v instanceof GameLib.API.Vector3 ||
|
||||||
);
|
v instanceof GameLib.API.Vector4 ||
|
||||||
} else if (isNumber(v)) {
|
v instanceof GameLib.API.Quaternion
|
||||||
var invS = 1.0 / v;
|
) {
|
||||||
return new GameLib.Vector2(
|
this.x *= (1.0 / v.x);
|
||||||
this.x * invS,
|
this.y *= (1.0 / v.y);
|
||||||
this.y * invS
|
} else if (typeof v == 'number') {
|
||||||
);
|
this.x *= 1.0 / v;
|
||||||
|
this.y *= 1.0 / v;
|
||||||
|
} else {
|
||||||
|
console.warn('Could not divide Vector2');
|
||||||
|
throw new Error('Could not divide Vector2');
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Vector2.prototype.set = function(x, y) {
|
/**
|
||||||
this.x = x;
|
* Clamp
|
||||||
this.y = y;
|
* TODO: Test
|
||||||
};
|
* @param min GameLib.API.Vector2
|
||||||
|
* @param max GameLib.API.Vector2
|
||||||
|
* @returns {GameLib.Vector2}
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.clamp = function(min, max) {
|
GameLib.Vector2.prototype.clamp = function(min, max) {
|
||||||
return new GameLib.Vector2(
|
|
||||||
Math.max(min.x, Math.min(max.x, this.x)),
|
this.x = Math.max(min.x, Math.min(max.x, this.x));
|
||||||
Math.max(min.y, Math.min(max.y, this.y))
|
this.y = Math.max(min.y, Math.min(max.y, this.y));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Length
|
||||||
|
* TODO: Test
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
GameLib.Vector2.prototype.length = function() {
|
||||||
|
return Math.sqrt(
|
||||||
|
this.x * this.x + this.y * this.y
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Vector2.prototype.length = function() {
|
/**
|
||||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
* Dot product
|
||||||
};
|
* TODO: Test
|
||||||
|
* @param v
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.dot = function(v) {
|
GameLib.Vector2.prototype.dot = function(v) {
|
||||||
return this.x * v.x + this.y * v.y;
|
return this.x * v.x + this.y * v.y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize
|
||||||
|
* TODO: Test
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.normalize = function() {
|
GameLib.Vector2.prototype.normalize = function() {
|
||||||
return this.multiply(1.0 / this.length());
|
return this.multiply(1.0 / this.length());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Test
|
||||||
|
* Angle between this vector and origin
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.angle = function() {
|
GameLib.Vector2.prototype.angle = function() {
|
||||||
var angle = Math.atan2(this.y, this.x);
|
var angle = Math.atan2(this.y, this.x);
|
||||||
if ( angle < 0 ) angle += 2 * Math.PI;
|
if ( angle < 0 ) angle += 2 * Math.PI;
|
||||||
return angle;
|
return angle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interpolate to v from here
|
||||||
|
* TODO: Test
|
||||||
|
* @param v
|
||||||
|
* @param alpha
|
||||||
|
* @returns {GameLib.Vector2}
|
||||||
|
*/
|
||||||
GameLib.Vector2.prototype.lerp = function ( v, alpha ) {
|
GameLib.Vector2.prototype.lerp = function ( v, alpha ) {
|
||||||
return new GameLib.Vector2(
|
return new GameLib.Vector2(
|
||||||
this.x + ( v.x - this.x ) * alpha,
|
this.x + ( v.x - this.x ) * alpha,
|
||||||
|
|
|
@ -1,25 +1,34 @@
|
||||||
/**
|
/**
|
||||||
* Runtime apiVector3 for updating instance objects
|
* Runtime apiVector3 for updating instance objects
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject GameLib.D3.*
|
|
||||||
* @param apiVector3 GameLib.API.Vector3
|
* @param apiVector3 GameLib.API.Vector3
|
||||||
|
* @param parentObject GameLib.*
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Vector3 = function (graphics, parentObject, apiVector3, grain) {
|
GameLib.Vector3 = function (
|
||||||
|
graphics,
|
||||||
for (var property in apiVector3) {
|
apiVector3,
|
||||||
if (apiVector3.hasOwnProperty(property)) {
|
parentObject,
|
||||||
this[property] = apiVector3[property];
|
grain
|
||||||
}
|
) {
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.Utils.Extend(GameLib.Vector3, GameLib.API.Vector3);
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiVector3)) {
|
||||||
|
apiVector3 = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.Vector3.call(
|
||||||
|
this,
|
||||||
|
apiVector3.x,
|
||||||
|
apiVector3.y,
|
||||||
|
apiVector3.z
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
|
}
|
||||||
this.parentObject = parentObject;
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||||
|
@ -30,6 +39,9 @@ GameLib.Vector3 = function (graphics, parentObject, apiVector3, grain) {
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.Vector3.prototype = Object.create(GameLib.API.Vector3.prototype);
|
||||||
|
GameLib.Vector3.prototype.constructor = GameLib.Vector3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance vector3
|
* Creates an instance vector3
|
||||||
* @param update
|
* @param update
|
||||||
|
@ -45,7 +57,11 @@ GameLib.Vector3.prototype.createInstance = function(update) {
|
||||||
instance.y = this.y;
|
instance.y = this.y;
|
||||||
instance.z = this.z;
|
instance.z = this.z;
|
||||||
} else {
|
} else {
|
||||||
instance = new THREE.Vector3(this.x, this.y, this.z);
|
instance = new THREE.Vector3(
|
||||||
|
this.x,
|
||||||
|
this.y,
|
||||||
|
this.z
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -58,7 +74,8 @@ GameLib.Vector3.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
if (this.parentObject.updateInstance) {
|
if (this.parentObject &&
|
||||||
|
this.parentObject.updateInstance) {
|
||||||
this.parentObject.updateInstance();
|
this.parentObject.updateInstance();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -75,17 +92,17 @@ GameLib.Vector3.prototype.toApiVector = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts runtime vector to API Vector
|
* Creates a new copy of this Vector3
|
||||||
*/
|
*/
|
||||||
GameLib.Vector3.prototype.copy = function() {
|
GameLib.Vector3.prototype.copy = function() {
|
||||||
return new GameLib.Vector3(
|
return new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this.parentObject,
|
|
||||||
new GameLib.API.Vector3(
|
new GameLib.API.Vector3(
|
||||||
this.x,
|
this.x,
|
||||||
this.y,
|
this.y,
|
||||||
this.z
|
this.z
|
||||||
),
|
),
|
||||||
|
this.parentObject,
|
||||||
this.grain
|
this.grain
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
/**
|
/**
|
||||||
* Runtime apiVector4 for updating instance objects
|
* Runtime apiVector4 for updating instance objects
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject GameLib.D3.*
|
|
||||||
* @param apiVector4 GameLib.API.Vector4
|
* @param apiVector4 GameLib.API.Vector4
|
||||||
|
* @param parentObject GameLib.*
|
||||||
* @param grain Number
|
* @param grain Number
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.Vector4 = function (graphics, parentObject, apiVector4, grain) {
|
GameLib.Vector4 = function (
|
||||||
|
graphics,
|
||||||
|
apiVector4,
|
||||||
|
parentObject,
|
||||||
|
grain
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiVector4)) {
|
||||||
|
apiVector4 = {};
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.API.Vector4.call(
|
GameLib.API.Vector4.call(
|
||||||
this,
|
this,
|
||||||
|
@ -16,10 +28,9 @@ GameLib.Vector4 = function (graphics, parentObject, apiVector4, grain) {
|
||||||
apiVector4.w
|
apiVector4.w
|
||||||
);
|
);
|
||||||
|
|
||||||
this.graphics = graphics;
|
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
|
||||||
|
parentObject = null;
|
||||||
this.graphics.isNotThreeThrow();
|
}
|
||||||
|
|
||||||
this.parentObject = parentObject;
|
this.parentObject = parentObject;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
if (GameLib.Utils.UndefinedOrNull(grain)) {
|
||||||
|
@ -62,7 +73,8 @@ GameLib.Vector4.prototype.updateInstance = function() {
|
||||||
|
|
||||||
this.createInstance(true);
|
this.createInstance(true);
|
||||||
|
|
||||||
if (this.parentObject.updateInstance) {
|
if (this.parentObject &&
|
||||||
|
this.parentObject.updateInstance) {
|
||||||
this.parentObject.updateInstance();
|
this.parentObject.updateInstance();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue