123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- # 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:
-
- ## Edit mode
- ##
- ## @name node3edit.vwf#editMode
- ## @property
- editMode:
- set: |
- switch ( value ) {
- case "translate":
- case "rotate":
- case "scale":
- this.editMode = value;
- break;
- }
- ## Axis
- ##
- ## @name node3edit.vwf#axis
- ## @property
- axis: [ 0, 0, 1 ]
- methods:
- ## Translate
- ##
- ## @name node3edit.vwf#translate
- ## @function
- ##
- ## @returns undefined
- translate:
- ## Rotate
- ##
- ## @name node3edit.vwf#rotate
- ## @function
- ##
- ## @returns undefined
- rotate:
- ## Scaling
- ##
- ## @name node3edit.vwf#scaling
- ## @function
- ##
- ## @returns undefined
- scaling:
- ## Edit
- ##
- ## @name node3edit.vwf#edit
- ## @function
- ##
- ## @returns undefined
- edit:
- ## Set Axis
- ##
- ## @name node3edit.vwf#setAxis
- ## @function
- ##
- ## @returns undefined
- setAxis:
- ## Initialize function
- ##
- ## @name node3edit.vwf#init
- ## @function
- ##
- ## @returns undefined
- init:
- scripts:
- - |
- this.init = function() {
- this.rotationAxis = 'z';
- this.input = {
- "initialTransform": undefined,
- "initialValue": undefined,
- "pointerInfo": undefined,
- "pickInfo": undefined,
- "previous": {
- "pointerInfo": undefined,
- "pickInfo": undefined,
- },
- pointerDown: {
- "pointerInfo": undefined,
- "pickInfo": undefined,
- },
- update: function( pointerInfo, pickInfo ){
- this.previous.pointerInfo = this.pointerInfo;
- this.previous.pickInfo = this.pickInfo;
- this.pointerInfo = pointerInfo;
- this.pickInfo = pickInfo;
- },
- clear: function(){
- this.previous.pointerInfo = undefined;
- this.previous.pickInfo = undefined;
- this.pointerInfo = undefined;
- this.pickInfo = undefined;
- this.initialValue = undefined;
- },
- change: function() {
- var ret = [ 0, 0 ]
- if ( this.pointerInfo && this.previous.pointerInfo ) {
- ret[0] = this.pointerInfo.position[0] - this.previous.pointerInfo.position[0];
- ret[1] = this.pointerInfo.position[1] - this.previous.pointerInfo.position[1];
- }
- return ret;
- },
- pointChange: function() {
- var ret = [ 0, 0, 0 ];
- if ( this.pickInfo && this.previous.pickInfo ) {
- var oldPt = this.previous.pickInfo.globalSource;
- var newPt = this.pickInfo.globalSource;
- ret[0] = newPt[0] - oldPt[0];
- ret[1] = newPt[1] - oldPt[1];
- ret[2] = newPt[2] - oldPt[2];
- }
- return ret;
- },
- };
- }
- this.pointerDown = this.events.add( function( pointerInfo, pickInfo ) {
- if ( !this.input ) { this.init(); }
- this.input.clear();
- this.input.initialTransform = this.transform;
- this.input.pointerDown.pointerInfo = pointerInfo;
- this.input.pointerDown.pointerInfo = pickInfo;
- this.input.update( pointerInfo, pickInfo );
- this.setAxis();
- }, "capture", this );
- this.pointerUp = this.events.add( function( pointerInfo, pickInfo ) {
- this.input.update( pointerInfo, pickInfo );
- this.edit();
- this.input.clear();
- }, "capture", this );
- this.pointerMove = this.events.add( function( pointerInfo, pickInfo ) {
- this.input.update( pointerInfo, pickInfo );
- this.edit();
- }, "capture", this );
- this.edit = function() {
- switch( this.editMode ) {
- case "translate":
- this.translate();
- break;
- case "rotate":
- this.rotate();
- break;
- case "scale":
- this.scaling();
- break;
- }
- }
- this.setAxis = function() {
- var info = this.input.pickInfo;
- if ( info && info.globalNormal ) {
- var largest = 0;
- var val = -1;
- for ( var i = 0; i < 3; i++ ) {
- if ( val >= info.globalNormal[i] ) {
- largest = i;
- val = info.globalNormal[i];
- }
- }
- switch( largest ) {
- case 0:
- this.axis = [ 1, 0, 0 ];
- this.rotationAxis = "x";
- break;
- case 1:
- this.axis = [ 0, 1, 0 ];
- this.rotationAxis = "y";
- break;
- default:
- this.axis = [ 0, 0, 1 ];
- this.rotationAxis = "z";
- break;
- }
- }
- }
- this.translate = function() {
- if ( !this.input.initialValue ) {
- this.input.initialValue = {
- transform: this.transform,
- }
- }
- var pc = this.input.pointChange();
- var pos = this.position;
- pos[0] += pc[0];
- pos[1] += pc[1];
- pos[2] += pc[2];
- this.position = pos;
- }
- this.rotate = function() {
- if ( !this.input.initialValue ) {
- this.input.initialValue = {
- transform: this.transform,
- }
- }
- var diff = this.input.change();
- var rot = this.rotation;
- switch( this.rotationAxis ) {
- case "x":
- this.rotateBy( [ 1, 0, 0, rot[3] + (diff[0] * 4) ], 0 );
- break;
- case "y":
- this.rotateBy( [ 0, 1, 0, rot[3] + (diff[0] * 4) ], 0 );
- break;
- case "z":
- this.rotateBy( [ 0, 0, 1, rot[3] + (diff[0] * 4) ], 0 );
- break;
- default:
- this.rotateBy( [ this.axis[0], this.axis[1], this.axis[2], rot[3] + (diff[0] * 4) ], 0 );
- break;
- }
- }
- this.scaling = function() {
- if ( !this.input.initialValue ) {
- this.input.initialValue = {
- transform: this.transform,
- }
- }
- var diff = this.input.change();
- var scale = this.scale;
- scale[0] += diff[0];
- scale[1] += diff[0];
- scale[2] += diff[0];
- if ( scale[0] != 0 && scale[1] != 0 && scale[2] != 0 ) {
- this.scale = scale;
- }
- } //@ sourceURL=node3edit.vwf
|