123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- this.modelDef = {
- "extends": "proxy/aframe/agltfmodel.vwf",
- "properties": {
- "src": "#xrcontroller",
- "position": "0 0 0",
- "rotation": "0 180 0"
- },
- "children": {
- "animation-mixer": {
- "extends": "proxy/aframe/anim-mixer-component.vwf",
- "properties": {
- "clip": "*",
- "duration": 1
- }
- }
- }
- }
- this.createController = function (pos, modelSrc) {
- let self = this;
- let position = pos ? pos : [0, 0, 0]
- var newNode = {
- "extends": "proxy/aframe/aentity.vwf",
- "properties": {
- "position": position
- },
- children: {}
- }
- let interpolation = {
- "extends": "proxy/aframe/interpolation-component.vwf",
- "type": "component",
- "properties": {
- "enabled": true
- }
- }
- let myRayCaster = {
- "extends": "proxy/aframe/raycasterComponent.vwf",
- "type": "component",
- "properties": {
- recursive: false,
- interval: 0,
- far: 10,
- objects: ".intersectable",
- showLine: false
- }
- }
-
-
- this.children.create( "raycaster", myRayCaster );
- this.children.create( "interpolation", interpolation );
- this.children.create("xrnode", newNode, function(child){
- if(child) {
- //find default costume
- self.setControllerNode(modelSrc);
- }
- });
- }
- this.moveVRController = function(){
- let controller = this.xrnode.controller;
- if(controller){
- controller.onMove();
- }
- }
- this.updateVRControl = function(position, rotation){
- this.rotation = rotation;
- this.position = position;
- }
- // this.createSimpleController = function(){
- // if (this.handVRNode.controller) {
- // this.handVRNode.children.delete(this.handVRNode.controller);
- // let controllerDef = this.simpleDef;
- // this.handVRNode.children.create("controller", controllerDef);
- // }
- // }
- this.createAvatarFromGLTF = function(modelSrc){
- if (this.handVRNode.controller) {
- this.handVRNode.children.delete(this.handVRNode.controller);
-
- let controllerDef = this.modelDef;
- controllerDef.properties.src = modelSrc;
- this.handVRNode.children.create("controller", controllerDef);
- }
- }
- this.initialize = function() {
- // this.future(0).update();
- }
- this.triggerdown = function() {
- let controller = this.xrnode.controller;
- if(controller){
- controller.triggerdown();
- }
- //this.xrnode.controller.pointer.material.color = 'red'
- }
- this.triggerup = function() {
- let controller = this.xrnode.controller;
- if(controller){
- controller.triggerup();
- }
- //this.xrnode.controller.pointer.material.color = 'green'
- }
- this.saveToScene = function(){
- let scene = this.getScene();
- let controller = this.xrnode.controller;
- if(controller){
- let defNode = this.checkDefaultXRCostume();
- if(defNode){
- scene.children.delete(defNode);
- }
- let node = controller.nodeDef();
- node.properties.visible = false;
- node.properties.displayName = 'defaultXRCostume';
- scene.children.create('defaultXRCostume', node, function( child ) {
- console.log('Save default controller costume to scene: ', child);
- });
- }
- }
- this.checkDefaultXRCostume = function(){
- let scene = this.getScene();
- let defaultNode = scene.getChildByName('defaultXRCostume');
- return defaultNode ? defaultNode : undefined
- }
- this.setControllerNode = function(modelSrc){
- let scene = this.getScene();
- let defaultNode = this.checkDefaultXRCostume();
- let oldCostume = this.xrnode.controller;
- if(oldCostume){
- this.xrnode.children.delete(oldCostume);
- }
- if(defaultNode) {
- let def = _app.helpers.getNodeDef(defaultNode.id);
- def.properties.position = '0 0 0';
- def.properties.rotation = '0 0 0';
- def.properties.visible = true;
- def.properties.displayName = 'controller';
- this.xrnode.children.create('controller', def, function( child ) {
- console.log('Restore controller costume: ', child);
- if(child.cursorVisual){
- child.cursorVisual.createVisual();
- }
- });
- } else {
- let controllerDef = scene.getDefaultXRCostume();
- controllerDef.properties.displayName = 'controller';
- if (modelSrc) {
- let controllerDef = this.modelDef;
- controllerDef.properties.src = modelSrc;
- }
- this.xrnode.children.create('controller', controllerDef, function( child ) {
- console.log('New controller costume: ', child);
- child.cursorVisual.createVisual();
- });
-
- }
- }
- this.showHandSelection = function (point) {
- let end = this.xrnode.controller.cursorVisual.worldToLocal(point);
- //this.xrnode.controller.line.end = end;
- this.xrnode.controller.cursorVisual.end = end;
- }
- this.resetHandSelection = function () {
- //this.xrnode.controller.line.end = "0 0 -3";
- this.xrnode.controller.cursorVisual.end = "0 0 -0.2";
- }
|