scene save bug fix, set from camera for raycaster, lookAt for mesh

beta.r3js.org
-=yb4f310 2017-11-11 17:44:09 +01:00
parent 237816ad7e
commit a0500b9bd4
4 changed files with 48 additions and 3 deletions

View File

@ -194,7 +194,7 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
objectScene.showGrid,
objectScene.showAxis,
objectScene.gridSize,
objectScene.gridColor,
GameLib.API.Color.FromObject(objectScene.gridColor),
objectScene.parentEntity
);

View File

@ -194,6 +194,28 @@ GameLib.D3.Mesh.MESH_TYPE_CYLINDER = 0x6;
GameLib.D3.Mesh.MESH_TYPE_TEXT = 0x7;
GameLib.D3.Mesh.MESH_TYPE_LINE = 0x8;
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.createInstanceGeometry = function(instanceGeometry) {
if (instanceGeometry instanceof THREE.Geometry) {
@ -537,7 +559,7 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
/**
* Updates the mesh instance
*/
GameLib.D3.Mesh.prototype.updateInstance = function() {
GameLib.D3.Mesh.prototype.updateInstance = function(property) {
if (( this.isBufferMesh && !(this.instance.geometry instanceof THREE.BufferGeometry)) ||
( !this.isBufferMesh && (this.instance.geometry instanceof THREE.BufferGeometry)))

View File

@ -148,6 +148,29 @@ GameLib.D3.Raycaster.prototype.setPosition = function(
this.position.updateInstance();
};
/**
* Sets the ray position and direction from the mouse coordinates (in proper x and y (-1 to 1))
* @param mouse
* @param camera
*/
GameLib.D3.Raycaster.prototype.setFromCamera = function(
mouse,
camera
) {
this.instance.setFromCamera(
mouse,
camera.instance
);
this.position.x = this.instance.ray.origin.x;
this.position.y = this.instance.ray.origin.y;
this.position.z = this.instance.ray.origin.z;
this.direction.x = this.instance.ray.direction.x;
this.direction.y = this.instance.ray.direction.y;
this.direction.z = this.instance.ray.direction.z;
};
/**
* Gets all interesected GameLib.D3.Mesh objects
* @param meshes [GameLib.D3.Mesh]

View File

@ -403,7 +403,7 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
this.showGrid,
this.showAxis,
this.gridSize,
this.gridColor,
this.gridColor.toApiObject(),
GameLib.Utils.IdOrNull(this.parentEntity)
);
};