|
From: <ma...@us...> - 2011-12-18 14:19:27
|
Revision: 589
http://openautomation.svn.sourceforge.net/openautomation/?rev=589&view=rev
Author: mayerch
Date: 2011-12-18 14:19:21 +0000 (Sun, 18 Dec 2011)
Log Message:
-----------
Make it work again (although the hole fix isn't correct at the moment and things look worse...).
Also some initial commets to make YUI Doc work.
NOTE: YUI Doc has to be a newer version than the published release as that has a problem with UTF-8 chars...
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 13:27:38 UTC (rev 588)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 14:19:21 UTC (rev 589)
@@ -20,6 +20,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
+ * @module JSFloorPlan3D *
***************************************************************************/
// setup script here:
@@ -365,7 +366,6 @@
var sId, eId;
for( var v = 0; v < Tvertices.length; v++ )
{
- /* prepare for later...
// project s1, e1 and s2, e2 onto line sm->em
var lSquaredInv = 1.0 / ((em.x-sm.x)*(em.x-sm.x) + (em.y-sm.y)*(em.y-sm.y));
var s1f = 1-((s1.x-sm.x)*(em.x-sm.x) + (s1.y-sm.y)*(em.y-sm.y))*lSquaredInv;
@@ -380,8 +380,7 @@
var x2 = s2.x * tvx2 + e2.x * (1 - tvx2);
var y1 = s1.y * tvx1 + e1.y * (1 - tvx1);
var y2 = s2.y * tvx2 + e2.y * (1 - tvx2);
- console.log( sm, em, s1, e1, tvx1, x1, y1, s2, e2, tvx2, x2, y2 );
- */
+ //console.log( sm, em, s1, e1, tvx1, x1, y1, s2, e2, tvx2, x2, y2 );
var z = heightOfGround + sh*tv.y;
if( wallSideOrder > 0 )
{
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2011-12-18 13:27:38 UTC (rev 588)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2011-12-18 14:19:21 UTC (rev 589)
@@ -20,6 +20,8 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
+ * @module JSFloorPlan3D *
+ * @submodule JSFloorPlan3D_example *
***************************************************************************/
@@ -166,6 +168,8 @@
/**
* Provides requestAnimationFrame in a cross browser way.
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
+ * @class window
+ * @method requestAnimationFrame
*/
if ( !window.requestAnimationFrame ) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2011-12-18 14:39:46
|
Revision: 591
http://openautomation.svn.sourceforge.net/openautomation/?rev=591&view=rev
Author: mayerch
Date: 2011-12-18 14:39:40 +0000 (Sun, 18 Dec 2011)
Log Message:
-----------
Set up files to start conversion to a clean library and document in at the same time
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 14:29:20 UTC (rev 590)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 14:39:40 UTC (rev 591)
@@ -1,29 +1,43 @@
-/***************************************************************************
- * *
- * JavaScript FloorPlan 3D *
- * *
- * Copyright (C) 2009, 2010 by Christian Mayer *
- * jsfloorplan (at) ChristianMayer.de *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- * *
- * @module JSFloorPlan3D *
- ***************************************************************************/
+//
+// JavaScript FloorPlan 3D.
+//
+// Copyright (C) 2009, 2010 by Christian Mayer
+// jsfloorplan (at) ChristianMayer.de
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+//////////////////////////////////////////////////////////////////////////////
-// setup script here:
+/**
+ * The JSFLOORPLAN3D object is the single global object created by the
+ * JSFloorPlan 3D library.
+ * @module JSFloorPlan3D
+ * @title JS Floor Plan 3D
+ */
+if (typeof JSFLOORPLAN3D == 'undefined' || !JSFLOORPLAN3D)
+{
+ /**
+ * The JSFLOORPLAN3D global namespace object. If JSFLOORPLAN3D is already
+ * defined, the existing JSFLOORPLAN3D object will not be overwritten so
+ * that defined namespaces are preserved.
+ * @class JSFLOORPLAN3D
+ * @static
+ */
+ var JSFLOORPLAN3D = {};
+}
// don't change anything below:
var ELEMENT_NODE = 1;
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2011-12-18 14:29:20 UTC (rev 590)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2011-12-18 14:39:40 UTC (rev 591)
@@ -1,28 +1,25 @@
-/***************************************************************************
- * *
- * JavaScript FloorPlan 3D - helper functions for the example *
- * *
- * Copyright (C) 2009 by Christian Mayer *
- * jsfloorplan (at) ChristianMayer.de *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- * *
- * @module JSFloorPlan3D *
- * @submodule JSFloorPlan3D_example *
- ***************************************************************************/
+//
+// JavaScript FloorPlan 3D.
+//
+// Copyright (C) 2009, 2010 by Christian Mayer
+// jsfloorplan (at) ChristianMayer.de
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+//////////////////////////////////////////////////////////////////////////////
function three_init()
@@ -168,8 +165,7 @@
/**
* Provides requestAnimationFrame in a cross browser way.
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
- * @class window
- * @method requestAnimationFrame
+ * @class requestAnimationFrame
*/
if ( !window.requestAnimationFrame ) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2011-12-20 16:39:30
|
Revision: 602
http://openautomation.svn.sourceforge.net/openautomation/?rev=602&view=rev
Author: mayerch
Date: 2011-12-20 16:39:19 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
Clarify coordinate system and change camera and light position to azimut/elevation. (This should later allow an easy lighting based by the current time and date)
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-19 21:35:14 UTC (rev 601)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-20 16:39:19 UTC (rev 602)
@@ -65,11 +65,14 @@
* <dd>The attribute <code>orientation</code> defines a rotation of the local
* coordinate system to north.
* <ul>
- * <li><code>orientation="0"</code> means that the x axis is looking
- * north and the y axis is looking east.</li>
- * <li><code>orientation="90"</code> means that the x axis is looking
- * west and the y axis is looking south.</li>
+ * <li><code>orientation="0"</code> means that the y axis is looking
+ * north and the x axis is looking east.</li>
+ * <li><code>orientation="90"</code> means that the y axis is looking
+ * east and the x axis is looking south.</li>
* </ul>
+ * Note: As the z axis points upwards this is a right handed coordinate
+ * system.
+ * <img src="assets/coordinate_system.png" />
* </dd>
* <dt><code><b><floor></b></code></dt>
* <dd>The <code>floor</code> element contains all relevant information
@@ -905,32 +908,32 @@
* Show the floor plan by updating the relevant view parameters and calling
* the render() method
* @method show3D
- * @param {Integer} rotation The direction to look at. 0° = North, 180° =
- * South
- * @param {Integer} tilt The amount of tilting the vire. 0° = no tilt,
- * 90° = bird eyes view
+ * @param {Integer} azmiut The direction of the camera. 0° = North, 90° =
+ * East.
+ * @param {Integer} elevation The amount of tilting the view. 0° = no tilt,
+ * 90° = bird eyes view
*/
- JSFloorPlan3D.show3D = function( rotation, tilt )
+ JSFloorPlan3D.show3D = function( azimut, elevation )
{
if( noSetup ) setup3D();
// set up camera
- var cx = -Math.cos(rotation) * Math.cos(tilt);
- var cy = Math.sin(rotation) * Math.cos(tilt);
- var cz = Math.sin(tilt);
+ var cx = Math.sin(azimut) * Math.cos(elevation);
+ var cy = Math.cos(azimut) * Math.cos(elevation);
+ var cz = Math.sin(elevation);
var heightOfGround = JSFloorPlan3D.buildingProperties.floor[ showStates.showFloor ].heightOfGround;
var target = new THREE.Vector3( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center, heightOfGround);
- camera.up = new THREE.Vector3( Math.cos(rotation) * Math.sin(tilt), -Math.sin(rotation) * Math.sin(tilt), Math.cos(tilt) );
+ camera.up = new THREE.Vector3( -Math.sin(azimut) * Math.sin(elevation), -Math.cos(azimut) * Math.sin(elevation), Math.cos(elevation) );
camera.position = new THREE.Vector3( cx*dist + JSFloorPlan3D.buildingProperties.x_center, cy*dist + JSFloorPlan3D.buildingProperties.y_center, dist * cz + heightOfGround);
camera.lookAt( target );
pointLight.position = camera.position;
// set up sun
- var sx = -Math.cos(lightDirection) * Math.cos(lightHeight);
- var sy = Math.sin(lightDirection) * Math.cos(lightHeight);
- var sz = Math.sin(lightHeight);
+ var sx = Math.sin(lightAzimut) * Math.cos(lightElevation);
+ var sy = Math.cos(lightAzimut) * Math.cos(lightElevation);
+ var sz = Math.sin(lightElevation);
sunLight.target.position = target;
- sunLight.position = new THREE.Vector3( sx * lightDistance, sy * lightDistance, sz * lightDistance );
+ sunLight.position = new THREE.Vector3( sx * lightDistance, sy * lightDistance, sz * lightDistance + heightOfGround);
sunLight.intensity = lightStrength / 100.0;
sunLightViewLine.geometry.vertices[0].position = sunLight.position;
sunLightViewLine.geometry.vertices[1].position = sunLight.target.position;
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2011-12-19 21:35:14 UTC (rev 601)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2011-12-20 16:39:19 UTC (rev 602)
@@ -21,6 +21,12 @@
//
//////////////////////////////////////////////////////////////////////////////
+/**
+ * The "Example helpers" module contains all the JavaScript functions that are
+ * needed to show the example.
+ * @module JS FloorPlan 3D Example
+ */
+
j = new JSFLOORPLAN3D();
function loadFloorplan()
{
@@ -148,8 +154,8 @@
// add to the scene
//scene.add(pointLight);
-var lightDirection = 3.9;
-var lightHeight = 0.25;
+var lightAzimut = 3.9;
+var lightElevation = 0.25;
var lightStrength = 80;
var lightDistance = 50;
//var sunLight = new THREE.PointLight( 0xFFFFFF );
@@ -452,8 +458,8 @@
globalInUpdateSlider = true;
var rollAngle = (roll * 180/Math.PI);
var tiltAngle = (tilt * 180/Math.PI);
- var lightDirectionAngle = (lightDirection * 180/Math.PI);
- var lightHeightAngle = (lightHeight * 180/Math.PI);
+ var lightDirectionAngle = (lightAzimut * 180/Math.PI);
+ var lightHeightAngle = (lightElevation * 180/Math.PI);
$( "#rollSlider" ).slider( "option", "value", rollAngle );
$( "#tiltSlider" ).slider( "option", "value", tiltAngle );
$( "#distSlider" ).slider( "option", "value", dist );
@@ -488,14 +494,14 @@
function lightDirectionChange( event, ui )
{
if( globalInUpdateSlider ) return true;
- lightDirection = ui.value * Math.PI / 180;
+ lightAzimut = ui.value * Math.PI / 180;
j.show3D( roll, tilt );
}
function lightHeightChange( event, ui )
{
if( globalInUpdateSlider ) return true;
- lightHeight = ui.value * Math.PI / 180;
+ lightElevation = ui.value * Math.PI / 180;
j.show3D( roll, tilt );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-01-08 14:14:45
|
Revision: 642
http://openautomation.svn.sourceforge.net/openautomation/?rev=642&view=rev
Author: mayerch
Date: 2012-01-08 14:14:38 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
- fix holes in the walls
- new method moveTo() for smooth transisions
- use moveTo for floor level change
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 00:30:29 UTC (rev 641)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 14:14:38 UTC (rev 642)
@@ -565,7 +565,7 @@
var wall2vertices = [];
var sId, eId;
var l1SquaredInv = 1.0 / ((e1.x-s1.x)*(e1.x-s1.x) + (e1.y-s1.y)*(e1.y-s1.y));
- var l1SquaredInv = 1.0 / ((e2.x-s2.x)*(e2.x-s2.x) + (e2.y-s2.y)*(e2.y-s2.y));
+ var l2SquaredInv = 1.0 / ((e2.x-s2.x)*(e2.x-s2.x) + (e2.y-s2.y)*(e2.y-s2.y));
for( var v = 0; v < Tvertices.length; v++ )
{
var tv = Tvertices[v];
@@ -583,11 +583,11 @@
var y1 = s1.y * (1-f1) + e1.y * f1;
// project it onto s2->e2
- var f2 = ((tm.x-s2.x)*(e2.x-s2.x) + (tm.y-s2.y)*(e2.y-s2.y))*l1SquaredInv;
+ var f2 = ((tm.x-s2.x)*(e2.x-s2.x) + (tm.y-s2.y)*(e2.y-s2.y))*l2SquaredInv;
if( tv.x == 0.0 || tv.x == 1.0 ) f2 = 1-tv.x; // special case on concave wall bend
var x2 = s2.x * (1-f2) + e2.x * f2;
var y2 = s2.y * (1-f2) + e2.y * f2;
-
+
var z = heightOfGround + sh*tv.y;
if( wallSideOrder > 0 )
{
@@ -902,6 +902,17 @@
selectChange( 'showFloor' );
}
+ function setupCamera( azimut, elevation, height, target )
+ {
+ var cx = Math.sin(azimut) * Math.cos(elevation);
+ var cy = Math.cos(azimut) * Math.cos(elevation);
+ var cz = Math.sin(elevation);
+ camera.up = new THREE.Vector3( -Math.sin(azimut) * Math.sin(elevation), -Math.cos(azimut) * Math.sin(elevation), Math.cos(elevation) );
+ camera.position = new THREE.Vector3( cx*dist + JSFloorPlan3D.buildingProperties.x_center, cy*dist + JSFloorPlan3D.buildingProperties.y_center, dist * cz + height );
+ camera.lookAt( target );
+ pointLight.position = camera.position;
+ }
+
/**
* Show the floor plan by updating the relevant view parameters and calling
* the render() method
@@ -916,16 +927,14 @@
if( noSetup ) setup3D();
// set up camera
- var cx = Math.sin(azimut) * Math.cos(elevation);
- var cy = Math.cos(azimut) * Math.cos(elevation);
- var cz = Math.sin(elevation);
var heightOfGround = JSFloorPlan3D.buildingProperties.floor[ showStates.showFloor ].heightOfGround;
- var target = new THREE.Vector3( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center, heightOfGround);
- camera.up = new THREE.Vector3( -Math.sin(azimut) * Math.sin(elevation), -Math.cos(azimut) * Math.sin(elevation), Math.cos(elevation) );
- camera.position = new THREE.Vector3( cx*dist + JSFloorPlan3D.buildingProperties.x_center, cy*dist + JSFloorPlan3D.buildingProperties.y_center, dist * cz + heightOfGround);
- camera.lookAt( target );
- pointLight.position = camera.position;
+ var target = new THREE.Vector3( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center, heightOfGround );
+ setupCamera( azimut, elevation, heightOfGround, target );
+ showStates.currentAzimut = azimut;
+ showStates.currentElevation = elevation;
+ showStates.currentHeight = heightOfGround;
+
// set up sun
var sx = Math.sin(lightAzimut) * Math.cos(lightElevation);
var sy = Math.cos(lightAzimut) * Math.cos(lightElevation);
@@ -972,4 +981,59 @@
render();
}
+ /**
+ * Move the displayed part of the floor plan to a new part
+ * @method moveTo
+ * @param {Integer} floor The number of the floor to show
+ * @param {Integer} azmiut The direction of the camera. 0° = North, 90° =
+ * East.
+ * @param {Integer} elevation The amount of tilting the view. 0° = no tilt,
+ * 90° = bird eyes view
+ * @param {Function} delayedFn (optional) Function to call after animation is
+ * finished
+ */
+ JSFloorPlan3D.moveTo = function( floor, azimut, elevation, delayedFn )
+ {
+ if( noSetup ) setup3D();
+
+ var height = JSFloorPlan3D.buildingProperties.floor[ floor ].heightOfGround;
+
+ // speed of the changing
+ var steps = 100;
+ var rate = {
+ azimut: ( azimut - showStates.currentAzimut ) / steps,
+ elevation: ( elevation - showStates.currentElevation ) / steps,
+ height: ( height - showStates.currentHeight ) / steps
+ };
+
+ function doMove()
+ {
+ var done = true;
+ if( Math.abs( azimut - showStates.currentAzimut ) > Math.abs( rate.azimut ) )
+ {
+ showStates.currentAzimut += rate.azimut;
+ done = false;
+ }
+ if( Math.abs( elevation - showStates.currenteElevation ) > Math.abs( rate.elevation ) )
+ {
+ showStates.currentElevation += rate.elevation;
+ done = false;
+ }
+ if( Math.abs( height - showStates.currentHeight ) > Math.abs( rate.height ) )
+ {
+ showStates.currentHeight += rate.height;
+ done = false;
+ }
+
+ var target = new THREE.Vector3( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center, showStates.currentHeight );
+ setupCamera( showStates.currentAzimut, showStates.currentElevation, showStates.currentHeight, target );
+ render();
+ if( !done )
+ window.requestAnimationFrame( doMove );
+ else if( delayedFn )
+ delayedFn();
+ }
+
+ doMove();
+ }
};//());
\ No newline at end of file
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-01-08 00:30:29 UTC (rev 641)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-01-08 14:14:38 UTC (rev 642)
@@ -248,16 +248,22 @@
function init()
{
$('input').change(function(e){
+ var old = showStates[ e.target.name ];
showStates[ e.target.name ] = e.target.checked;
- selectChange( e.target.name );
- j.show3D( roll, tilt );
+ if( selectChange( e.target.name, old ) )
+ {
+ j.show3D( roll, tilt );
+ }
}).each(function(){
showStates[ this.name ] = this.checked; // init
});
$('select').change(function(e){
+ var old = showStates[ e.target.name ];
showStates[ e.target.name ] = e.target.value;
- selectChange( e.target.name );
- j.show3D( roll, tilt );
+ if( selectChange( e.target.name, old ) )
+ {
+ j.show3D( roll, tilt );
+ }
}).each(function(){
showStates[ this.name ] = this.value; // init
});
@@ -266,7 +272,7 @@
createSlider();
}
-function selectChange( name )
+function selectChange( name, old )
{
switch( name )
{
@@ -287,17 +293,30 @@
break;
case 'showFloor':
+ //showStates['showFloor'] = Number( showStates['showFloor'] );
+ var min = old < showStates['showFloor'] ? old : showStates['showFloor'];
+ var max = old > showStates['showFloor'] ? old : showStates['showFloor'];
$( j.buildingProperties.floor ).each( function( number ){
THREE.SceneUtils.traverseHierarchy( this.wallGroup, function( object ) {
- object.visible = ( showStates['showFloor'] == number );
+ object.visible = ( (min <= number) && (number <= max) );
});
});
+ j.moveTo( showStates['showFloor'], roll, tilt, function(){
+ $( j.buildingProperties.floor ).each( function( number ){
+ THREE.SceneUtils.traverseHierarchy( this.wallGroup, function( object ) {
+ object.visible = ( showStates['showFloor'] == number );
+ });
+ });
+ j.show3D( roll, tilt );
+ });
+ return false;
break;
case 'showWireframe':
cubeMaterial.wireframe = showStates['showWireframe'];
break;
}
+ return true;
}
var toggle = false;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-01-14 14:44:42
|
Revision: 649
http://openautomation.svn.sourceforge.net/openautomation/?rev=649&view=rev
Author: mayerch
Date: 2012-01-14 14:44:36 +0000 (Sat, 14 Jan 2012)
Log Message:
-----------
New feature: figure out the room / zone that's under the mouse during a click
-> also added functions to map points between building and screen space
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-09 18:39:38 UTC (rev 648)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-14 14:44:36 UTC (rev 649)
@@ -1074,4 +1074,84 @@
else
doMove();
}
+
+ /**
+ * Check if point p is in the zone zone. It's basically a point-in-polygon
+ * test using a ray casting from left infinity to the point <code>p</code>.
+ */
+ function pointInZone( p, zone )
+ {
+ var crossing = 0;
+ var prevCorner = floorNodes[ zone.corners[zone.corners.length-1] ];
+ for( var i in zone.corners )
+ {
+ var corner = floorNodes[ zone.corners[i] ];
+ if( // only intersection if
+ (prevCorner.x < p.x || corner.x < p.x ) // at least one point is left
+ && // and
+ ( (prevCorner.y - p.y) * (corner.y - p.y) < 0 ) // one corner is above and the other below
+ )
+ {
+ crossing++;
+ }
+ prevCorner = corner;
+ }
+ return crossing % 2; // odd number of crossings == inside
+ }
+
+ /**
+ * Figur out the room that contains the point <code>p</code> in the floor <code>floor</code>.
+ */
+ JSFloorPlan3D.selectRoom = function( p, floor )
+ {
+ var thisFloor = rooms[floor];
+ for( var room in thisFloor )
+ {
+ var thisRoom = thisFloor[room];
+ for( var zone in thisRoom.zones )
+ {
+ if( pointInZone( p, thisRoom.zones[zone] ) )
+ {
+ console.log( 'in zone', thisRoom.zones[zone].name, 'in raum', thisFloor[room].name, 'in stock', floor );
+ }
+ }
+ }
+ }
+
+ /**
+ * Project screen coordinate to building space
+ */
+ JSFloorPlan3D.sceen2building = function( x, y, h )
+ {
+ var vector = new THREE.Vector3( (x / WIDTH)*2-1, -(y / HEIGHT)*2+1, 0.5 );
+ projector.unprojectVector( vector, camera );
+ var dirVec = vector.subSelf( camera.position ).normalize()
+ var d = (h - camera.position.z) / dirVec.z;
+ return new THREE.Vector3( camera.position.x + d * dirVec.x, camera.position.y + d * dirVec.y, camera.position.z + d * dirVec.z );
+ }
+
+ /**
+ * Project point in building space to screen space
+ */
+ JSFloorPlan3D.building2screen = function( p )
+ {
+ var screen = p.clone();
+ projector.projectVector( screen, camera );
+ return screen;
+ }
+
+ /**
+ * This method can be used as an event handler for mouse events.
+ * @param {Event} event The jQuery event object.
+ * @param {Function} event.data.callback This callback function will be called
+ * after the mouse event was translated
+ */
+ JSFloorPlan3D.translateMouseEvent = function( event )
+ {
+ console.log( JSFloorPlan3D.buildingProperties, showStates );
+ var thisFloor = JSFloorPlan3D.buildingProperties.floor[showStates.showFloor];
+ var height = thisFloor.heightOfGround + thisFloor.height;
+ var intersec = JSFloorPlan3D.sceen2building( event.offsetX, event.offsetY, height );
+ JSFloorPlan3D.selectRoom( intersec, showStates.showFloor );
+ }
};//());
\ No newline at end of file
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-01-09 18:39:38 UTC (rev 648)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-01-14 14:44:36 UTC (rev 649)
@@ -102,8 +102,8 @@
renderer.shadowMapHeight = SHADOW_MAP_HEIGHT;
renderer.shadowMapEnabled = true;
//renderer.shadowMapSoft = true;
+var projector = new THREE.Projector();
-
// set up the sphere vars
var radius = 50, segments = 16, rings = 16;
@@ -209,6 +209,7 @@
/////////////////////////////////////////////////////////////////////////////
$(function() {
three_init();
+ $('#top_level').click( 'foo', j.translateMouseEvent );
});
/////////////////////////////////////////////////////////////////////////////
// setup script here:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-01-15 21:53:18
|
Revision: 659
http://openautomation.svn.sourceforge.net/openautomation/?rev=659&view=rev
Author: mayerch
Date: 2012-01-15 21:53:11 +0000 (Sun, 15 Jan 2012)
Log Message:
-----------
Move to the rooms by clicking on them - and move to a overview by clicking outside
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-15 20:47:26 UTC (rev 658)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-15 21:53:11 UTC (rev 659)
@@ -685,11 +685,12 @@
JSFloorPlan3D.buildingProperties.x_center = (JSFloorPlan3D.buildingProperties.x_max - JSFloorPlan3D.buildingProperties.x_min) / 2;
JSFloorPlan3D.buildingProperties.y_center = (JSFloorPlan3D.buildingProperties.y_max - JSFloorPlan3D.buildingProperties.y_min) / 2;
+ JSFloorPlan3D.buildingProperties.size = Math.max( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center );
imageCenter.x = JSFloorPlan3D.buildingProperties.x_center;
imageCenter.y = JSFloorPlan3D.buildingProperties.y_center;
imageCenter.z = JSFloorPlan3D.buildingProperties.z_max / 2;
- JSFloorPlan3D.show3D( 35*Math.PI/180, 30*Math.PI/180 );
+ JSFloorPlan3D.show3D( 35*Math.PI/180, 30*Math.PI/180, 10, new THREE.Vector3( imageCenter.x, imageCenter.y, imageCenter.z ) );
//}
};
@@ -842,6 +843,10 @@
var room = new Object;
room.name = node.getAttribute('name');
room.zones = new Array;
+ room.center = { x: 0, y: 0 };
+ var centerCount = 0;
+ var min = {};
+ var max = {};
for( var j=0; j < node.childNodes.length; j++ )
{
@@ -857,10 +862,25 @@
{
var corner = zone.childNodes[k];
if (corner.nodeType != ELEMENT_NODE) continue;
- thiszone.corners.push( corner.getAttribute('nodeid') );
+ var id = corner.getAttribute('nodeid')
+ thiszone.corners.push( id );
+ var x = floorNodes[ id ].x;
+ var y = floorNodes[ id ].y;
+ room.center.x += x;
+ room.center.y += y;
+ if( x < min.x || (!min.x) ) min.x = x;
+ if( y < min.y || (!min.y) ) min.y = y;
+ if( x > max.x || (!max.x) ) max.x = x;
+ if( y > max.y || (!max.y) ) max.y = y;
+ centerCount++;
}
room.zones.push( thiszone );
}
+ room.center.x /= centerCount;
+ room.center.y /= centerCount;
+ var min_dist = Math.sqrt( (room.center.x - min.x)*(room.center.x - min.x) + (room.center.y - min.y)*(room.center.y - min.y) );
+ var max_dist = Math.sqrt( (room.center.x - max.x)*(room.center.x - max.x) + (room.center.y - max.y)*(room.center.y - max.y) );
+ room.size = min_dist < max_dist ? max_dist : min_dist;
rooms[floor].push( room );
}
}
@@ -906,18 +926,18 @@
$container.append(renderer.domElement);
// Init after the scene was set up
- selectChange( 'showNodes' );
- selectChange( 'showWallLines' );
- selectChange( 'showFloor' );
+ selectChange( 'showNodes' , 0, true );
+ selectChange( 'showWallLines' , 0, true );
+ selectChange( 'showFloor' , 0, true );
}
- function setupCamera( azimut, elevation, height, target )
+ function setupCamera( azimut, elevation, distance, target )
{
var cx = Math.sin(azimut) * Math.cos(elevation);
var cy = Math.cos(azimut) * Math.cos(elevation);
var cz = Math.sin(elevation);
camera.up = new THREE.Vector3( -Math.sin(azimut) * Math.sin(elevation), -Math.cos(azimut) * Math.sin(elevation), Math.cos(elevation) );
- camera.position = new THREE.Vector3( cx*dist + JSFloorPlan3D.buildingProperties.x_center, cy*dist + JSFloorPlan3D.buildingProperties.y_center, dist * cz + height );
+ camera.position = new THREE.Vector3( cx*distance + target.x, cy*distance + target.y, distance * cz + target.z );
camera.lookAt( target );
pointLight.position = camera.position;
}
@@ -926,30 +946,31 @@
* Show the floor plan by updating the relevant view parameters and calling
* the render() method
* @method show3D
- * @param {Integer} azmiut The direction of the camera. 0° = North, 90° =
- * East.
- * @param {Integer} elevation The amount of tilting the view. 0° = no tilt,
- * 90° = bird eyes view
+ * @param {Integer} azmiut The direction of the camera. 0° = North,
+ * 90° = East.
+ * @param {Integer} elevation The amount of tilting the view. 0° = no tilt,
+ * 90° = bird eyes view
+ * @param {Number} distnce Distance between camera and <code>target</code>
+ * @param {THREE.Vector3} target The point to look at
*/
- JSFloorPlan3D.show3D = function( azimut, elevation )
+ JSFloorPlan3D.show3D = function( azimut, elevation, distance, target )
{
+ showStates.currentAzimut = azimut;
+ showStates.currentElevation = elevation;
+ showStates.currentDistance = distance;
+ showStates.currentTarget = target.clone(); //JSFloorPlan3D.buildingProperties.x_center;
+
if( noSetup ) setup3D();
// set up camera
- var heightOfGround = JSFloorPlan3D.buildingProperties.floor[ showStates.showFloor ].heightOfGround;
- var target = new THREE.Vector3( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center, heightOfGround );
- setupCamera( azimut, elevation, heightOfGround, target );
+ setupCamera( azimut, elevation, distance, target );
- showStates.currentAzimut = azimut;
- showStates.currentElevation = elevation;
- showStates.currentHeight = heightOfGround;
-
// set up sun
var sx = Math.sin(lightAzimut) * Math.cos(lightElevation);
var sy = Math.cos(lightAzimut) * Math.cos(lightElevation);
var sz = Math.sin(lightElevation);
sunLight.target.position = target;
- sunLight.position = new THREE.Vector3( sx * lightDistance, sy * lightDistance, sz * lightDistance + heightOfGround);
+ sunLight.position = new THREE.Vector3( sx * lightDistance, sy * lightDistance, sz * lightDistance + target.z );
sunLight.intensity = lightStrength / 100.0;
sunLightViewLine.geometry.vertices[0].position = sunLight.position;
sunLightViewLine.geometry.vertices[1].position = sunLight.target.position;
@@ -1001,65 +1022,93 @@
/**
* Move the displayed part of the floor plan to a new part
* @method moveTo
- * @param {Integer} floor The number of the floor to show
- * @param {Integer} azmiut The direction of the camera. 0° = North, 90° =
- * East.
- * @param {Integer} elevation The amount of tilting the view. 0° = no tilt,
- * 90° = bird eyes view
- * @param {Function} delayedFn (optional) Function to call after animation is
- * finished
+ * @param {Integer} floor The number of the floor to show
+ * @param {Integer} azmiut The direction of the camera. 0° = North,
+ * 90° = East.
+ * @param {Integer} elevation The amount of tilting the view. 0° = no tilt,
+ * 90° = bird eyes view
+ * @param {Number} distance The distance of the camera
+ * @param {THREE.Vector3} target The point to look at (only <code>x</code>
+ * and <code>y</code> are used the <code>z</code>
+ * is taken from the parameter <code>floor</code>
+ * @param {Function} delayedFn (optional) Function to call after animation is
+ * finished
*/
- JSFloorPlan3D.moveTo = function( floor, azimut, elevation, delayedFn )
+ JSFloorPlan3D.moveTo = function( floor, azimut, elevation, distance, target, delayedFn )
{
if( noSetup ) setup3D();
- var height = JSFloorPlan3D.buildingProperties.floor[ floor ].heightOfGround;
-
// speed of the changing
var steps = 100;
- var rate = { azimut: 0.0, elevation: 0.0, height: 0.0 };
+ var rate = { azimut: 0.0, elevation: 0.0, distance: 0.0, target: new THREE.Vector3 };
function calcRate()
{
- rate = {
- azimut: ( azimut - showStates.currentAzimut ) / steps,
- elevation: ( elevation - showStates.currentElevation ) / steps,
- height: ( height - showStates.currentHeight ) / steps
- };
+ rate.azimut = ( azimut - showStates.currentAzimut ) / steps;
+ rate.elevation = ( elevation - showStates.currentElevation ) / steps;
+ rate.distance = ( distance - showStates.currentDistance ) / steps;
+ rate.target.sub( target, showStates.currentTarget );
+ rate.target.multiplyScalar( 1.0 / steps );
+ return (
+ ( Math.abs( rate.azimut * steps ) < 1e-5 ) &&
+ ( Math.abs( rate.elevation * steps ) < 1e-5 ) &&
+ ( Math.abs( rate.distance * steps ) < 1e-4 ) &&
+ ( Math.abs( rate.target.x * steps ) < 1e-4 ) &&
+ ( Math.abs( rate.target.y * steps ) < 1e-4 ) &&
+ ( Math.abs( rate.target.z * steps ) < 1e-4 )
+ );
}
function doMove()
{
JSFloorPlan3D.inAnimation = true;
var done = true;
- if( Math.abs( azimut - showStates.currentAzimut ) > Math.abs( rate.azimut ) )
+ if( (showStates.currentAzimut + rate.azimut) * rate.azimut < azimut * rate.azimut )
{
- if( rate.azimut == 0.0 ) calcRate();
showStates.currentAzimut += rate.azimut;
- if( Math.abs( azimut - showStates.currentAzimut ) < 1e-5 ) // clamp if close enough
- showStates.currentAzimut = azimut;
done = false;
+ } else {
+ showStates.currentAzimut = azimut;
}
- if( Math.abs( elevation - showStates.currenteElevation ) > Math.abs( rate.elevation ) )
+ if( (showStates.currentElevation + rate.elevation) * rate.elevation < elevation * rate.elevation )
{
- if( rate.elevation == 0.0 ) calcRate();
showStates.currentElevation += rate.elevation;
- if( Math.abs( elevation - showStates.currenteElevation ) < 1e-5 ) // clamp if close enough
- showStates.currenteElevation = elevation;
done = false;
+ } else {
+ showStates.currenteElevation = elevation;
}
- if( Math.abs( height - showStates.currentHeight ) > Math.abs( rate.height ) )
+ if( (showStates.currentDistance + rate.distance) * rate.distance < distance * rate.distance )
{
- if( rate.height == 0.0 ) calcRate();
- showStates.currentHeight += rate.height;
- if( Math.abs( height - showStates.currentHeight ) < 1e-4 ) // clamp if close enough
- showStates.currentHeight = height;
+ showStates.currentDistance += rate.distance;
done = false;
+ } else {
+ showStates.currentDistance = distance;
}
+ if( (showStates.currentTarget.x + rate.target.x) * rate.target.x < target.x * rate.target.x )
+ {
+ showStates.currentTarget.x += rate.target.x;
+ done = false;
+ } else {
+ showStates.currentTarget.x = target.x;
+ }
+ if( (showStates.currentTarget.y + rate.target.y) * rate.target.y < target.y * rate.target.y )
+ {
+ showStates.currentTarget.y += rate.target.y;
+ done = false;
+ } else {
+ showStates.currentTarget.y = target.y;
+ }
+ if( (showStates.currentTarget.z + rate.target.z) * rate.target.z < target.z * rate.target.z )
+ {
+ showStates.currentTarget.z += rate.target.z;
+ done = false;
+ } else {
+ showStates.currentTarget.z = target.z;
+ }
- var target = new THREE.Vector3( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center, showStates.currentHeight );
- setupCamera( showStates.currentAzimut, showStates.currentElevation, showStates.currentHeight, target );
+ setupCamera( showStates.currentAzimut, showStates.currentElevation, showStates.currentDistance, showStates.currentTarget );
render();
+
if( !done )
window.requestAnimationFrame( doMove );
else {
@@ -1069,9 +1118,8 @@
}
}
- if( JSFloorPlan3D.inAnimation )
- calcRate();
- else
+ calcRate();
+ if( !JSFloorPlan3D.inAnimation )
doMove();
}
@@ -1178,6 +1226,7 @@
var thisFloor = JSFloorPlan3D.buildingProperties.floor[showStates.showFloor];
var height = thisFloor.heightOfGround + thisFloor.height;
var intersec = JSFloorPlan3D.sceen2building( event.offsetX, event.offsetY, height );
- JSFloorPlan3D.selectRoom( intersec, showStates.showFloor );
+ event.room = JSFloorPlan3D.selectRoom( intersec, showStates.showFloor );
+ if( event.data.callback ) event.data.callback( event );
}
};//());
\ No newline at end of file
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-01-15 20:47:26 UTC (rev 658)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-01-15 21:53:11 UTC (rev 659)
@@ -30,7 +30,12 @@
j = new JSFLOORPLAN3D();
function loadFloorplan()
{
- $.get('floorplan01.xml', j.parseXMLFloorPlan, 'xml');
+ $.ajax({
+ url: 'floorplan01.xml',
+ success: j.parseXMLFloorPlan,
+ dataType: 'xml',
+ async: false
+ });
}
@@ -195,7 +200,7 @@
function animate() {
requestAnimationFrame( animate );
//render();
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
//stats.update();
}
@@ -206,10 +211,27 @@
//}
+function handleMouseClickEvent( event )
+{
+ if( event.room.room )
+ {
+ var room = event.room.room;
+ var zone = event.room.zone;
+ target.x = room.center.x;
+ target.y = room.center.y;
+ dist = room.size / Math.tan( VIEW_ANGLE * Math.PI/180 / 2 );
+ } else {
+ target.x = j.buildingProperties.x_center;
+ target.y = j.buildingProperties.y_center;
+ dist = j.buildingProperties.size / Math.tan( VIEW_ANGLE * Math.PI/180 / 2 );
+ }
+ updateSlider();
+ j.moveTo( showStates['showFloor'], roll, tilt, dist, target );
+}
/////////////////////////////////////////////////////////////////////////////
$(function() {
three_init();
- $('#top_level').click( 'foo', j.translateMouseEvent );
+ $('#top_level').css('border','1px solid black').click( {callback:handleMouseClickEvent}, j.translateMouseEvent );
});
/////////////////////////////////////////////////////////////////////////////
// setup script here:
@@ -235,6 +257,7 @@
var tilt = 30*Math.PI/180;
var tilt_dir = 1;
var dist = 10;
+var target = new THREE.Vector3();
//var plan = createSVGElement( "g" );
var f_avr = 0;
var m_avr = 0;
@@ -253,7 +276,7 @@
showStates[ e.target.name ] = e.target.checked;
if( selectChange( e.target.name, old ) )
{
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
}).each(function(){
showStates[ this.name ] = this.checked; // init
@@ -263,17 +286,20 @@
showStates[ e.target.name ] = e.target.value;
if( selectChange( e.target.name, old ) )
{
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
}).each(function(){
showStates[ this.name ] = this.value; // init
});
loadFloorplan();
+ target.x = j.buildingProperties.x_center;
+ target.y = j.buildingProperties.y_center;
createSlider();
+ render();
}
-function selectChange( name, old )
+function selectChange( name, old, onlyInit )
{
switch( name )
{
@@ -295,6 +321,17 @@
case 'showFloor':
//showStates['showFloor'] = Number( showStates['showFloor'] );
+ if( onlyInit )
+ {
+ $( j.buildingProperties.floor ).each( function( number ){
+ THREE.SceneUtils.traverseHierarchy( this.wallGroup, function( object ) {
+ object.visible = ( showStates['showFloor'] == number );
+ });
+ });
+ target.z = j.buildingProperties.floor[ showStates['showFloor'] ].heightOfGround +
+ j.buildingProperties.floor[ showStates['showFloor'] ].height / 2;
+ return false;
+ }
var min = old < showStates['showFloor'] ? old : showStates['showFloor'];
var max = old > showStates['showFloor'] ? old : showStates['showFloor'];
$( j.buildingProperties.floor ).each( function( number ){
@@ -302,13 +339,15 @@
object.visible = ( (min <= number) && (number <= max) );
});
});
- j.moveTo( showStates['showFloor'], roll, tilt, function(){
+ target.z = j.buildingProperties.floor[ showStates['showFloor'] ].heightOfGround +
+ j.buildingProperties.floor[ showStates['showFloor'] ].height / 2;
+ j.moveTo( showStates['showFloor'], roll, tilt, dist, target, function(){
$( j.buildingProperties.floor ).each( function( number ){
THREE.SceneUtils.traverseHierarchy( this.wallGroup, function( object ) {
object.visible = ( showStates['showFloor'] == number );
});
});
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
});
return false;
break;
@@ -348,7 +387,7 @@
if( tilt < 0 )
tilt_dir = 1;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
//////
var middle = new Date();
@@ -429,7 +468,7 @@
if( redraw )
{
- j.show3D( roll, tilt, plan );
+ j.show3D( roll, tilt, dist, plan );
}
}
*/
@@ -453,7 +492,7 @@
if( redraw )
{
- j.show3D( roll, tilt, plan );
+ j.show3D( roll, tilt, dist, plan );
}
}
*/
@@ -494,49 +533,49 @@
{
if( globalInUpdateSlider ) return true;
roll = ui.value * Math.PI / 180;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
function tiltChange( event, ui )
{
if( globalInUpdateSlider ) return true;
tilt = ui.value * Math.PI / 180;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
function distChange( event, ui )
{
if( globalInUpdateSlider ) return true;
dist = ui.value;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
function lightDirectionChange( event, ui )
{
if( globalInUpdateSlider ) return true;
lightAzimut = ui.value * Math.PI / 180;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
function lightHeightChange( event, ui )
{
if( globalInUpdateSlider ) return true;
lightElevation = ui.value * Math.PI / 180;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
function lightStrengthChange( event, ui )
{
if( globalInUpdateSlider ) return true;
lightStrength = ui.value;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
function lightDistanceChange( event, ui )
{
if( globalInUpdateSlider ) return true;
lightDistance = ui.value;
- j.show3D( roll, tilt );
+ j.show3D( roll, tilt, dist, target );
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-02-20 21:43:38
|
Revision: 711
http://openautomation.svn.sourceforge.net/openautomation/?rev=711&view=rev
Author: mayerch
Date: 2012-02-20 21:43:31 +0000 (Mon, 20 Feb 2012)
Log Message:
-----------
Big step towards a self contained and clean libaray.
Still missing (not in this commit to keep revision to revision comparisions readable):
* sort stuff between the helper and the library
* sort functions and variables inside of the library
* proper indentation
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-02-19 23:12:54 UTC (rev 710)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-02-20 21:43:31 UTC (rev 711)
@@ -135,31 +135,39 @@
* @title JS FloorPlan 3D
* @reqires jQuery, Three.js
*/
-if (typeof JSFLOORPLAN3D == 'undefined' || !JSFLOORPLAN3D)
-{
- /*
- * The JSFLOORPLAN3D global namespace object. If JSFLOORPLAN3D is already
- * defined, the existing JSFLOORPLAN3D object will not be overwritten so
- * that defined namespaces are preserved.
- */
- var JSFLOORPLAN3D = {};
-}
/**
* @class JSFLOORPLAN3D
* @constructor FOO
*/
-JSFLOORPLAN3D = function () {
+(function( window, undefined ){
+ // the constructor
+ var JSFloorPlan3D = function( floorPlan ){
+ if (!(this instanceof JSFloorPlan3D))
+ {
+ return new JSFloorPlan3D( floorPlan );
+ }
+
+ if (typeof floorPlan === "string")
+ {
+ this.loadFloorPlan( floorPlan );
+ }
+
+ // public variables of this object instance
+ this.buildingProperties = { floor: [], Object3D: new THREE.Object3D() };
+
+ // private variables of this object instance will follow
+
+ var that = this;
+
////////////////////////////////////////////////////////////////////////////
// Definition of the private variables
- var JSFloorPlan3D = this;
var floor;
// this array will contain all vertices to show in the svg
var vertices = Array();
// infos about the building
- JSFloorPlan3D.buildingProperties = { floor: [], Object3D: new THREE.Object3D() };
var imageCenter = new Object;
var noFloorplan = true;
@@ -290,11 +298,27 @@
}
/**
+ * Get the URL url and set up this object by its content
+ * @param {String} url
+ */
+ JSFloorPlan3D.prototype.loadFloorPlan = function( url )
+ {
+ var outerThis = this;
+ $.ajax({
+ url: url,
+ context: outerThis,
+ success: function( xmlDoc ){ outerThis.parseXMLFloorPlan( xmlDoc ); },
+ dataType: 'xml',
+ async: false
+ });
+ }
+
+ /**
* Parse and create internal structure for the floor plan.
* @method parseXMLFloorPlan
* @param {XMLDom} xmlDoc
*/
- JSFloorPlan3D.parseXMLFloorPlan = function( xmlDoc )
+ JSFloorPlan3D.prototype.parseXMLFloorPlan = function( xmlDoc )
{
noFloorplan = false;
@@ -320,7 +344,7 @@
if( floor.tagName == 'textures' )
{
- parseTextures( floor );
+ this.parseTextures( floor );
continue;
}
@@ -329,14 +353,14 @@
"Expected: 'floor', found '" + floor.tagName + "'" );
floorCount++;
- JSFloorPlan3D.buildingProperties.floor[floorCount] = {};
+ this.buildingProperties.floor[floorCount] = {};
var floorName = floor.getAttribute('name');
- JSFloorPlan3D.buildingProperties.floor[floorCount].name = floorName;
+ this.buildingProperties.floor[floorCount].name = floorName;
var floorheight = Number( floor.getAttribute('height') );
- JSFloorPlan3D.buildingProperties.floor[floorCount].height = floorheight;
- JSFloorPlan3D.buildingProperties.floor[floorCount].heightOfGround = heightOfGround;
+ this.buildingProperties.floor[floorCount].height = floorheight;
+ this.buildingProperties.floor[floorCount].heightOfGround = heightOfGround;
var floorWallsStart = floorWalls.length;
@@ -349,15 +373,15 @@
switch( floorNode.tagName )
{
case 'nodes':
- parseFloorNodes( floorNode, floorheight );
+ this.parseFloorNodes( floorNode, floorheight );
break;
case 'walls':
- parseFloorWalls( floorNode );
+ this.parseFloorWalls( floorNode );
break;
case 'rooms':
- parseFloorRooms( floorNode, floorCount );
+ this.parseFloorRooms( floorNode, floorCount );
break;
}
}
@@ -544,7 +568,6 @@
sourrounding.splice( 0, 0, new poly2tri.Point(fRight,0), new poly2tri.Point(fRight,lintel), new poly2tri.Point(fLeft,lintel), new poly2tri.Point(fLeft,0) );
continue;
}
-
holesToAdd.push( [new poly2tri.Point(fLeft,paparet), new poly2tri.Point(fRight,paparet), new poly2tri.Point(fRight,lintel), new poly2tri.Point(fLeft,lintel)] );
}
} // if( floorWalls[j].holes.length )
@@ -555,7 +578,9 @@
// Do the triangulation - FIXME: handle exceptions, don't ignore them...
try {
poly2tri.sweep.Triangulate(swctx);
- }catch(err){}
+ }catch(err){
+ console.log(err);
+ }
// mark all points to make sure that we don't need to double vertices
for( var tp = 0; tp < swctx.point_count(); tp++ )
@@ -674,23 +699,23 @@
Object3D.add( lineGroup );
Object3D.add( wallGroup );
- JSFloorPlan3D.buildingProperties.floor[floorCount].Object3D = Object3D;
- JSFloorPlan3D.buildingProperties.floor[floorCount].nodeGroup = nodeGroup;
- JSFloorPlan3D.buildingProperties.floor[floorCount].lineGroup = lineGroup;
- JSFloorPlan3D.buildingProperties.floor[floorCount].wallGroup = wallGroup;
- JSFloorPlan3D.buildingProperties.Object3D.add( Object3D ); // add / link; note: we use that JavaScript is not copying objects but uses ref counting on them here!
+ this.buildingProperties.floor[floorCount].Object3D = Object3D;
+ this.buildingProperties.floor[floorCount].nodeGroup = nodeGroup;
+ this.buildingProperties.floor[floorCount].lineGroup = lineGroup;
+ this.buildingProperties.floor[floorCount].wallGroup = wallGroup;
+ this.buildingProperties.Object3D.add( Object3D ); // add / link; note: we use that JavaScript is not copying objects but uses ref counting on them here!
heightOfGround += floorheight;
} // end floor
- JSFloorPlan3D.buildingProperties.x_center = (JSFloorPlan3D.buildingProperties.x_max - JSFloorPlan3D.buildingProperties.x_min) / 2;
- JSFloorPlan3D.buildingProperties.y_center = (JSFloorPlan3D.buildingProperties.y_max - JSFloorPlan3D.buildingProperties.y_min) / 2;
- JSFloorPlan3D.buildingProperties.size = Math.max( JSFloorPlan3D.buildingProperties.x_center, JSFloorPlan3D.buildingProperties.y_center );
- imageCenter.x = JSFloorPlan3D.buildingProperties.x_center;
- imageCenter.y = JSFloorPlan3D.buildingProperties.y_center;
- imageCenter.z = JSFloorPlan3D.buildingProperties.z_max / 2;
+ this.buildingProperties.x_center = (this.buildingProperties.x_max - this.buildingProperties.x_min) / 2;
+ this.buildingProperties.y_center = (this.buildingProperties.y_max - this.buildingProperties.y_min) / 2;
+ this.buildingProperties.size = Math.max( this.buildingProperties.x_center, this.buildingProperties.y_center );
+ imageCenter.x = this.buildingProperties.x_center;
+ imageCenter.y = this.buildingProperties.y_center;
+ imageCenter.z = this.buildingProperties.z_max / 2;
- JSFloorPlan3D.show3D( 35*Math.PI/180, 30*Math.PI/180, 10, new THREE.Vector3( imageCenter.x, imageCenter.y, imageCenter.z ) );
+ this.show3D( 35*Math.PI/180, 30*Math.PI/180, 10, new THREE.Vector3( imageCenter.x, imageCenter.y, imageCenter.z ) );
//}
};
@@ -703,7 +728,7 @@
* @param {Float} floorheight The generic height of this floor that might be
* overwritten by individual nodes.
*/
- function parseFloorNodes( nodes, floorheight )
+ JSFloorPlan3D.prototype.parseFloorNodes = function( nodes, floorheight )
{
for( var i=0; i < nodes.childNodes.length; i++ )
{
@@ -719,21 +744,21 @@
floorNodes[id] = point;
- if( undefined == JSFloorPlan3D.buildingProperties.x_min )
+ if( undefined == this.buildingProperties.x_min )
{
- JSFloorPlan3D.buildingProperties.x_min = point.x;
- JSFloorPlan3D.buildingProperties.x_max = point.x;
- JSFloorPlan3D.buildingProperties.y_min = point.y;
- JSFloorPlan3D.buildingProperties.y_max = point.y;
- JSFloorPlan3D.buildingProperties.z_min = point.z;
- JSFloorPlan3D.buildingProperties.z_max = point.z;
+ this.buildingProperties.x_min = point.x;
+ this.buildingProperties.x_max = point.x;
+ this.buildingProperties.y_min = point.y;
+ this.buildingProperties.y_max = point.y;
+ this.buildingProperties.z_min = point.z;
+ this.buildingProperties.z_max = point.z;
} else {
- if( JSFloorPlan3D.buildingProperties.x_min > point.x ) JSFloorPlan3D.buildingProperties.x_min = point.x;
- if( JSFloorPlan3D.buildingProperties.x_max < point.x ) JSFloorPlan3D.buildingProperties.x_max = point.x;
- if( JSFloorPlan3D.buildingProperties.y_min > point.y ) JSFloorPlan3D.buildingProperties.y_min = point.y;
- if( JSFloorPlan3D.buildingProperties.y_max < point.y ) JSFloorPlan3D.buildingProperties.y_max = point.y;
- if( JSFloorPlan3D.buildingProperties.z_min > point.z ) JSFloorPlan3D.buildingProperties.z_min = point.z;
- if( JSFloorPlan3D.buildingProperties.z_max < point.z ) JSFloorPlan3D.buildingProperties.z_max = point.z;
+ if( this.buildingProperties.x_min > point.x ) this.buildingProperties.x_min = point.x;
+ if( this.buildingProperties.x_max < point.x ) this.buildingProperties.x_max = point.x;
+ if( this.buildingProperties.y_min > point.y ) this.buildingProperties.y_min = point.y;
+ if( this.buildingProperties.y_max < point.y ) this.buildingProperties.y_max = point.y;
+ if( this.buildingProperties.z_min > point.z ) this.buildingProperties.z_min = point.z;
+ if( this.buildingProperties.z_max < point.z ) this.buildingProperties.z_max = point.z;
}
}
}
@@ -745,7 +770,7 @@
* @private
* @param {XMLDom} nodeGroup
*/
- function parseFloorWalls( nodes )
+ JSFloorPlan3D.prototype.parseFloorWalls = function( nodes )
{
for( var i=0; i < nodes.childNodes.length; i++ )
{
@@ -832,7 +857,7 @@
* @param {XMLDom} nodeGroup
* @param {Integer} floor The floor number.
*/
- function parseFloorRooms( nodes, floor )
+ JSFloorPlan3D.prototype.parseFloorRooms = function( nodes, floor )
{
rooms[floor] = new Array;
for( var i=0; i < nodes.childNodes.length; i++ )
@@ -892,7 +917,7 @@
* @private
* @param {XMLDom} nodes
*/
- function parseTextures( nodes )
+ JSFloorPlan3D.prototype.parseTextures = function( nodes )
{
return;
for( var i=0; i < nodes.childNodes.length; i++ )
@@ -907,12 +932,12 @@
* @method setup3D
* @private
*/
- function setup3D()
+ function setup3D( thisObject3D )
{
if( noFloorplan ) return;
noSetup = false;
- scene.add( JSFloorPlan3D.buildingProperties.Object3D );
+ scene.add( thisObject3D );
var showFloor = showStates.showFloor;
@@ -953,14 +978,14 @@
* @param {Number} distnce Distance between camera and <code>target</code>
* @param {THREE.Vector3} target The point to look at
*/
- JSFloorPlan3D.show3D = function( azimut, elevation, distance, target )
+ JSFloorPlan3D.prototype.show3D = function( azimut, elevation, distance, target )
{
showStates.currentAzimut = azimut;
showStates.currentElevation = elevation;
showStates.currentDistance = distance;
showStates.currentTarget = target.clone(); //JSFloorPlan3D.buildingProperties.x_center;
- if( noSetup ) setup3D();
+ if( noSetup ) setup3D( this.buildingProperties.Object3D );
// set up camera
setupCamera( azimut, elevation, distance, target );
@@ -1034,9 +1059,9 @@
* @param {Function} delayedFn (optional) Function to call after animation is
* finished
*/
- JSFloorPlan3D.moveTo = function( floor, azimut, elevation, distance, target, delayedFn )
+ JSFloorPlan3D.prototype.moveTo = function( floor, azimut, elevation, distance, target, delayedFn )
{
- if( noSetup ) setup3D();
+ if( noSetup ) setup3D( this.buildingProperties.Object3D );
// speed of the changing
var steps = 100;
@@ -1166,7 +1191,7 @@
* @return {Object} If a zone / room was found a hash with the keys "room" and
* "zone" will be returned otherwise an empty Object.
*/
- JSFloorPlan3D.selectRoom = function( p, floor )
+ JSFloorPlan3D.prototype.selectRoom = function( p, floor )
{
var thisFloor = rooms[floor];
for( var room in thisFloor )
@@ -1191,7 +1216,7 @@
* @param {Number} h Height in building space used for mapping
* @return {THREE.Vector3} Point in building space
*/
- JSFloorPlan3D.sceen2building = function( x, y, h )
+ JSFloorPlan3D.prototype.sceen2building = function( x, y, h )
{
var vector = new THREE.Vector3( (x / WIDTH)*2-1, -(y / HEIGHT)*2+1, 0.5 );
projector.unprojectVector( vector, camera );
@@ -1207,7 +1232,7 @@
* @return {Object} Hash with keys <code>x</code> and <code>y</code> in screen
* coordinates
*/
- JSFloorPlan3D.building2screen = function( p )
+ JSFloorPlan3D.prototype.building2screen = function( p )
{
var screen = p.clone();
projector.projectVector( screen, camera );
@@ -1221,12 +1246,19 @@
* @param {Function} event.data.callback This callback function will be called
* after the mouse event was translated
*/
- JSFloorPlan3D.translateMouseEvent = function( event )
+ JSFloorPlan3D.prototype.translateMouseEvent = function( event )
{
- var thisFloor = JSFloorPlan3D.buildingProperties.floor[showStates.showFloor];
+ var tJSFloorPlan3D = event.data.JSFloorPlan3D;
+ var thisFloor = tJSFloorPlan3D.buildingProperties.floor[showStates.showFloor];
var height = thisFloor.heightOfGround + thisFloor.height;
- var intersec = JSFloorPlan3D.sceen2building( event.offsetX, event.offsetY, height );
- event.room = JSFloorPlan3D.selectRoom( intersec, showStates.showFloor );
+ var intersec = tJSFloorPlan3D.sceen2building( event.offsetX, event.offsetY, height );
+ event.room = tJSFloorPlan3D.selectRoom( intersec, showStates.showFloor );
if( event.data.callback ) event.data.callback( event );
}
-};//());
\ No newline at end of file
+
+ };
+ // library local variables
+
+ //Expose dQuery object to window as dQuery or JSlib
+ window.JSFloorPlan3D = JSFloorPlan3D;
+})(window);
\ No newline at end of file
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-02-19 23:12:54 UTC (rev 710)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-02-20 21:43:31 UTC (rev 711)
@@ -27,18 +27,6 @@
* @module JS FloorPlan 3D Example
*/
-j = new JSFLOORPLAN3D();
-function loadFloorplan()
-{
- $.ajax({
- url: 'floorplan01.xml',
- success: j.parseXMLFloorPlan,
- dataType: 'xml',
- async: false
- });
-}
-
-
function three_init()
{
return;
@@ -229,10 +217,6 @@
j.moveTo( showStates['showFloor'], roll, tilt, dist, target );
}
/////////////////////////////////////////////////////////////////////////////
-$(function() {
- three_init();
- $('#top_level').css('border','1px solid black').click( {callback:handleMouseClickEvent}, j.translateMouseEvent );
-});
/////////////////////////////////////////////////////////////////////////////
// setup script here:
var sc = 40; // overall scaling
@@ -269,6 +253,8 @@
var t_25d_after_sort;
var t_25d_end;
+j = new JSFloorPlan3D();
+
function init()
{
$('input').change(function(e){
@@ -292,7 +278,8 @@
showStates[ this.name ] = this.value; // init
});
- loadFloorplan();
+ //loadFloorplan();
+ j.loadFloorPlan('floorplan_demo.xml');
target.x = j.buildingProperties.x_center;
target.y = j.buildingProperties.y_center;
createSlider();
@@ -636,4 +623,9 @@
azimuth: azimuth * 180/Math.PI,
altitude: Math.atan2( sin_a, azimuth ) * 180/Math.PI
};
-}
\ No newline at end of file
+}
+
+$(function() {
+ three_init();
+ $('#top_level').css('border','1px solid black').click( {callback:handleMouseClickEvent,JSFloorPlan3D:j}, j.translateMouseEvent );
+});
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-05-01 11:35:38
|
Revision: 776
http://openautomation.svn.sourceforge.net/openautomation/?rev=776&view=rev
Author: mayerch
Date: 2012-05-01 11:35:32 +0000 (Tue, 01 May 2012)
Log Message:
-----------
Added ability to call a callback function during each animation step
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-04-30 21:05:40 UTC (rev 775)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-05-01 11:35:32 UTC (rev 776)
@@ -1250,11 +1250,12 @@
* @param {THREE.Vector3} target The point to look at (only <code>x</code>
* and <code>y</code> are used the <code>z</code>
* is taken from the parameter <code>floor</code>
+ * @param {Function} animateFn (optional) Function to call during each animation step
* @param {Function} delayedFn (optional) Function to call after animation is
* finished
* @param {Bool} animate Animate unless set to false
*/
- this.moveTo = function( floor, azimut, elevation, distance, target, delayedFn, animate )
+ this.moveTo = function( floor, azimut, elevation, distance, target, animateFn, delayedFn, animate )
{
if( noSetup ) setup3D( this.buildingProperties.Object3D );
@@ -1328,6 +1329,7 @@
setupCamera( showStates.currentAzimut, showStates.currentElevation, showStates.currentDistance, showStates.currentTarget );
renderer.render( scene, camera );
+ if( animateFn ) animateFn();
if( !done )
window.requestAnimationFrame( doMove );
@@ -1382,7 +1384,7 @@
var f = self.buildingProperties.floor.length-1;
for( ; f >= 0; f-- ) self.hideFloor( f, minFloor <= f && f <= maxFloor );
}
- this.moveTo( floor, showStates.currentAzimut, showStates.currentElevation, dist, target,
+ this.moveTo( floor, showStates.currentAzimut, showStates.currentElevation, dist, target, undefined,
function(){
if( hideOtherFloors )
{
Modified: JSFloorPlan/trunk/src/jsfloorplan_example_helper.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-04-30 21:05:40 UTC (rev 775)
+++ JSFloorPlan/trunk/src/jsfloorplan_example_helper.js 2012-05-01 11:35:32 UTC (rev 776)
@@ -29,7 +29,7 @@
function handleMouseClickEvent( event )
{
- target = j.moveToRoom( j.getState('showFloor'), event.room.room );
+ target = j.moveToRoom( j.getState('showFloor'), event.room.room, true );
updateSlider();
}
/////////////////////////////////////////////////////////////////////////////
@@ -129,12 +129,12 @@
});
target.z = j.buildingProperties.floor[ j.getState( 'showFloor' ) ].heightOfGround +
j.buildingProperties.floor[ j.getState( 'showFloor' ) ].height / 2;
- j.moveTo( j.getState( 'showFloor' ), roll, tilt, dist, target, function(){
+ j.moveTo( j.getState( 'showFloor' ), roll, tilt, dist, target, undefined, function(){
$( j.buildingProperties.floor ).each( function( number ){
j.hideFloor( number, j.getState( 'showFloor' ) == number );
});
j.show3D( roll, tilt, dist, target );
- });
+ }, true );
return false;
break;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|