From a0500b9bd4d541a2c8b1d068eeb531600272155b Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sat, 11 Nov 2017 17:44:09 +0100 Subject: [PATCH] scene save bug fix, set from camera for raycaster, lookAt for mesh --- src/game-lib-d3-api-scene.js | 2 +- src/game-lib-d3-mesh-0.js | 24 +++++++++++++++++++++++- src/game-lib-d3-raycaster.js | 23 +++++++++++++++++++++++ src/game-lib-d3-scene.js | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/game-lib-d3-api-scene.js b/src/game-lib-d3-api-scene.js index a7dfe19..0bf7656 100644 --- a/src/game-lib-d3-api-scene.js +++ b/src/game-lib-d3-api-scene.js @@ -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 ); diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index 86abfbf..a03b4cf 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -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))) diff --git a/src/game-lib-d3-raycaster.js b/src/game-lib-d3-raycaster.js index 00282d8..5e9b2a0 100644 --- a/src/game-lib-d3-raycaster.js +++ b/src/game-lib-d3-raycaster.js @@ -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] diff --git a/src/game-lib-d3-scene.js b/src/game-lib-d3-scene.js index 291a83c..fd62480 100644 --- a/src/game-lib-d3-scene.js +++ b/src/game-lib-d3-scene.js @@ -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) ); };