camera update lookat

beta.r3js.org
-=yb4f310 2017-10-30 19:34:26 +01:00
parent 99cef0a288
commit 16eca4acb7
2 changed files with 141 additions and 0 deletions

View File

@ -195,6 +195,10 @@ GameLib.D3.Camera.prototype.updateInstance = function() {
this.instance.quaternion.z = this.quaternion.z;
this.instance.quaternion.w = this.quaternion.w;
this.lookAt.instance.x = this.lookAt.x;
this.lookAt.instance.y = this.lookAt.y;
this.lookAt.instance.z = this.lookAt.z;
this.instance.lookAt(this.lookAt.instance);
this.instance.updateProjectionMatrix();

View File

@ -0,0 +1,137 @@
/**
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
* @param graphics GameLib.D3.Graphics
* @param apiMesh GameLib.D3.API.Mesh
* @param width
* @param height
* @param depth
* @constructor
*/
GameLib.D3.Mesh.Box = function (
graphics,
apiMesh,
width,
height,
depth
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
apiMesh = {};
}
if (apiMesh instanceof GameLib.D3.Mesh.Box) {
return apiMesh;
}
apiMesh.meshType = GameLib.D3.Mesh.MESH_TYPE_BOX;
if (GameLib.Utils.UndefinedOrNull(width)) {
width = 1;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 1;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(depth)) {
depth = 1;
}
this.depth = depth;
GameLib.D3.Mesh.call(
this,
this.graphics,
apiMesh
);
};
GameLib.D3.Mesh.Box.prototype = Object.create(GameLib.D3.Mesh.prototype);
GameLib.D3.Mesh.Box.prototype.constructor = GameLib.D3.Mesh.Box;
GameLib.D3.Mesh.Box.prototype.createInstance = function() {
var geometry = null;
if (this.vertices.length === 0) {
geometry = new THREE.BoxGeometry(
this.width,
this.height,
this.depth
);
this.updateVerticesFromGeometryInstance(geometry);
}
GameLib.D3.Mesh.prototype.createInstance.call(this);
this.instance.userData.width = this.width;
this.instance.userData.height = this.height;
this.instance.userData.depth = this.depth;
};
GameLib.D3.Mesh.Box.prototype.updateInstance = function() {
if (
this.instance.userData.width !== this.width ||
this.instance.userData.height !== this.height ||
this.instance.userData.depth !== this.depth
) {
this.instance.userData.width = this.width;
this.instance.userData.height = this.height;
this.instance.userData.depth = this.depth;
var geometry = new THREE.BoxGeometry(
this.width,
this.height,
this.depth
);
this.updateVerticesFromGeometryInstance(geometry);
geometry = this.createInstanceGeometry();
this.instance.geometry = geometry;
}
GameLib.D3.Mesh.prototype.updateInstance.call(this);
};
/**
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
* @returns {GameLib.D3.API.Mesh}
*/
GameLib.D3.Mesh.Box.prototype.toApiObject = function() {
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this);
apiMesh.width = this.width;
apiMesh.height = this.height;
apiMesh.depth = this.depth;
return apiMesh;
};
/**
* Converts a standard object mesh to a GameLib.D3.Mesh
* @param graphics GameLib.D3.Graphics
* @param objectMesh {Object}
* @constructor
*/
GameLib.D3.Mesh.Box.FromObject = function(graphics, objectMesh) {
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);
return new GameLib.D3.Mesh.Box(
graphics,
apiMesh,
objectMesh.width,
objectMesh.height,
objectMesh.depth
);
};