|
From: <ma...@us...> - 2011-12-18 15:59:30
|
Revision: 593
http://openautomation.svn.sourceforge.net/openautomation/?rev=593&view=rev
Author: mayerch
Date: 2011-12-18 15:59:22 +0000 (Sun, 18 Dec 2011)
Log Message:
-----------
Whitespace (only!) fix
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 15:45:26 UTC (rev 592)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 15:59:22 UTC (rev 593)
@@ -31,7 +31,7 @@
{
/**
* The JSFLOORPLAN3D global namespace object. If JSFLOORPLAN3D is already
- * defined, the existing JSFLOORPLAN3D object will not be overwritten so
+ * defined, the existing JSFLOORPLAN4D object will not be overwritten so
* that defined namespaces are preserved.
* @class JSFLOORPLAN3D
* @static
@@ -40,665 +40,661 @@
}
JSFLOORPLAN3D= function () {
-var JSFloorPlan3D = this;
-// don't change anything below:
-var ELEMENT_NODE = 1;
-
-// calculate the distance between two cartesian 2D points
-function calcLength2D( start, end )
-{
- return Math.sqrt( (end.x-start.x)*(end.x-start.x) +
- (end.y-start.y)*(end.y-start.y) );
-}
-
-// calculate the rotation of a cartesian 2D point around the center
-function rotate2D( angle, point, center )
-{
- var s = Math.sin( angle );
- var c = Math.cos( angle );
- var ret = new Object;
- ret.x = center.x + c * (point.x-center.x) - s * (point.y-center.y);
- ret.y = center.y + s * (point.x-center.x) + c * (point.y-center.y);
- return ret;
-}
-
-// calculate the rotation of a cartesian 2D point around the center
-// but with given sin and cos of the angle
-function rotate2D( s, c, point, center )
-{
- var ret = new Object;
- ret.x = center.x + c * (point.x-center.x) - s * (point.y-center.y);
- ret.y = center.y + s * (point.x-center.x) + c * (point.y-center.y);
- return ret;
-}
-
-// calculate the translation of a cartesian 2D point
-function translate2D( point, translation )
-{
- var ret = new Object;
- ret.x = point.x + translation.x;
- ret.y = point.y + translation.y;
- return ret;
-}
-
-// sort two 2D unit(!) vectors clockwise
-function vecSort( a, b )
-{
- var pseudoangle_a = a.y>=0 ? (1-a.x) : (a.x+3);
- var pseudoangle_b = b.y>=0 ? (1-b.x) : (b.x+3);
- return pseudoangle_a - pseudoangle_b;
-}
-
-//function loadFloorplan()
-//{
-// $.get('floorplan01.xml', parseXMLFloorPlan, 'xml');
-//}
-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;
-
-//return { parseXMLFloorPlan: function( xmlDoc )
-JSFloorPlan3D.parseXMLFloorPlan = function( xmlDoc )
-{
- noFloorplan = false;
-
- var floorCount = -1;
- var heightOfGround = 0; // the base level of the current floor
+ var JSFloorPlan3D = this;
+ // don't change anything below:
+ var ELEMENT_NODE = 1;
- // basic check if the document seems right
- // this could be avoided if the XML file would be validated
- // with a DTD
- var building;
- if( 'building' == xmlDoc.documentElement.tagName )
- building = xmlDoc.documentElement;
- else
- return alert( "ERROR: Not a valid floor plan! " +
- "Expected: 'building', found '" + xmlDoc.documentElement.tagName + "'" );
-
- // now we are sure to have a sensible file
- // => iterate over all floors
- for( var i=0; i < building.childNodes.length; i++ )
+ // calculate the distance between two cartesian 2D points
+ function calcLength2D( start, end )
{
- floor = building.childNodes[i];
- if (floor.nodeType != ELEMENT_NODE) continue;
-
- if( floor.tagName == 'textures' )
- {
- parseTextures( floor );
- continue;
- }
-
- if( floor.tagName != 'floor' )
- return alert( "ERROR: Not a valid floor plan! " +
- "Expected: 'floor', found '" + floor.tagName + "'" );
+ return Math.sqrt( (end.x-start.x)*(end.x-start.x) +
+ (end.y-start.y)*(end.y-start.y) );
+ }
+
+ // calculate the rotation of a cartesian 2D point around the center
+ function rotate2D( angle, point, center )
+ {
+ var s = Math.sin( angle );
+ var c = Math.cos( angle );
+ var ret = new Object;
+ ret.x = center.x + c * (point.x-center.x) - s * (point.y-center.y);
+ ret.y = center.y + s * (point.x-center.x) + c * (point.y-center.y);
+ return ret;
+ }
+
+ // calculate the rotation of a cartesian 2D point around the center
+ // but with given sin and cos of the angle
+ function rotate2D( s, c, point, center )
+ {
+ var ret = new Object;
+ ret.x = center.x + c * (point.x-center.x) - s * (point.y-center.y);
+ ret.y = center.y + s * (point.x-center.x) + c * (point.y-center.y);
+ return ret;
+ }
+
+ // calculate the translation of a cartesian 2D point
+ function translate2D( point, translation )
+ {
+ var ret = new Object;
+ ret.x = point.x + translation.x;
+ ret.y = point.y + translation.y;
+ return ret;
+ }
+
+ // sort two 2D unit(!) vectors clockwise
+ function vecSort( a, b )
+ {
+ var pseudoangle_a = a.y>=0 ? (1-a.x) : (a.x+3);
+ var pseudoangle_b = b.y>=0 ? (1-b.x) : (b.x+3);
+ return pseudoangle_a - pseudoangle_b;
+ }
+
+ 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;
+
+ //return { parseXMLFloorPlan: function( xmlDoc )
+ JSFloorPlan3D.parseXMLFloorPlan = function( xmlDoc )
+ {
+ noFloorplan = false;
- floorCount++;
- JSFloorPlan3D.buildingProperties.floor[floorCount] = {};
+ var floorCount = -1;
+ var heightOfGround = 0; // the base level of the current floor
- var floorName = floor.getAttribute('name');
- JSFloorPlan3D.buildingProperties.floor[floorCount].name = floorName;
+ // basic check if the document seems right
+ // this could be avoided if the XML file would be validated
+ // with a DTD
+ var building;
+ if( 'building' == xmlDoc.documentElement.tagName )
+ building = xmlDoc.documentElement;
+ else
+ return alert( "ERROR: Not a valid floor plan! " +
+ "Expected: 'building', found '" + xmlDoc.documentElement.tagName + "'" );
- var floorheight = Number( floor.getAttribute('height') );
- JSFloorPlan3D.buildingProperties.floor[floorCount].height = floorheight;
- JSFloorPlan3D.buildingProperties.floor[floorCount].heightOfGround = heightOfGround;
-
- var floorWallsStart = 0;// floorWalls.length; <- not defined here yet...
-
- // iterate over the content of this floor
- for( var j=0; j < floor.childNodes.length; j++ )
+ // now we are sure to have a sensible file
+ // => iterate over all floors
+ for( var i=0; i < building.childNodes.length; i++ )
{
- floorNode = floor.childNodes[j];
- if (floorNode.nodeType != ELEMENT_NODE) continue;
-
- switch( floorNode.tagName )
+ floor = building.childNodes[i];
+ if (floor.nodeType != ELEMENT_NODE) continue;
+
+ if( floor.tagName == 'textures' )
{
- case 'nodes':
- parseFloorNodes( floorNode, floorheight );
- break;
-
- case 'walls':
- parseFloorWalls( floorNode );
- break;
-
- case 'rooms':
- parseFloorRooms( floorNode, floorCount );
- break;
- }
- }
-
- // now the content of the floor is stored in easily
- // accessable objects
- // => derive the necessary information
-
- // group all elements on this floor
- var Object3D = new THREE.Object3D();
-
- // add the information to each node to which nodes it's connected to
- for( var j = floorWallsStart; j < floorWalls.length; j++ )
- {
- // note: the ID is shifted by one to avoid an ID of zero
- // as that wouldn't allow me anymore to distinguish
- // start and stop
- floorNodes[ floorWalls[j].start ].neighbour.push( j+1 );
- floorNodes[ floorWalls[j].end ].neighbour.push( -j-1 );
- }
-
- var nodeGroup = new THREE.Object3D(); nodeGroup.name = 'nodeGroup';
- for( var id in floorNodes )
- {
- // calculate the vectors showing to the neighbours
- var vectors = new Array();
- var start = floorNodes[id];
+ parseTextures( floor );
+ continue;
+ }
- // show them on request as spheres
- var sphere = new THREE.Mesh( new THREE.SphereGeometry(0.1, 4, 4), sphereMaterial);
- sphere.position = new THREE.Vector3( start.x, start.y, heightOfGround );
- nodeGroup.add(sphere);
+ if( floor.tagName != 'floor' )
+ return alert( "ERROR: Not a valid floor plan! " +
+ "Expected: 'floor', found '" + floor.tagName + "'" );
- for( var j=0; j<floorNodes[id].neighbour.length; j++ )
- {
- var vec = new Object;
- vec.id = floorNodes[id].neighbour[j];
- var end;
- if( vec.id < 0 )
- end = floorNodes[ floorWalls[ -vec.id-1 ].start ];
- else
- end = floorNodes[ floorWalls[ vec.id-1 ].end ];
-
- length = calcLength2D( start, end );
- vec.x = (end.x - start.x) / length;
- vec.y = (end.y - start.y) / length;
- vectors.push( vec );
- }
-
- // sort them clockwise
- vectors.sort( vecSort );
-
- // calculate the cutting points of the walls at this node id
- for( var j=0; j<vectors.length; j++ )
- {
- var jj = (j+1) % vectors.length;
- var wj = Math.abs(vectors[j ].id)-1;
- var wjj = Math.abs(vectors[jj].id)-1;
- var dj = floorWalls[wj ].thickness/2;
- var djj = floorWalls[wjj].thickness/2;
- if( floorWalls[wj ].startOffset && vectors[j ].id > 0 )
- dj += floorWalls[wj].startOffset;
- if( floorWalls[wj ].endOffset && vectors[j ].id < 0 )
- dj += floorWalls[wj].endOffset;
- if( floorWalls[wjj].startOffset && vectors[jj].id > 0 )
- djj += -floorWalls[wjj].startOffset;
- if( floorWalls[wjj].endOffset && vectors[jj].id < 0 )
- djj += -floorWalls[wjj].endOffset;
-
- vertex = new Object;
- vertex.x = vectors[j].x*djj + vectors[jj].x*dj;
- vertex.y = vectors[j].y*djj + vectors[jj].y*dj;
- var l = vectors[j].x*vectors[jj].y - vectors[j].y*vectors[jj].x;
- if( Math.abs( l ) < 1e-5 )
- { // the angle between the two vectors is exactly 180°
- // i.e. a straight wall...
- if( Math.abs( dj - djj ) < 1e-5 )
- { // at least the walls have the same thickness...
- vertex.x = start.x - vectors[j].y*dj;
- vertex.y = start.y + vectors[j].x*dj;
- } else {
- alert( "ERROR: A straight wall with different thicknesses " +
- "is currently not supported!" );
- // but we still try our best...
- vertex.x = start.x - vectors[j].y*(dj+djj)/2;
- vertex.y = start.y + vectors[j].x*(dj+djj)/2;
- }
- } else {
- vertex.x = start.x + vertex.x / l;
- vertex.y = start.y + vertex.y / l;
- }
-
- if( vectors[j ].id < 0 )
- floorWalls[wj ].startVertex.push( vertices.length );
- else
- floorWalls[wj ].endVertex.push( vertices.length );
-
- if( 1 == vectors.length )
- {
- var additional = new Object;
- additional.x = 2 * start.x - vertex.x;
- additional.y = 2 * start.y - vertex.y;
- vertices.push( additional );
- }
-
- if( vectors[jj].id < 0 )
- floorWalls[wjj].startVertex.push( vertices.length );
- else
- floorWalls[wjj].endVertex.push( vertices.length );
-
- vertices.push( vertex );
- }
- } // end for( var id in floorNodes )
- Object3D.add( nodeGroup );
-
- // show walls
- var lineGroup = new THREE.Object3D(); lineGroup.name = 'lineGroup';
- var wallGroup = new THREE.Object3D(); wallGroup.name = 'wallGroup';
- for( var j = floorWallsStart; j<floorWalls.length; j++ )
- {
- var vs = floorNodes[ floorWalls[j].start ];
- var ve = floorNodes[ floorWalls[j].end ];
- var lineGeo = new THREE.Geometry();
- lineGeo.vertices.push( new THREE.Vertex( new THREE.Vector3( vs.x, vs.y, heightOfGround ) ) );
- lineGeo.vertices.push( new THREE.Vertex( new THREE.Vector3( ve.x, ve.y, heightOfGround ) ) );
- lineGroup.add( new THREE.Line( lineGeo, lineMaterial ) );
+ floorCount++;
+ JSFloorPlan3D.buildingProperties.floor[floorCount] = {};
- var s1 = vertices[ floorWalls[j].startVertex[0] ];
- var e1 = vertices[ floorWalls[j].endVertex [0] ];
- var s2 = vertices[ floorWalls[j].startVertex[1] ];
- var e2 = vertices[ floorWalls[j].endVertex [1] ];
+ var floorName = floor.getAttribute('name');
+ JSFloorPlan3D.buildingProperties.floor[floorCount].name = floorName;
- // check that the start and end points aren't twisted
- var v1 = new Object; v1.x = s1.x-s2.x; v1.y = s1.y-s2.y;
- var v2 = new Object; v2.x = e1.x-s2.x; v2.y = e1.y-s2.y;
- var v3 = new Object; v3.x = e1.x-e2.x; v3.y = e1.y-e2.y;
- if( (v1.x*v2.y - v1.y*v2.x)*(v2.x*v3.y - v2.y*v3.x) > 0 )
+ var floorheight = Number( floor.getAttribute('height') );
+ JSFloorPlan3D.buildingProperties.floor[floorCount].height = floorheight;
+ JSFloorPlan3D.buildingProperties.floor[floorCount].heightOfGround = heightOfGround;
+
+ var floorWallsStart = 0;// floorWalls.length; <- not defined here yet...
+
+ // iterate over the content of this floor
+ for( var j=0; j < floor.childNodes.length; j++ )
{
- e1 = vertices [ floorWalls[j].endVertex[1] ];
- e2 = vertices [ floorWalls[j].endVertex[0] ];
+ floorNode = floor.childNodes[j];
+ if (floorNode.nodeType != ELEMENT_NODE) continue;
+
+ switch( floorNode.tagName )
+ {
+ case 'nodes':
+ parseFloorNodes( floorNode, floorheight );
+ break;
+
+ case 'walls':
+ parseFloorWalls( floorNode );
+ break;
+
+ case 'rooms':
+ parseFloorRooms( floorNode, floorCount );
+ break;
+ }
}
- var sm = floorNodes[ floorWalls[j].start ];
- var em = floorNodes[ floorWalls[j].end ];
- var sh = floorNodes[ floorWalls[j].start ].z ;
- var eh = floorNodes[ floorWalls[j].end ].z ;
- var wallSideOrder = (s2.x-s1.x)*(e1.y-s1.y) - (s2.y-s1.y)*(e1.x-s1.x);
- var geometry = new THREE.Geometry();
- var normal1 = new THREE.Vector3(sm.y-em.y,-sm.x+em.x,0); // fixme? normalize
- var normal2 = new THREE.Vector3(1,0,0);
+ // now the content of the floor is stored in easily
+ // accessable objects
+ // => derive the necessary information
- var sourrounding = [ new poly2tri.Point(0,0), new poly2tri.Point(0,1), new poly2tri.Point(1,1), new poly2tri.Point(1,0) ];
- sourrounding[1].startEndMarker = 'start';
- sourrounding[2].startEndMarker = 'end';
- var holesToAdd = [];
+ // group all elements on this floor
+ var Object3D = new THREE.Object3D();
- if( floorWalls[j].holes.length )
+ // add the information to each node to which nodes it's connected to
+ for( var j = floorWallsStart; j < floorWalls.length; j++ )
{
- var holes = floorWalls[j].holes;
- for( var h = 0; h < holes.length; h++ )
+ // note: the ID is shifted by one to avoid an ID of zero
+ // as that wouldn't allow me anymore to distinguish
+ // start and stop
+ floorNodes[ floorWalls[j].start ].neighbour.push( j+1 );
+ floorNodes[ floorWalls[j].end ].neighbour.push( -j-1 );
+ }
+
+ var nodeGroup = new THREE.Object3D(); nodeGroup.name = 'nodeGroup';
+ for( var id in floorNodes )
+ {
+ // calculate the vectors showing to the neighbours
+ var vectors = new Array();
+ var start = floorNodes[id];
+
+ // show them on request as spheres
+ var sphere = new THREE.Mesh( new THREE.SphereGeometry(0.1, 4, 4), sphereMaterial);
+ sphere.position = new THREE.Vector3( start.x, start.y, heightOfGround );
+ nodeGroup.add(sphere);
+
+ for( var j=0; j<floorNodes[id].neighbour.length; j++ )
{
- var wallLength = calcLength2D( sm, em );
- var fLeft = holes[h].distance / wallLength;
- var fRight = (holes[h].distance + holes[h].width) / wallLength;
- if( fLeft <= 0.0 ) fLeft = 0.001; //// FIXME - actually the config file is bad. Leave at least 1mm wall
- if( fRight >= 1.0 ) fRight = 0.999; //// FIXME - actually the config file is bad. Leave at least 1mm wall
- var lintel = (sh - holes[h].lintel) / sh;
- var paparet = holes[h].paparet / sh;
- if( 1 == lintel )
- {
- // not a hole, the sourrounding goes to the groud...
-
- if( paparet == 0 ) continue; // FIXME: Assume paparet != 0 - otherwise it should be two walls...
-
- sourrounding.splice( -2, 0, new poly2tri.Point(fLeft,1), new poly2tri.Point(fLeft,paparet), new poly2tri.Point(fRight,paparet), new poly2tri.Point(fRight,1) );
- continue;
+ var vec = new Object;
+ vec.id = floorNodes[id].neighbour[j];
+ var end;
+ if( vec.id < 0 )
+ end = floorNodes[ floorWalls[ -vec.id-1 ].start ];
+ else
+ end = floorNodes[ floorWalls[ vec.id-1 ].end ];
+
+ length = calcLength2D( start, end );
+ vec.x = (end.x - start.x) / length;
+ vec.y = (end.y - start.y) / length;
+ vectors.push( vec );
+ }
+
+ // sort them clockwise
+ vectors.sort( vecSort );
+
+ // calculate the cutting points of the walls at this node id
+ for( var j=0; j<vectors.length; j++ )
+ {
+ var jj = (j+1) % vectors.length;
+ var wj = Math.abs(vectors[j ].id)-1;
+ var wjj = Math.abs(vectors[jj].id)-1;
+ var dj = floorWalls[wj ].thickness/2;
+ var djj = floorWalls[wjj].thickness/2;
+ if( floorWalls[wj ].startOffset && vectors[j ].id > 0 )
+ dj += floorWalls[wj].startOffset;
+ if( floorWalls[wj ].endOffset && vectors[j ].id < 0 )
+ dj += floorWalls[wj].endOffset;
+ if( floorWalls[wjj].startOffset && vectors[jj].id > 0 )
+ djj += -floorWalls[wjj].startOffset;
+ if( floorWalls[wjj].endOffset && vectors[jj].id < 0 )
+ djj += -floorWalls[wjj].endOffset;
+
+ vertex = new Object;
+ vertex.x = vectors[j].x*djj + vectors[jj].x*dj;
+ vertex.y = vectors[j].y*djj + vectors[jj].y*dj;
+ var l = vectors[j].x*vectors[jj].y - vectors[j].y*vectors[jj].x;
+ if( Math.abs( l ) < 1e-5 )
+ { // the angle between the two vectors is exactly 180°
+ // i.e. a straight wall...
+ if( Math.abs( dj - djj ) < 1e-5 )
+ { // at least the walls have the same thickness...
+ vertex.x = start.x - vectors[j].y*dj;
+ vertex.y = start.y + vectors[j].x*dj;
+ } else {
+ alert( "ERROR: A straight wall with different thicknesses " +
+ "is currently not supported!" );
+ // but we still try our best...
+ vertex.x = start.x - vectors[j].y*(dj+djj)/2;
+ vertex.y = start.y + vectors[j].x*(dj+djj)/2;
}
- if( 0 == paparet )
+ } else {
+ vertex.x = start.x + vertex.x / l;
+ vertex.y = start.y + vertex.y / l;
+ }
+
+ if( vectors[j ].id < 0 )
+ floorWalls[wj ].startVertex.push( vertices.length );
+ else
+ floorWalls[wj ].endVertex.push( vertices.length );
+
+ if( 1 == vectors.length )
{
- // not a hole, the sourrounding goes to the groud...
-
- // lintel == 1 can't happen, it's checked in the if clause above
-
- 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;
+ var additional = new Object;
+ additional.x = 2 * start.x - vertex.x;
+ additional.y = 2 * start.y - vertex.y;
+ vertices.push( additional );
}
- holesToAdd.push( [new poly2tri.Point(fLeft,paparet), new poly2tri.Point(fRight,paparet), new poly2tri.Point(fRight,lintel), new poly2tri.Point(fLeft,lintel)] );
+ if( vectors[jj].id < 0 )
+ floorWalls[wjj].startVertex.push( vertices.length );
+ else
+ floorWalls[wjj].endVertex.push( vertices.length );
+
+ vertices.push( vertex );
}
- } // if( floorWalls[j].holes.length )
- var swctx = new poly2tri.SweepContext( sourrounding.slice(0) ); // pass a copy of sourrounding
- for( var htA = 0; htA < holesToAdd.length; htA++ )
- swctx.AddHole( holesToAdd[htA] );
+ } // end for( var id in floorNodes )
+ Object3D.add( nodeGroup );
- // Do the triangulation - FIXME: handle exceptions, don't ignore them...
- try {
- poly2tri.sweep.Triangulate(swctx);
- }catch(err){}
-
- // mark all points to make sure that we don't need to double vertices
- for( var tp = 0; tp < swctx.point_count(); tp++ )
- swctx.GetPoint( tp ).id = tp;
-
- // translate poly2tri triangles to THREE.js faces:
- var p2tF = [];
- $.each(swctx.GetTriangles(), function(idx, val) {
- p2tF.push(new THREE.Face3(val.GetPoint(0).id, val.GetPoint(1).id, val.GetPoint(2).id));
- });
-
- Tvertices = swctx.points_;
- Tfaces = p2tF;
- var wall1vertices = [];
- var wall2vertices = [];
- var sId, eId;
- for( var v = 0; v < Tvertices.length; v++ )
+ // show walls
+ var lineGroup = new THREE.Object3D(); lineGroup.name = 'lineGroup';
+ var wallGroup = new THREE.Object3D(); wallGroup.name = 'wallGroup';
+ for( var j = floorWallsStart; j<floorWalls.length; j++ )
{
- // 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;
- var e1f = 1-((e1.x-sm.x)*(em.x-sm.x) + (e1.y-sm.y)*(em.y-sm.y))*lSquaredInv;
- var s2f = 1-((s2.x-sm.x)*(em.x-sm.x) + (s2.y-sm.y)*(em.y-sm.y))*lSquaredInv;
- var e2f = 1-((e2.x-sm.x)*(em.x-sm.x) + (e2.y-sm.y)*(em.y-sm.y))*lSquaredInv;
+ var vs = floorNodes[ floorWalls[j].start ];
+ var ve = floorNodes[ floorWalls[j].end ];
+ var lineGeo = new THREE.Geometry();
+ lineGeo.vertices.push( new THREE.Vertex( new THREE.Vector3( vs.x, vs.y, heightOfGround ) ) );
+ lineGeo.vertices.push( new THREE.Vertex( new THREE.Vector3( ve.x, ve.y, heightOfGround ) ) );
+ lineGroup.add( new THREE.Line( lineGeo, lineMaterial ) );
- var tv = Tvertices[v];
- var tvx1 = Math.min( 1.0, Math.max( 0.0, (tv.x - s1f) * (e1f - s1f) ) ); // map between s1 and e1
- var tvx2 = Math.min( 1.0, Math.max( 0.0, (tv.x - s2f) * (e2f - s2f) ) ); // map between s2 and e2
- var x1 = s1.x * tvx1 + e1.x * (1 - tvx1);
- 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 );
- var z = heightOfGround + sh*tv.y;
- if( wallSideOrder > 0 )
+ var s1 = vertices[ floorWalls[j].startVertex[0] ];
+ var e1 = vertices[ floorWalls[j].endVertex [0] ];
+ var s2 = vertices[ floorWalls[j].startVertex[1] ];
+ var e2 = vertices[ floorWalls[j].endVertex [1] ];
+
+ // check that the start and end points aren't twisted
+ var v1 = new Object; v1.x = s1.x-s2.x; v1.y = s1.y-s2.y;
+ var v2 = new Object; v2.x = e1.x-s2.x; v2.y = e1.y-s2.y;
+ var v3 = new Object; v3.x = e1.x-e2.x; v3.y = e1.y-e2.y;
+ if( (v1.x*v2.y - v1.y*v2.x)*(v2.x*v3.y - v2.y*v3.x) > 0 )
{
- wall1vertices.push(new THREE.Vertex(new THREE.Vector3(x1,y1,z), normal1));
- wall2vertices.push(new THREE.Vertex(new THREE.Vector3(x2,y2,z), normal1));
- } else {
- wall1vertices.push(new THREE.Vertex(new THREE.Vector3(x2,y2,z), normal1));
- wall2vertices.push(new THREE.Vertex(new THREE.Vector3(x1,y1,z), normal1));
+ e1 = vertices [ floorWalls[j].endVertex[1] ];
+ e2 = vertices [ floorWalls[j].endVertex[0] ];
}
- if( 'startEndMarker' in tv )
+ var sm = floorNodes[ floorWalls[j].start ];
+ var em = floorNodes[ floorWalls[j].end ];
+ var sh = floorNodes[ floorWalls[j].start ].z ;
+ var eh = floorNodes[ floorWalls[j].end ].z ;
+ var wallSideOrder = (s2.x-s1.x)*(e1.y-s1.y) - (s2.y-s1.y)*(e1.x-s1.x);
+ var geometry = new THREE.Geometry();
+
+ var normal1 = new THREE.Vector3(sm.y-em.y,-sm.x+em.x,0); // fixme? normalize
+ var normal2 = new THREE.Vector3(1,0,0);
+
+ var sourrounding = [ new poly2tri.Point(0,0), new poly2tri.Point(0,1), new poly2tri.Point(1,1), new poly2tri.Point(1,0) ];
+ sourrounding[1].startEndMarker = 'start';
+ sourrounding[2].startEndMarker = 'end';
+ var holesToAdd = [];
+
+ if( floorWalls[j].holes.length )
{
- if( 'start' == tv.startEndMarker )
+ var holes = floorWalls[j].holes;
+ for( var h = 0; h < holes.length; h++ )
{
- sId = wall1vertices.length - 1;
+ var wallLength = calcLength2D( sm, em );
+ var fLeft = holes[h].distance / wallLength;
+ var fRight = (holes[h].distance + holes[h].width) / wallLength;
+ if( fLeft <= 0.0 ) fLeft = 0.001; //// FIXME - actually the config file is bad. Leave at least 1mm wall
+ if( fRight >= 1.0 ) fRight = 0.999; //// FIXME - actually the config file is bad. Leave at least 1mm wall
+ var lintel = (sh - holes[h].lintel) / sh;
+ var paparet = holes[h].paparet / sh;
+ if( 1 == lintel )
+ {
+ // not a hole, the sourrounding goes to the groud...
+
+ if( paparet == 0 ) continue; // FIXME: Assume paparet != 0 - otherwise it should be two walls...
+
+ sourrounding.splice( -2, 0, new poly2tri.Point(fLeft,1), new poly2tri.Point(fLeft,paparet), new poly2tri.Point(fRight,paparet), new poly2tri.Point(fRight,1) );
+ continue;
+ }
+ if( 0 == paparet )
+ {
+ // not a hole, the sourrounding goes to the groud...
+
+ // lintel == 1 can't happen, it's checked in the if clause above
+
+ 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 )
+ var swctx = new poly2tri.SweepContext( sourrounding.slice(0) ); // pass a copy of sourrounding
+ for( var htA = 0; htA < holesToAdd.length; htA++ )
+ swctx.AddHole( holesToAdd[htA] );
+
+ // Do the triangulation - FIXME: handle exceptions, don't ignore them...
+ try {
+ poly2tri.sweep.Triangulate(swctx);
+ }catch(err){}
+
+ // mark all points to make sure that we don't need to double vertices
+ for( var tp = 0; tp < swctx.point_count(); tp++ )
+ swctx.GetPoint( tp ).id = tp;
+
+ // translate poly2tri triangles to THREE.js faces:
+ var p2tF = [];
+ $.each(swctx.GetTriangles(), function(idx, val) {
+ p2tF.push(new THREE.Face3(val.GetPoint(0).id, val.GetPoint(1).id, val.GetPoint(2).id));
+ });
+
+ Tvertices = swctx.points_;
+ Tfaces = p2tF;
+ var wall1vertices = [];
+ var wall2vertices = [];
+ var sId, eId;
+ for( var v = 0; v < Tvertices.length; v++ )
+ {
+ // 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;
+ var e1f = 1-((e1.x-sm.x)*(em.x-sm.x) + (e1.y-sm.y)*(em.y-sm.y))*lSquaredInv;
+ var s2f = 1-((s2.x-sm.x)*(em.x-sm.x) + (s2.y-sm.y)*(em.y-sm.y))*lSquaredInv;
+ var e2f = 1-((e2.x-sm.x)*(em.x-sm.x) + (e2.y-sm.y)*(em.y-sm.y))*lSquaredInv;
+
+ var tv = Tvertices[v];
+ var tvx1 = Math.min( 1.0, Math.max( 0.0, (tv.x - s1f) * (e1f - s1f) ) ); // map between s1 and e1
+ var tvx2 = Math.min( 1.0, Math.max( 0.0, (tv.x - s2f) * (e2f - s2f) ) ); // map between s2 and e2
+ var x1 = s1.x * tvx1 + e1.x * (1 - tvx1);
+ 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 );
+ var z = heightOfGround + sh*tv.y;
+ if( wallSideOrder > 0 )
+ {
+ wall1vertices.push(new THREE.Vertex(new THREE.Vector3(x1,y1,z), normal1));
+ wall2vertices.push(new THREE.Vertex(new THREE.Vector3(x2,y2,z), normal1));
} else {
- eId = wall1vertices.length - 1;
+ wall1vertices.push(new THREE.Ver...
[truncated message content] |
|
From: <ma...@us...> - 2011-12-18 21:09:06
|
Revision: 597
http://openautomation.svn.sourceforge.net/openautomation/?rev=597&view=rev
Author: mayerch
Date: 2011-12-18 21:09:00 +0000 (Sun, 18 Dec 2011)
Log Message:
-----------
Inital set of comments
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 20:39:17 UTC (rev 596)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 21:09:00 UTC (rev 597)
@@ -26,32 +26,57 @@
* JSFloorPlan 3D library.
* @module JSFloorPlan3D
* @title JS Floor Plan 3D
+ * @reqires jQuery
*/
if (typeof JSFLOORPLAN3D == 'undefined' || !JSFLOORPLAN3D)
{
- /**
+ /*
* The JSFLOORPLAN3D global namespace object. If JSFLOORPLAN3D is already
- * defined, the existing JSFLOORPLAN4D object will not be overwritten so
+ * defined, the existing JSFLOORPLAN3D object will not be overwritten so
* that defined namespaces are preserved.
- * @class JSFLOORPLAN3D
- * @static
*/
var JSFLOORPLAN3D = {};
}
+/**
+ * @class JSFLOORPLAN3D
+ * @constructor FOO
+ */
JSFLOORPLAN3D= function () {
var JSFloorPlan3D = this;
- // don't change anything below:
+
+ /**
+ * Constant representing the ID of an ELEMENT_NODE
+ * @property ELEMENT_NODE
+ * @private
+ * @static
+ * @final
+ * @type Enum
+ */
var ELEMENT_NODE = 1;
- // calculate the distance between two cartesian 2D points
+ /**
+ * Calculate the distance between two cartesian 2D points.
+ * @method calcLength2D
+ * @private
+ * @param {Point} start
+ * @param {Point} end
+ */
function calcLength2D( start, end )
{
return Math.sqrt( (end.x-start.x)*(end.x-start.x) +
(end.y-start.y)*(end.y-start.y) );
}
- // calculate the rotation of a cartesian 2D point around the center
+ /**
+ * calculate the rotation of a cartesian 2D point around the center
+ * @method rotate2D
+ * @private
+ * @param {Float} angle Rotation angle
+ * @param {Point} point
+ * @param {Point} center
+ * @return {Point} new point containing the turned coordinates
+ */
function rotate2D( angle, point, center )
{
var s = Math.sin( angle );
@@ -62,8 +87,17 @@
return ret;
}
- // calculate the rotation of a cartesian 2D point around the center
- // but with given sin and cos of the angle
+ /**
+ * Calculate the rotation of a cartesian 2D point around the center
+ * but with given sin and cos of the angle.
+ * @method rotate2D
+ * @private
+ * @param {Float} s Sin of the rotation angle
+ * @param {Float} c Cos of the rotation angle
+ * @param {Point} point
+ * @param {Point} center
+ * @return {Point} new point containing the turned coordinates
+ */
function rotate2D( s, c, point, center )
{
var ret = new Object;
@@ -72,7 +106,14 @@
return ret;
}
- // calculate the translation of a cartesian 2D point
+ /**
+ * Calculate the translation of a cartesian 2D point.
+ * @method translate2D
+ * @private
+ * @param {Point} point
+ * @param {Point} translation vector
+ * @return {Point} new point containing the turned coordinates
+ */
function translate2D( point, translation )
{
var ret = new Object;
@@ -81,7 +122,14 @@
return ret;
}
- // sort two 2D unit(!) vectors clockwise
+ /**
+ * Sort two 2D unit(!) vectors clockwise
+ * @method vecSort
+ * @private
+ * @param {Point} a Unit vector
+ * @param {Point} b Unit vector
+ * @return {Float} Order
+ */
function vecSort( a, b )
{
var pseudoangle_a = a.y>=0 ? (1-a.x) : (a.x+3);
@@ -99,7 +147,11 @@
var noFloorplan = true;
- //return { parseXMLFloorPlan: function( xmlDoc )
+ /**
+ * Parse and create internal structure for the floor plan.
+ * @method parseXMLFloorPlan
+ * @param {XMLDom} xmlDoc
+ */
JSFloorPlan3D.parseXMLFloorPlan = function( xmlDoc )
{
noFloorplan = false;
@@ -491,7 +543,22 @@
//}
};
+ /**
+ * Store all nodes. This is an hash of points.
+ * @property floorNodes
+ * @type Hash
+ * @private
+ */
var floorNodes = new Object();
+ /**
+ * Fill the <code>floorNodes</code> structure with the nodes from the
+ * config file.
+ * @method parseFloorNodes
+ * @private
+ * @param {XMLDom} node
+ * @param {Float} floorheight The generic height of this floor that might be
+ * overwritten by individual nodes.
+ */
function parseFloorNodes( nodes, floorheight )
{
for( var i=0; i < nodes.childNodes.length; i++ )
@@ -527,7 +594,21 @@
}
}
+ /**
+ * Store all walls. This is an arry of <code>wall</code> objects.
+ * @property floorWalls
+ * @type Array
+ * @private
+ */
var floorWalls = new Array();
+
+ /**
+ * Fill the <code>floorWalls</code> structure with the wall elements from the
+ * config file.
+ * @method parseFloorWalls
+ * @private
+ * @param {XMLDom} nodeGroup
+ */
function parseFloorWalls( nodes )
{
for( var i=0; i < nodes.childNodes.length; i++ )
@@ -535,17 +616,58 @@
node = nodes.childNodes[i];
if (node.nodeType != ELEMENT_NODE) continue;
+ /**
+ * Contain all informations known about a wall.
+ * @class wall
+ * @for JSFLOORPLAN3D
+ */
var wall = new Object;
+ /**
+ * @property start ID of the start node
+ * @type ID-String
+ */
wall.start = node.getAttribute('start' );
+ /**
+ * @property startVertex
+ * @type Array
+ */
wall.startVertex = new Array;
+ /**
+ * @property startOffset Offset at the start node
+ * @type Array
+ */
wall.startOffset = Number( node.getAttribute('startoffset') );
+ /**
+ * @property end ID of the end node
+ * @type ID-String
+ */
wall.end = node.getAttribute('end' );
+ /**
+ * @property endVertex
+ * @type Array
+ */
wall.endVertex = new Array;
+ /**
+ * @property endOffset Offset at the end node
+ * @type Float
+ */
wall.endOffset = Number( node.getAttribute('endoffset' ) );
+ /**
+ * @property thickness Thickness of the wall
+ * @type Float
+ */
wall.thickness = Number( node.getAttribute('thickness' ) );
+ /**
+ * @property texture ID of the texture
+ * @type ID-String
+ */
wall.texture = node.getAttribute('texture' );
if( !wall.texture ) wall.texture = 0;
+ /**
+ * @property holes Array containing all holes in the wall
+ * @type Array
+ */
wall.holes = new Array;
for( var j=0; j < node.childNodes.length; j++ )
{
@@ -565,7 +687,22 @@
}
}
+ /**
+ * Store all rooms. This is an array of arrays of Objects.
+ * @property rooms
+ * @type Array
+ * @private
+ */
var rooms = new Array;
+ /**
+ * Fill the <code>rooms</code> array with the room elements from the
+ * config file.
+ * @method parseFloorRooms
+ * @for JSFLOORPLAN3D
+ * @private
+ * @param {XMLDom} nodeGroup
+ * @param {Integer} floor The floor number.
+ */
function parseFloorRooms( nodes, floor )
{
rooms[floor] = new Array;
@@ -601,6 +738,12 @@
}
//var textures = new Object();
+ /**
+ * Dummy routine to handle textures.
+ * @method parseTextures
+ * @private
+ * @param {XMLDom} nodes
+ */
function parseTextures( nodes )
{
return;
@@ -612,6 +755,11 @@
}
var noSetup = true;
+ /**
+ * Setup the whole scene
+ * @method setup3D
+ * @private
+ */
function setup3D()
{
if( noFloorplan ) return;
@@ -636,6 +784,15 @@
selectChange( 'showFloor' );
}
+ /**
+ * 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
+ */
JSFloorPlan3D.show3D = function( rotation, tilt )
{
if( noSetup ) setup3D();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2011-12-18 21:37:46
|
Revision: 598
http://openautomation.svn.sourceforge.net/openautomation/?rev=598&view=rev
Author: mayerch
Date: 2011-12-18 21:37:40 +0000 (Sun, 18 Dec 2011)
Log Message:
-----------
Sorting that private variables are at the top
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 21:09:00 UTC (rev 597)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 21:37:40 UTC (rev 598)
@@ -26,7 +26,7 @@
* JSFloorPlan 3D library.
* @module JSFloorPlan3D
* @title JS Floor Plan 3D
- * @reqires jQuery
+ * @reqires jQuery, Three.js
*/
if (typeof JSFLOORPLAN3D == 'undefined' || !JSFLOORPLAN3D)
{
@@ -43,9 +43,52 @@
* @constructor FOO
*/
JSFLOORPLAN3D= function () {
+ ////////////////////////////////////////////////////////////////////////////
+ // 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;
+
/**
+ * Store all nodes. This is an hash of points.
+ * @property floorNodes
+ * @type Hash
+ * @private
+ */
+ var floorNodes = new Object();
+
+ /**
+ * Store all walls. This is an arry of <code>wall</code> objects.
+ * @property floorWalls
+ * @type Array
+ * @private
+ */
+ var floorWalls = new Array();
+
+ /**
+ * Store all rooms. This is an array of arrays of Objects.
+ * @property rooms
+ * @type Array
+ * @private
+ */
+ var rooms = new Array;
+
+ /**
+ * Status if the 3D setup was done.
+ * @property noSetup
+ * @type Bool
+ * @private
+ */
+ var noSetup = true;
+
+ /**
* Constant representing the ID of an ELEMENT_NODE
* @property ELEMENT_NODE
* @private
@@ -55,6 +98,9 @@
*/
var ELEMENT_NODE = 1;
+ ////////////////////////////////////////////////////////////////////////////
+ // Definition of the private methods
+
/**
* Calculate the distance between two cartesian 2D points.
* @method calcLength2D
@@ -137,16 +183,6 @@
return pseudoangle_a - pseudoangle_b;
}
- 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;
-
/**
* Parse and create internal structure for the floor plan.
* @method parseXMLFloorPlan
@@ -544,13 +580,6 @@
};
/**
- * Store all nodes. This is an hash of points.
- * @property floorNodes
- * @type Hash
- * @private
- */
- var floorNodes = new Object();
- /**
* Fill the <code>floorNodes</code> structure with the nodes from the
* config file.
* @method parseFloorNodes
@@ -595,14 +624,6 @@
}
/**
- * Store all walls. This is an arry of <code>wall</code> objects.
- * @property floorWalls
- * @type Array
- * @private
- */
- var floorWalls = new Array();
-
- /**
* Fill the <code>floorWalls</code> structure with the wall elements from the
* config file.
* @method parseFloorWalls
@@ -688,13 +709,6 @@
}
/**
- * Store all rooms. This is an array of arrays of Objects.
- * @property rooms
- * @type Array
- * @private
- */
- var rooms = new Array;
- /**
* Fill the <code>rooms</code> array with the room elements from the
* config file.
* @method parseFloorRooms
@@ -754,7 +768,6 @@
}
}
- var noSetup = true;
/**
* Setup the whole scene
* @method setup3D
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2011-12-19 16:42:39
|
Revision: 599
http://openautomation.svn.sourceforge.net/openautomation/?rev=599&view=rev
Author: mayerch
Date: 2011-12-19 16:42:30 +0000 (Mon, 19 Dec 2011)
Log Message:
-----------
Document the used XML structure of the config file.
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-18 21:37:40 UTC (rev 598)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-19 16:42:30 UTC (rev 599)
@@ -24,8 +24,112 @@
/**
* The JSFLOORPLAN3D object is the single global object created by the
* JSFloorPlan 3D library.
- * @module JSFloorPlan3D
- * @title JS Floor Plan 3D
+ * <p/>
+ * The definition of the config file is:
+ * <pre>
+ * <?xml version="1.0" encoding="UTF-8"?>
+ * <building name="MyBuilding" orientation="45">
+ * <floor name="UG" height="2.44">
+ * <nodes>
+ * <node id="1" x="5.51" y="0" z="0.9" />
+ * ...
+ * </nodes>
+ * <walls>
+ * <wall start="1" end="2" thickness=".24" texture="wall">
+ * <hole id="door01" distance="0.3" width="0.88" paparet="0.0" lintel="0.2" />
+ * ...
+ * </wall>
+ * ...
+ * </walls>
+ * <rooms>
+ * <room name="Bad">
+ * <zone name="all" onclick="alert('Bad')">
+ * <corner nodeid="1" />
+ * ...
+ * </zone>
+ * ...
+ * </room>
+ * </rooms>
+ * </floor>
+ * ...
+ * <textues>
+ * <texture />
+ * ...
+ * </textures>
+ * </building>
+ * </pre>
+ *
+ * The elements used are:
+ * <dl>
+ * <dt><code><b><building></b></code></dt>
+ * <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>
+ * </ul>
+ * </dd>
+ * <dt><code><b><floor></b></code></dt>
+ * <dd>The <code>floor</code> element contains all relevant information
+ * about one floor of the building. The <code>name</code> attribute
+ * gives this floor its name and the <code>height</code> attribute
+ * defines the (maximum) height.
+ * </dd>
+ * <dt><code><b><nodes></b></code></dt>
+ * <dd>The contianer to contain all <code>node</code> elements of the floor.
+ * </dd>
+ * <dt><code><b><node></b></code></dt>
+ * <dd>A <code>node</code> is a point in x/y space where walls meet. It's the
+ * middle of all walls. If the walls have different thicknesses it might
+ * be necessary got define an offset in the corresponding <code>wall</code>
+ * element.<br />
+ * The <code>z</code> is optional and needed if this point of meeting
+ * walls is lower than the usual wall height. This might be used for a
+ * balustrade.
+ * </dd>
+ * <dt><code><b><walls></b></code></dt>
+ * <dd>The contianer to contain all <code>wall</code> elements of the floor.
+ * </dd>
+ * <dt><code><b><wall></b></code></dt>
+ * <dd>The <code>wall</code> element defines one visible wall that is spanned
+ * between the nodes with the IDs defined by the attributes
+ * <code>start</code> and <code>end</code>. The wall thickness is
+ * defined by the attribute <code>thickness</code>
+ * </dd>
+ * <dt><code><b><hole></b></code></dt>
+ * <dd>The <code>hole</code> element defines a hole in the wall, e.g. for a
+ * door or a window. It starts from the start node after
+ * <code>distance</code> meters and has a width as defined by the
+ * <code>width</code> attribute. The bottom is defined by the
+ * <code>paparet</code> attribute (so it's usually 0.0 for a door) and
+ * the top is defined by the <code>lintel</code> attribute.
+ * </dd>
+ * <dt><code><b><rooms></b></code></dt>
+ * <dd>The contianer of all rooms in this floor.
+ * </dd>
+ * <dt><code><b><room></b></code></dt>
+ * <dd>The contianer to hold all information about a room. The name of the
+ * room is defined by the <code>name</code> attribute.
+ * </dd>
+ * <dt><code><b><zone></b></code></dt>
+ * <dd>A room might consist out of multiple zones. But at least one is needed.
+ * </dd>
+ * <dt><code><b><corner></b></code></dt>
+ * <dd>Defining the corners of the zone by having the node IDs in the
+ * <code>nodeid</code> attribute.
+ * </dd>
+ * <dt><code><b><textues></b></code></dt>
+ * <dd>Container for the <code>texture</code> Elements.
+ * </dd>
+ * <dt><code><b><texture></b></code></dt>
+ * <dd>Currently unsued. In future the definition of the texture files.
+ * </dd>
+ * </dl>
+ *
+ * @module JavaScript FloorPlan 3D
+ * @title JS FloorPlan 3D
* @reqires jQuery, Three.js
*/
if (typeof JSFLOORPLAN3D == 'undefined' || !JSFLOORPLAN3D)
@@ -42,7 +146,7 @@
* @class JSFLOORPLAN3D
* @constructor FOO
*/
-JSFLOORPLAN3D= function () {
+JSFLOORPLAN3D = function () {
////////////////////////////////////////////////////////////////////////////
// Definition of the private variables
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:57:36
|
Revision: 603
http://openautomation.svn.sourceforge.net/openautomation/?rev=603&view=rev
Author: mayerch
Date: 2011-12-20 16:57:26 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
Fix documentation anoyity that was caused by "overloading" a method (which JS can't do...).
As this method isn't used (yet) it won't have any side effects.
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-20 16:39:19 UTC (rev 602)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-20 16:57:26 UTC (rev 603)
@@ -222,27 +222,10 @@
}
/**
- * calculate the rotation of a cartesian 2D point around the center
- * @method rotate2D
- * @private
- * @param {Float} angle Rotation angle
- * @param {Point} point
- * @param {Point} center
- * @return {Point} new point containing the turned coordinates
- */
- function rotate2D( angle, point, center )
- {
- var s = Math.sin( angle );
- var c = Math.cos( angle );
- var ret = new Object;
- ret.x = center.x + c * (point.x-center.x) - s * (point.y-center.y);
- ret.y = center.y + s * (point.x-center.x) + c * (point.y-center.y);
- return ret;
- }
-
- /**
* Calculate the rotation of a cartesian 2D point around the center
- * but with given sin and cos of the angle.
+ * but with given sin and cos of the angle. <br />
+ * Note: This method might also be used in a three argument form where the
+ * first argument is the angle (and not it's sin/cos pair).
* @method rotate2D
* @private
* @param {Float} s Sin of the rotation angle
@@ -253,6 +236,14 @@
*/
function rotate2D( s, c, point, center )
{
+ if( rotate2D.arguments.length == 3 )
+ {
+ center = rotate2D.arguments[2];
+ point = rotate2D.arguments[1];
+ c = Math.cos( rotate2D.arguments[0] );
+ s = Math.sin( rotate2D.arguments[0] );
+ }
+
var ret = new Object;
ret.x = center.x + c * (point.x-center.x) - s * (point.y-center.y);
ret.y = center.y + s * (point.x-center.x) + c * (point.y-center.y);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2011-12-20 17:06:50
|
Revision: 604
http://openautomation.svn.sourceforge.net/openautomation/?rev=604&view=rev
Author: mayerch
Date: 2011-12-20 17:06:40 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
Bugfix that placed all floors in one...
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-20 16:57:26 UTC (rev 603)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-20 17:06:40 UTC (rev 604)
@@ -330,7 +330,7 @@
JSFloorPlan3D.buildingProperties.floor[floorCount].height = floorheight;
JSFloorPlan3D.buildingProperties.floor[floorCount].heightOfGround = heightOfGround;
- var floorWallsStart = 0;// floorWalls.length; <- not defined here yet...
+ var floorWallsStart = floorWalls.length;
// iterate over the content of this floor
for( var j=0; j < floor.childNodes.length; j++ )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2011-12-20 17:46:43
|
Revision: 605
http://openautomation.svn.sourceforge.net/openautomation/?rev=605&view=rev
Author: mayerch
Date: 2011-12-20 17:46:36 +0000 (Tue, 20 Dec 2011)
Log Message:
-----------
Fix holes in the wall (finally!)
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-20 17:06:40 UTC (rev 604)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2011-12-20 17:46:36 UTC (rev 605)
@@ -564,23 +564,30 @@
var wall1vertices = [];
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));
for( var v = 0; v < Tvertices.length; v++ )
{
- // 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;
- var e1f = 1-((e1.x-sm.x)*(em.x-sm.x) + (e1.y-sm.y)*(em.y-sm.y))*lSquaredInv;
- var s2f = 1-((s2.x-sm.x)*(em.x-sm.x) + (s2.y-sm.y)*(em.y-sm.y))*lSquaredInv;
- var e2f = 1-((e2.x-sm.x)*(em.x-sm.x) + (e2.y-sm.y)*(em.y-sm.y))*lSquaredInv;
+ var tv = Tvertices[v];
- var tv = Tvertices[v];
- var tvx1 = Math.min( 1.0, Math.max( 0.0, (tv.x - s1f) * (e1f - s1f) ) ); // map between s1 and e1
- var tvx2 = Math.min( 1.0, Math.max( 0.0, (tv.x - s2f) * (e2f - s2f) ) ); // map between s2 and e2
- var x1 = s1.x * tvx1 + e1.x * (1 - tvx1);
- 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 );
+ // get point in building space:
+ var tm = {
+ x: sm.x * (1-tv.x) + em.x * tv.x ,
+ y: sm.y * (1-tv.x) + em.y * tv.x
+ };
+
+ // project it onto s1->e1
+ var f1 = ((tm.x-s1.x)*(e1.x-s1.x) + (tm.y-s1.y)*(e1.y-s1.y))*l1SquaredInv;
+ if( tv.x == 0.0 || tv.x == 1.0 ) f1 = 1-tv.x; // special case on concave wall bend
+ var x1 = s1.x * (1-f1) + e1.x * f1;
+ 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;
+ 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 )
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-01-08 15:02:10
|
Revision: 643
http://openautomation.svn.sourceforge.net/openautomation/?rev=643&view=rev
Author: mayerch
Date: 2012-01-08 15:02:04 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
More stable moveTo during rapidly following requests
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 14:14:38 UTC (rev 642)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 15:02:04 UTC (rev 643)
@@ -196,6 +196,14 @@
var noSetup = true;
/**
+ * Status if currently an animation is running
+ * @property inAnimation
+ * @type Bool
+ * @private
+ */
+ JSFloorPlan3D.inAnimation = false;
+
+ /**
* Constant representing the ID of an ELEMENT_NODE
* @property ELEMENT_NODE
* @private
@@ -1000,28 +1008,43 @@
// speed of the changing
var steps = 100;
- var rate = {
- azimut: ( azimut - showStates.currentAzimut ) / steps,
- elevation: ( elevation - showStates.currentElevation ) / steps,
- height: ( height - showStates.currentHeight ) / steps
- };
+ var rate = { azimut: 0.0, elevation: 0.0, height: 0.0 };
+ function calcRate()
+ {
+ rate = {
+ azimut: ( azimut - showStates.currentAzimut ) / steps,
+ elevation: ( elevation - showStates.currentElevation ) / steps,
+ height: ( height - showStates.currentHeight ) / steps
+ };
+ }
+
function doMove()
{
+ JSFloorPlan3D.inAnimation = true;
var done = true;
if( Math.abs( azimut - showStates.currentAzimut ) > Math.abs( 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;
}
if( Math.abs( elevation - showStates.currenteElevation ) > Math.abs( 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;
}
if( Math.abs( height - showStates.currentHeight ) > Math.abs( rate.height ) )
{
+ 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;
done = false;
}
@@ -1030,10 +1053,16 @@
render();
if( !done )
window.requestAnimationFrame( doMove );
- else if( delayedFn )
- delayedFn();
+ else {
+ JSFloorPlan3D.inAnimation = false;
+ if( delayedFn )
+ delayedFn();
+ }
}
- doMove();
+ if( JSFloorPlan3D.inAnimation )
+ calcRate();
+ else
+ doMove();
}
};//());
\ 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-01-08 15:30:09
|
Revision: 644
http://openautomation.svn.sourceforge.net/openautomation/?rev=644&view=rev
Author: mayerch
Date: 2012-01-08 15:30:03 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
Improofed transparency handling
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 15:02:04 UTC (rev 643)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-08 15:30:03 UTC (rev 644)
@@ -668,6 +668,7 @@
var mesh = new THREE.Mesh(geometry, cubeMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
+ //mesh.doubleSided = true;
wallGroup.add(mesh);
} // end for( j=0; j<floorWalls.length; j++ )
Object3D.add( lineGroup );
@@ -961,7 +962,15 @@
}
// update opacity
- cubeMaterial.opacity = showStates.fillOpacity;
+ if( cubeMaterial.opacity != showStates.fillOpacity )
+ {
+ cubeMaterial.opacity = showStates.fillOpacity;
+ cubeMaterial.transparent = showStates.fillOpacity < 1.0;
+ cubeMaterial.depthTest = !cubeMaterial.transparent;
+ THREE.SceneUtils.traverseHierarchy( JSFloorPlan3D.buildingProperties.Object3D, function( object ) {
+ object.doubleSided = cubeMaterial.transparent;
+ });
+ }
// update color
switch( showStates.fillColor )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-01-15 12:32:28
|
Revision: 653
http://openautomation.svn.sourceforge.net/openautomation/?rev=653&view=rev
Author: mayerch
Date: 2012-01-15 12:32:22 +0000 (Sun, 15 Jan 2012)
Log Message:
-----------
Update documentation for new methods
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-14 16:47:21 UTC (rev 652)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-01-15 12:32:22 UTC (rev 653)
@@ -1076,8 +1076,16 @@
}
/**
- * 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>.
+ * Check if point <code>p</code> is in the zone <code>zone</code>. It's
+ * basically a point-in-polygon test using a ray casting from left infinity to
+ * the point <code>p</code>.
+ * @method pointInZone
+ * @private
+ * @param {THREE.Vector3} p The point to check (note: only the
+ * <code>x</code> and <code>y</code> corrdinates
+ * are checked
+ * @param {Number} zone The zone to check
+ * @return {Bool} True when point <code>p</code> is inside
*/
function pointInZone( p, zone )
{
@@ -1100,7 +1108,15 @@
}
/**
- * Figur out the room that contains the point <code>p</code> in the floor <code>floor</code>.
+ * Figur out the room that contains the point <code>p</code> in the floor.
+ * <code>floor</code>.
+ * @method selectRoom
+ * @param {THREE.Vector3} p The point to check (note: only the
+ * <code>x</code> and <code>y</code> corrdinates
+ * are checked
+ * @param {Number} floor The number of the floor to check
+ * @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 )
{
@@ -1112,14 +1128,20 @@
{
if( pointInZone( p, thisRoom.zones[zone] ) )
{
- console.log( 'in zone', thisRoom.zones[zone].name, 'in raum', thisFloor[room].name, 'in stock', floor );
+ return { room: thisFloor[room], zone: thisRoom.zones[zone] };
}
}
}
+ return {};
}
/**
- * Project screen coordinate to building space
+ * Project screen coordinate to building space.
+ * @method sceen2building
+ * @param {Number} x x position in pixel
+ * @param {Number} y y position in pixel
+ * @param {Number} h Height in building space used for mapping
+ * @return {THREE.Vector3} Point in building space
*/
JSFloorPlan3D.sceen2building = function( x, y, h )
{
@@ -1131,24 +1153,28 @@
}
/**
- * Project point in building space to screen space
+ * Project point in building space to screen space.
+ * @method building2screen
+ * @param {THREE.Vector3} p point in building space to map
+ * @return {Object} Hash with keys <code>x</code> and <code>y</code> in screen
+ * coordinates
*/
JSFloorPlan3D.building2screen = function( p )
{
var screen = p.clone();
projector.projectVector( screen, camera );
- return screen;
+ return { x: (screen.x+1)/2*WIDTH, y: -(screen.y-1)/2*HEIGHT };
}
/**
* This method can be used as an event handler for mouse events.
+ * @method translateMouseEvent
* @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 );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-03-11 20:11:22
|
Revision: 727
http://openautomation.svn.sourceforge.net/openautomation/?rev=727&view=rev
Author: mayerch
Date: 2012-03-11 20:11:16 +0000 (Sun, 11 Mar 2012)
Log Message:
-----------
Better error handling
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-03-11 19:52:14 UTC (rev 726)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-03-11 20:11:16 UTC (rev 727)
@@ -1306,6 +1306,9 @@
{
floor = this.buildingProperties.floorNames[floor];
}
+ if( !(floor in this.buildingProperties.floor) )
+ return target; // early exit when floor is invalid
+
if( room ) // use room if defined
{
target.x = room.center.x;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ma...@us...> - 2012-03-11 21:52:26
|
Revision: 728
http://openautomation.svn.sourceforge.net/openautomation/?rev=728&view=rev
Author: mayerch
Date: 2012-03-11 21:52:15 +0000 (Sun, 11 Mar 2012)
Log Message:
-----------
Update of the inline documentation
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-03-11 20:11:16 UTC (rev 727)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-03-11 21:52:15 UTC (rev 728)
@@ -22,7 +22,7 @@
//////////////////////////////////////////////////////////////////////////////
/**
- * The JSFLOORPLAN3D object is the single global object created by the
+ * The JSFloorPlan3D object is the single global object created by the
* JSFloorPlan 3D library.
* <p/>
* The definition of the config file is:
@@ -136,26 +136,25 @@
* @reqires jQuery, Three.js
*/
-/**
- * @class JSFLOORPLAN3D
- * @constructor FOO
- */
(function( window, undefined ){
////////////////////////////////////////////////////////////////////////////
// private static variables and methods:
- /**
- * Constant representing the ID of an ELEMENT_NODE
- * @property ELEMENT_NODE
- * @private
- * @static
- * @final
- * @type Enum
- */
+ // Constant representing the ID of an ELEMENT_NODE
var ELEMENT_NODE = 1;
////////////////////////////////////////////////////////////////////////////
// the library
+
+ /**
+ * The object JSFloorPlan3D contains the whole API necessary to handle a
+ * 3D floorplan.
+ * @class JSFloorPlan3D
+ * @constructor FOO
+ * @param {DOMElement} container The DOM element where floorplan will be
+ * inserted
+ * @param {URL} floorPlan The URL of the floorplan to show
+ */
var JSFloorPlan3D = function( container, floorPlan ){
// check and fix if the user forgot the "new" keyword
if (!(this instanceof JSFloorPlan3D))
@@ -163,6 +162,11 @@
return new JSFloorPlan3D( container, floorPlan );
}
+ /**
+ * Private pointer to <i>this</i>
+ * @property self
+ * @private
+ */
var self = this;
/*
@@ -172,7 +176,10 @@
}
*/
- // public variables of this object instance
+ /**
+ * public variables of this object instance
+ * @property buildingProperties
+ */
this.buildingProperties = { floor: [], Object3D: new THREE.Object3D(), floorNames:{} };
// private variables of this object instance will follow
@@ -196,6 +203,8 @@
/**
* Set states that define how the floor plan is drawn
+ * @property showStates
+ * @private
*/
var showStates = {
currentAzimut: 1, // North up
@@ -273,6 +282,7 @@
* @private
* @param {Point} start
* @param {Point} end
+ * @return {Number}
*/
function calcLength2D( start, end )
{
@@ -756,10 +766,7 @@
$.ajax({
url: url,
context: self,
- success: function( xmlDoc ){
- parseXMLFloorPlan( xmlDoc );
-
- },
+ success: function( xmlDoc ){ parseXMLFloorPlan( xmlDoc ); },
dataType: 'xml',
async: false
});
@@ -826,7 +833,7 @@
/**
* Contain all informations known about a wall.
* @class wall
- * @for JSFLOORPLAN3D
+ * @for JSFloorPlan3D
*/
var wall = new Object;
/**
@@ -898,7 +905,7 @@
* Fill the <code>rooms</code> array with the room elements from the
* config file.
* @method parseFloorRooms
- * @for JSFLOORPLAN3D
+ * @for JSFloorPlan3D
* @private
* @param {XMLDom} nodeGroup
* @param {Integer} floor The floor number.
@@ -956,7 +963,6 @@
}
}
- //var textures = new Object();
/**
* Dummy routine to handle textures.
* @method parseTextures
@@ -965,7 +971,7 @@
*/
var parseTextures = function( nodes )
{
- return;
+ return; // FIXME - this is currently a dummy...
for( var i=0; i < nodes.childNodes.length; i++ )
{
node = nodes.childNodes[i];
@@ -1055,6 +1061,15 @@
$container.append(renderer.domElement);
}
+ /**
+ * Set up the camera.
+ * @method setupCamera
+ * @param {Number} azimut
+ * @param {Number} elevation
+ * @param {Number} distance
+ * @param {THREE.Vector3} target
+ * @private
+ */
function setupCamera( azimut, elevation, distance, target )
{
var cx = Math.sin(azimut) * Math.cos(elevation);
@@ -1066,11 +1081,22 @@
pointLight.position = camera.position;
}
+ /**
+ * Render the scene
+ * @method render
+ */
this.render = function()
{
renderer.render( scene, camera );
}
+ /**
+ * Change an internal state
+ * @method setState
+ * @param {String} property The property to set
+ * @param {String} value The new value for the property
+ * @param {Bool} redraw Redraw the scene if true
+ */
this.setState = function( property, value, redraw )
{
switch( property )
@@ -1094,6 +1120,12 @@
update3D();
}
}
+
+ /**
+ * Get the value of an internal state
+ * @method getState
+ * @return The value of the state
+ */
this.getState = function( property )
{
return showStates[ property ];
@@ -1102,6 +1134,10 @@
/**
* Resize the canvas. This might be done explicit by passing a width and
* height. Or implicit by passing no parameter or just the redraw parameter.
+ * @method resize
+ * @param {Number} width
+ * @param {Number} height
+ * @param {Bool} redraw
*/
this.resize = function( width, height, redraw )
{
@@ -1124,6 +1160,13 @@
}
}
+ /**
+ * Show or hide a floor
+ * @mthod hideFloor
+ * @param {Number} floorNr The number of the floor to change visibility
+ * @param {Bool} doShow <code>true</code> if floor has to be visible,
+ * <code>false</code> if it has to be hidden
+ */
this.hideFloor = function( floorNr, doShow )
{
THREE.SceneUtils.traverseHierarchy( self.buildingProperties.floor[floorNr].wallGroup, function( object ) {
@@ -1154,6 +1197,11 @@
update3D();
}
+ /**
+ * Update internal
+ * @method update3D
+ * @private
+ */
function update3D()
{
// set up camera
@@ -1296,7 +1344,12 @@
}
/**
+ * Move display to the given room on the given floor. If <code>room</code>
+ * is undefined, the whole floor will be shown.
* @method moveToRoom
+ * @param {Number} floor
+ * @param {Room} room
+ * @return {THREE.Vector3} Target
*/
this.moveToRoom = function( floor, room, hideOtherFloors, animate )
{
@@ -1467,7 +1520,6 @@
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
* @class requestAnimationFrame
*/
-
if ( !window.requestAnimationFrame ) {
window.requestAnimationFrame = ( function() {
return window.webkitRequestAnimationFrame ||
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:42:56
|
Revision: 777
http://openautomation.svn.sourceforge.net/openautomation/?rev=777&view=rev
Author: mayerch
Date: 2012-05-01 11:42:50 +0000 (Tue, 01 May 2012)
Log Message:
-----------
Added ability to call a callback function during each animation step - but also for moveToRoom
Modified Paths:
--------------
JSFloorPlan/trunk/src/jsfloorplan.js
Modified: JSFloorPlan/trunk/src/jsfloorplan.js
===================================================================
--- JSFloorPlan/trunk/src/jsfloorplan.js 2012-05-01 11:35:32 UTC (rev 776)
+++ JSFloorPlan/trunk/src/jsfloorplan.js 2012-05-01 11:42:50 UTC (rev 777)
@@ -1349,11 +1349,15 @@
* Move display to the given room on the given floor. If <code>room</code>
* is undefined, the whole floor will be shown.
* @method moveToRoom
- * @param {Number} floor
- * @param {Room} room
+ * @param {Number} floor
+ * @param {Room} room
+ * @param {Bool} hideOtherFloors
+ * @param {Bool} animate
+ * @param {Function} animateFn Callback
+ * @param {Function} delayedFn Callback
* @return {THREE.Vector3} Target
*/
- this.moveToRoom = function( floor, room, hideOtherFloors, animate, callback )
+ this.moveToRoom = function( floor, room, hideOtherFloors, animate, animateFn, delayedFn )
{
var target = new THREE.Vector3();
var dist;
@@ -1384,7 +1388,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, undefined,
+ this.moveTo( floor, showStates.currentAzimut, showStates.currentElevation, dist, target, animateFn,
function(){
if( hideOtherFloors )
{
@@ -1393,7 +1397,7 @@
for( ; f >= 0; f-- ) self.hideFloor( f, f == floor );
}
self.render();
- if( callback !== undefined ) callback();
+ if( delayedFn !== undefined ) delayedFn();
}, animate );
showStates.showFloor = floor;
return target;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|