123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- # Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
- # Secretary of Defense (Personnel & Readiness).
- #
- # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- # in compliance with the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software distributed under the License
- # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- # or implied. See the License for the specific language governing permissions and limitations under
- # the License.
- ## The component representation of an editable node3 behavior
- ##
- ## @name node3edit.vwf
- ## @namespace
- ---
- extends: http://vwf.example.com/node3.vwf
- properties:
- ttPositions:
- ttPoints:
- boxCenter:
- pivotPoint:
- methods:
- createTool:
- getToolDimensions:
- createToolGeometry:
- deleteGeometry:
- createPointList:
- testTool:
- objectSelected:
- calcBoxCenter:
- removeChildren:
- events:
- transformUpdated:
- scripts:
- - |
- this.initialize = function() {
- //console.info( "== initialize == transformTool == initialize ==" );
- this.objBoundingBox = undefined;
- this.selectedID = undefined;
- this.selectedNode = undefined;
- }
- this.transformUpdated = this.events.add( function( ID ) {
-
- } );
- this.objectSelected = function( node ) {
- if ( node ) {
- this.selectedNode = node;
- this.selectedID = this.selectedNode.id;
- } else {
- if ( this.children.length > 0 ) {
- this.selectedNode = this.children[0];
- this.selectedID = this.selectedNode.id;
- } else {
- this.selectedID = undefined;
- this.selectedNode = undefined;
- }
- }
-
- if ( this.selectedNode ) {
- this.createTool();
- }
- };
- this.testTool = function() {
- this.createToolGeometry( 100, 100, 100 );
- this.position = [ 0, 0, 0 ];
- }
- this.createTool = function() {
- this.objBoundingBox = this.selectedNode.boundingbox;
-
- if ( this.objBoundingBox ) {
- this.calcBoxCenter();
- var dim = this.getToolDimensions();
- if ( dim ) {
- this.createToolGeometry( dim[0], dim[1], dim[2] );
- }
- }
- }
- this.calcBoxCenter = function() {
- if ( this.objBoundingBox ) {
- var min = this.objBoundingBox.min;
- var max = this.objBoundingBox.max;
- var dX = max.x-min.x;
- var dY = max.y-min.y;
- var dZ = max.z-min.z;
- this.boxCenter = goog.vec.Vec3.add(
- goog.vec.Vec3.createFromArray( [ min.x, min.y, min.z ] ),
- goog.vec.Vec3.scale(
- goog.vec.Vec3.createFromArray( [ dX, dY, dZ ] ),
- 0.5,
- goog.vec.Vec3.create()
- ),
- goog.vec.Vec3.create()
- );
- //console.info( " this.boxCenter = " + Array.prototype.slice.call( this.boxCenter ) );
- }
- }
- this.deleteGeometry = function() {
- if ( this.children["transXPos"] !== undefined ) {
- this.children["transXPos"].deleteGeometry();
- }
- if ( this.children["transXNeg"] !== undefined ) {
- this.children["transXNeg"].deleteGeometry();
- }
- if ( this.children["transYPos"] !== undefined ) {
- this.children["transYPos"].deleteGeometry();
- }
- if ( this.children["transYNeg"] !== undefined ) {
- this.children["transYNeg"].deleteGeometry();
- }
- if ( this.children["transZPos"] !== undefined ) {
- this.children["transZPos"].deleteGeometry();
- }
- if ( this.children["transZNeg"] !== undefined ) {
- this.children["transZNeg"].deleteGeometry();
- }
- if ( this.children["rotX"] !== undefined ) {
- this.children["rotX"].deleteGeometry();
- }
- if ( this.children["rotY"] !== undefined ) {
- this.children["rotY"].deleteGeometry();
- }
- if ( this.children["rotZ"] !== undefined ) {
- this.children["rotY"].deleteGeometry();
- }
- if ( this.children["scaler"] !== undefined ) {
- this.children["scaler"].deleteGeometry();
- }
- }
- this.removeChildren = function() {
- //console.info( "DESELECTING: " + this.selectedID );
- if ( this.children ) {
- for ( var i = this.children.length-1; i >= 0; i-- ) {
- this.children.delete( node.children[i] );
- }
- }
- }
- this.getToolDimensions = function() {
- if ( this.objBoundingBox ) {
- var dX = this.objBoundingBox.max.x-this.objBoundingBox.min.x;
- var dY = this.objBoundingBox.max.y-this.objBoundingBox.min.y;
- var dZ = this.objBoundingBox.max.z-this.objBoundingBox.min.z;
- return [ dX, dY, dZ ];
- }
- return undefined;
- }
- this.createToolGeometry = function( dx, dy, dz ) {
- this.createPointList( dx, dy, dz );
- var path = "http://vwf.example.com/tools/transform/";
- if ( this.ttPoints ){
-
- // translate xPos 9,18,15,12
- if ( this.children["transXPos"] === undefined ) {
- this.children.create( "transXPos", { "includes": path + "translateXPos.vwf" }, function( child ) {
- child.createGeometry();
- } );
- } else {
- this.children["transXPos"].createGeometry();
- }
- // translate xNeg 21,24,27,30
- if ( this.children["transXNeg"] === undefined ) {
- this.children.create( "transXNeg", { "includes": path + "translateXNeg.vwf" }, function( child ) {
- child.createGeometry();
- } );
- } else {
- this.children["transXNeg"].createGeometry();
- }
- // translate yPos 48,49,50,51
- if ( this.children["transYPos"] === undefined ) {
- this.children.create( "transYPos", { "includes": path + "translateYPos.vwf" }, function( child ) {
- child.createGeometry();
- } );
- } else {
- this.children["transYPos"].createGeometry();
- }
- // translate yNeg 52,53,54,55
- if ( this.children["transYNeg"] === undefined ) {
- this.children.create( "transYNeg", { "includes": path + "translateYNeg.vwf" }, function( child ) {
- child.createGeometry();
- } );
- } else {
- this.children["transYNeg"].createGeometry();
- }
- // translate zPos 32,34,36,38
- if ( this.children["transZPos"] === undefined ) {
- this.children.create( "transZPos", { "includes": path + "translateZPos.vwf" }, function( child ) {
- child.createGeometry();
- } );
- } else {
- this.children["transZPos"].createGeometry();
- }
- // translate zNeg 40,46,44,42
- if ( this.children["transZNeg"] === undefined ) {
- this.children.create( "transZNeg", { "includes": path + "translateZNeg.vwf" }, function( child ) {
- child.createGeometry();
- } );
- } else {
- this.children["transZNeg"].createGeometry();
- }
-
- // rotate X yPos 34,35,37,36
- // rotate X yNeg 33,32,38,39
- // rotate X yPos 44,45,43,42
- // rotate X yNeg 47,46,40,41
- // rotate X zPos 39,54,53,33
- // rotate X zNeg 55,47,41,52
- // rotate X zPos 50,49,35,37
- // rotate X zNeg 43,48,51,45
- if ( this.children["rotX"] === undefined ) {
- this.children.create( "rotX", { "includes": path + "rotationX.vwf" }, function( child) {
- child.createGeometry();
- } );
- } else {
- this.children["rotX"].createGeometry();
- }
- // rotate Z yPos 12,13,16,15
- // rotate Z yNeg 10,9,18,19
- // rotate Z yPos 24,25,28,27
- // rotate Z yNeg 22,21,30,31
- // rotate Z xPos 16,48,49,13
- // rotate Z xNeg 28,51,50,25
- // rotate Z xPos 52,19,10,53
- // rotate Z xNeg 22,54,55,31
-
- if ( this.children["rotY"] === undefined ) {
- this.children.create( "rotY", { "includes": path + "rotationY.vwf" }, function( child) {
- child.createGeometry();
- } );
- } else {
- this.children["rotY"].createGeometry();
- }
- // rotate Z yPos 12,13,16,15
- // rotate Z yNeg 10,9,18,19
- // rotate Z yPos 24,25,28,27
- // rotate Z yNeg 22,21,30,31
- // rotate Z xPos 16,48,49,13
- // rotate Z xNeg 28,51,50,25
- // rotate Z xPos 52,19,10,53
- // rotate Z xNeg 22,54,55,31
- if ( this.children["rotZ"] === undefined ) {
- this.children.create( "rotZ", { "includes": path + "rotationZ.vwf" }, function( child) {
- child.createGeometry();
- } );
- } else {
- this.children["rotZ"].createGeometry();
- }
- if ( this.children["scaler"] === undefined ) {
- this.children.create( "scaler", { "includes": path + "scaleXYZ.vwf" }, function( child) {
- child.createGeometry();
- } );
- } else {
- this.children["scaler"].createGeometry();
- }
- }
- }
- this.createPointList = function( dX, dY, dZ ) {
- var points = [];
- //console.info( "createPointList( " +dX+ ", "+dY+ ", "+ +dZ+ " )" );
-
- var fHalfX = dX * 0.6;
- var fHalfY = dY * 0.6;
- var fHalfZ = dZ * 0.6;
- var fXThick = dX * 0.08;
- var fYThick = dY * 0.08;
- var fZThick = dZ * 0.08;
- var rp;
-
- points.push( [ fHalfX, -fHalfY, fHalfZ ] ); //0
- points.push( [ fHalfX, fHalfY, fHalfZ ] ); //1
- points.push( [ -fHalfX, fHalfY, fHalfZ ] ); //2
- points.push( [ -fHalfX, -fHalfY, fHalfZ ] ); //3
- points.push( [ fHalfX, -fHalfY, -fHalfZ ] ); //4
- points.push( [ fHalfX, fHalfY, -fHalfZ ] ); //5
- points.push( [ -fHalfX, fHalfY, -fHalfZ ] ); //6
- points.push( [ -fHalfX, -fHalfY, -fHalfZ ] ); //7
- // x pos
- // y-neg z-pos
- rp = points[ 0 ];
- points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //8
- points.push( [ rp[0], fYThick + rp[1], -fZThick + rp[2] ] ); //9
- points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //10
- // y-pos z-pos
- rp = points[ 1 ];
- points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //11
- points.push( [ rp[0], -fYThick + rp[1], -fZThick + rp[2] ] ); //12
- points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //13
- // y-pos z-neg
- rp = points[ 5 ];
- points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //14
- points.push( [ rp[0], -fYThick + rp[1], fZThick + rp[2] ] ); //15
- points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //16
- // y-neg z-neg
- rp = points[ 4 ];
- points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //17
- points.push( [ rp[0], fYThick + rp[1], fZThick + rp[2] ] ); //18
- points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //19
- // x neg
- // y-neg z-pos
- rp = points[ 3 ];
- points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //20
- points.push( [ rp[0], fYThick + rp[1], -fZThick + rp[2] ] ); //21
- points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //22
- // y-pos z-pos
- rp = points[ 2 ];
- points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //23
- points.push( [ rp[0], -fYThick + rp[1], -fZThick + rp[2] ] ); //24
- points.push( [ rp[0], rp[1], -fZThick + rp[2] ] ); //25
- // y-pos z-neg
- rp = points[ 6 ];
- points.push( [ rp[0], -fYThick + rp[1], rp[2] ] ); //26
- points.push( [ rp[0], -fYThick + rp[1], fZThick + rp[2] ] ); //27
- points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //28
- // y-neg z-neg
- rp = points[ 7 ];
- points.push( [ rp[0], fYThick + rp[1], rp[2] ] ); //29
- points.push( [ rp[0], fYThick + rp[1], fZThick + rp[2] ] ); //30
- points.push( [ rp[0], rp[1], fZThick + rp[2] ] ); //31
- // z pos
- // x-pos y-neg
- //8
- rp = points[ 0 ];
- points.push( [ -fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //32
- points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //33
- // x-pos y-pos
- //11
- rp = points[ 1 ];
- points.push( [ -fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //34
- points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //35
- // x-neg y-pos
- //23
- rp = points[ 2 ];
- points.push( [ fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //36
- points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //37
- // x-neg y-neg
- //20
- rp = points[ 3 ];
- points.push( [ fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //38
- points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //39
- // z neg
- // x-pos y-neg
- //17
- rp = points[ 4 ];
- points.push( [ -fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //40
- points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //41
- // x-pos y-pos
- //14
- rp = points[ 5 ];
- points.push( [ -fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //42
- points.push( [ -fXThick + rp[0], rp[1], rp[2] ] ); //43
- // x-neg y-pos
- //26
- rp = points[ 6 ];
- points.push( [ fXThick + rp[0], -fYThick + rp[1], rp[2] ] ); //44
- points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //45
- // x-neg y-neg
- //29
- rp = points[ 7 ];
- points.push( [ fXThick + rp[0], fYThick + rp[1], rp[2] ] ); //46
- points.push( [ fXThick + rp[0], rp[1], rp[2] ] ); //47
- // y pos
- // x-pos z-neg
- //16
- rp = points[ 5 ];
- points.push( [ -fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //48
- //43
- // x-pos z-pos
- //13
- rp = points[ 1 ];
- points.push( [ -fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //49
- //35
- // x-neg z-pos
- //25
- rp = points[ 2 ];
- points.push( [ fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //50
- //37
- // x-neg z-neg
- //28
- rp = points[ 6 ];
- points.push( [ fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //51
- //45
- // y neg
- // x-pos z-neg
- //19
- rp = points[ 4 ];
- points.push( [ -fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //52
- //41
- // x-pos z-pos
- //10
- rp = points[ 0 ];
- points.push( [ -fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //53
- //33
- // x-neg z-pos
- //22
- rp = points[ 3 ];
- points.push( [ fXThick + rp[0], rp[1], -fZThick + rp[2] ] ); //54
- //39
- // x-neg z-neg
- //31
- rp = points[ 7 ];
- points.push( [ fXThick + rp[0], rp[1], fZThick + rp[2] ] ); //55
- //47
- this.ttPositions = points;
- var pts = [];
- for ( var i = 0; i < points.length; i++ ) {
- //console.info( " points["+i+"] = " +points[i] );
- pts.push( points[i][0] );
- pts.push( points[i][1] );
- pts.push( points[i][2] );
- }
- this.ttPoints = pts;
- }//@ sourceURL=transformTool.vwf
-
|