Browse Source

accept coordinates as string

Nikolay Suslov 7 years ago
parent
commit
abb02ab553

+ 16 - 15
public/aframe2/index.vwf.yaml

@@ -11,32 +11,32 @@ children:
     properties:
       type: "point"
       color: "white"
-      position: [0, 10, 5]
-      rotation: [0, 0, 0]
+      position: "0 10 5"
+      rotation: "0 0 0"
   model:
     extends: http://vwf.example.com/aframe/acolladamodel.vwf
     properties:
       src: "#plane"
-      position: [-1.0, 1.7, -3]
-      rotation: [0, -45, 0]
-      scale: [10, 10, 10]
+      position: "-1.0 1.7 -3"
+      rotation: "0 -45 0"
+      scale: "10 10 10"
   spaceText:
     extends: http://vwf.example.com/aframe/atext.vwf
     properties:
       value: "Virtual World Framework & A-Frame"
       color: "#ddd"
-      position: [-2, 2.5, -2]
+      position: "-2 2.5 -2"
   spaceText2:
     extends: http://vwf.example.com/aframe/atext.vwf
     properties:
       value: "Project by Krestianstvo.org"
       color: "#aaa"
-      position: [1, 3, -4]
+      position: "1 3 -4"
   boxAnim:
     extends: http://vwf.example.com/aframe/abox.vwf
     properties:
-      position: [0, 0, -3]
-      rotation: [0, 0, 0]
+      position: "0 0 -3"
+      rotation: "0 0 0"
       color: "#3c7249"
       depth: 2
       height: 1
@@ -44,8 +44,8 @@ children:
   box:
     extends: http://vwf.example.com/aframe/abox.vwf
     properties:
-      position: [-1, 0.5, -3]
-      rotation: [0, -30, 0]
+      position: "-1 0.5 -3"
+      rotation: "0 -30 0"
       color: "#3c7249"
       depth: 2
       height: 1
@@ -75,7 +75,7 @@ children:
   sphere:
     extends: http://vwf.example.com/aframe/asphere.vwf
     properties:
-      position: [1, 1.25, -4]
+      position: "1 1.25 -4"
       color: "#e0e014"
       radius: 1
       wireframe: true
@@ -84,7 +84,7 @@ children:
         extends: http://vwf.example.com/aframe/abox.vwf
         properties:
           src: "#bg"
-          position: [2, -0.75, 0]
+          position: "2 -0.75 0"
           color: "#2167a5"
           depth: 1
         children:
@@ -99,7 +99,8 @@ children:
           run:
             body: |
               var time = vwf.now;
-              this.position = [this.position[0], this.position[1], Math.sin(time)]
+              let pos = AFRAME.utils.coordinates.parse(this.position);
+              this.position = [pos.x, pos.y, Math.sin(time)]
               this.future( 0.01 ).run();  // schedule the next step
   sky:
     extends: http://vwf.example.com/aframe/asky.vwf
@@ -113,7 +114,7 @@ children:
       height: 50
       width: 50
       repeat: "10 10"
-      rotation: [-90, 0, 0]
+      rotation: "-90 0 0"
       color: "white"
       wireframe: false
       src: "#bg2"

+ 56 - 22
support/client/lib/vwf/model/aframe.js

@@ -22,7 +22,7 @@
 /// @requires vwf/model
 
 define(["module", "vwf/model", "vwf/utility"], function (module, model, utility) {
-var self;
+    var self;
 
     return model.load(module, {
 
@@ -76,7 +76,19 @@ var self;
                         }
                     }
                     return found;
-                }
+                },
+                setAFrameProperty: function (propertyName, propertyValue, aframeObject) {
+                    
+                            if (propertyValue.hasOwnProperty('x')) {
+                                aframeObject.setAttribute(propertyName, propertyValue)
+                            } else
+                                if (Array.isArray(propertyValue)) {
+                                    aframeObject.setAttribute(propertyName, { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] })
+                                } else if (typeof propertyValue === 'string') {
+                                    aframeObject.setAttribute(propertyName, AFRAME.utils.coordinates.parse(propertyValue))
+                                }
+                    
+                        }
             };
 
             this.state.kernel = this.kernel.kernel.kernel;
@@ -133,11 +145,11 @@ var self;
                 //     }
                 // } else {
 
-                    node.aframeObj = createAFrameObject(node);
-                    addNodeToHierarchy(node);
+                node.aframeObj = createAFrameObject(node);
+                addNodeToHierarchy(node);
 
-                    //notifyDriverOfPrototypeAndBehaviorProps();
-              //  }
+                //notifyDriverOfPrototypeAndBehaviorProps();
+                //  }
 
                 //addNodeToHierarchy(node);
             }
@@ -149,10 +161,10 @@ var self;
         // initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
         //     childSource, childType, childIndex, childName ) {
         //     var node = this.state.nodes[childID];
-            
+
 
         //     if ( node && childType == "component" ) {
-                
+
         //     }
         // },
 
@@ -175,7 +187,7 @@ var self;
             return this.initializingProperty(nodeID, propertyName, propertyValue);
         },
 
-        
+
 
         // -- deletingNode -------------------------------------------------------------------------
 
@@ -209,9 +221,9 @@ var self;
             var node = this.state.nodes[nodeID];
             var value = undefined;
 
-        //    if (node.componentName == 'line') {
-        //        console.log(node.aframeObj);
-        //    }
+            //    if (node.componentName == 'line') {
+            //        console.log(node.aframeObj);
+            //    }
 
             if (node && node.aframeObj && utility.validObject(propertyValue)) {
 
@@ -229,7 +241,7 @@ var self;
                     }
 
                 }
-                
+
 
                 if (value === undefined && isAEntityDefinition(node.prototypes)) {
 
@@ -242,13 +254,33 @@ var self;
                         //         break;
 
                         case "position":
-                            aframeObject.setAttribute('position', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
+
+                        this.state.setAFrameProperty('position', propertyValue, aframeObject);
+                            // if (propertyValue.hasOwnProperty('x')) {
+                            //     aframeObject.setAttribute('position', propertyValue)
+                            // } else
+                            //     if (Array.isArray(propertyValue)) {
+                            //         aframeObject.setAttribute('position', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] })
+                            //     } else if (typeof propertyValue === 'string') {
+                            //         aframeObject.setAttribute('position', AFRAME.utils.coordinates.parse(propertyValue))
+                            //     }
+
                             break;
                         case "rotation":
-                            aframeObject.setAttribute('rotation', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
+                        this.state.setAFrameProperty('rotation', propertyValue, aframeObject);
+                            // if (Array.isArray(propertyValue)) {
+                            //     aframeObject.setAttribute('rotation', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
+                            // } else {
+                            //     aframeObject.setAttribute('rotation', AFRAME.utils.coordinates.parse(propertyValue));
+                            // }
                             break;
                         case "scale":
-                            aframeObject.setAttribute('scale', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
+                        this.state.setAFrameProperty('scale', propertyValue, aframeObject);
+                            // if (Array.isArray(propertyValue)) {
+                            //     aframeObject.setAttribute('scale', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
+                            // } else {
+                            //     aframeObject.setAttribute('scale', AFRAME.utils.coordinates.parse(propertyValue));
+                            // }
                             break;
 
                         case "color":
@@ -283,7 +315,7 @@ var self;
                             node.events.clickable = propertyValue;
                             break;
 
-                            case "visible":
+                        case "visible":
                             aframeObject.setAttribute('visible', propertyValue);
                             break;
 
@@ -577,20 +609,20 @@ var self;
                         case "position":
                             var pos = aframeObject.getAttribute('position');
                             if (pos !== undefined) {
-                                value = [pos.x, pos.y, pos.z];
+                                value = AFRAME.utils.coordinates.stringify(pos);
                             }
                             break;
                         case "scale":
                             var scale = aframeObject.getAttribute('scale');
                             if (scale !== undefined) {
-                                value = [scale.x, scale.y, scale.z];
+                                value = AFRAME.utils.coordinates.stringify(scale);
                             }
                             break;
 
                         case "rotation":
                             var rot = aframeObject.getAttribute('rotation');
                             if (rot !== undefined) {
-                                value = [rot.x, rot.y, rot.z];
+                                value = AFRAME.utils.coordinates.stringify(rot);
                             }
                             break;
 
@@ -844,7 +876,7 @@ var self;
             aframeObj = document.createElement('a-animation');
         } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/aentity.vwf")) {
             aframeObj = document.createElement('a-entity');
-        } 
+        }
         aframeObj.setAttribute('id', node.ID);
         return aframeObj;
     }
@@ -904,7 +936,7 @@ var self;
         return found;
     }
 
-   
+
 
 
 
@@ -980,6 +1012,8 @@ var self;
         }
     }
 
+ 
+
 
 });
 

+ 9 - 8
support/client/lib/vwf/view/aframe.js

@@ -151,13 +151,13 @@ define(["module", "vwf/view"], function (module, view) {
 
             }
 
-            if (eventName == "setAvatarRotation") {
-                vwf_view.kernel.setProperty(avatarName, "rotation", [eventParameters.x, eventParameters.y, eventParameters.z]);
-            }
+            // if (eventName == "setAvatarRotation") {
+            //     vwf_view.kernel.setProperty(avatarName, "rotation", [eventParameters.x, eventParameters.y, eventParameters.z]);
+            // }
 
-             if (eventName == "setAvatarPosition") {
-                vwf_view.kernel.setProperty(avatarName, "position", [eventParameters.x, eventParameters.y, eventParameters.z]);
-            }
+            //  if (eventName == "setAvatarPosition") {
+            //     vwf_view.kernel.setProperty(avatarName, "position", [eventParameters.x, eventParameters.y, eventParameters.z]);
+            // }
         },
 
         ticked: function (vwfTime) {
@@ -180,8 +180,9 @@ define(["module", "vwf/view"], function (module, view) {
             let rotation = el.getAttribute('rotation');
 
             if ( postion && rotation) {
-            vwf_view.kernel.setProperty(avatarName, "position", [postion.x, postion.y, postion.z]);
-            vwf_view.kernel.setProperty(avatarName, "rotation", [rotation.x, rotation.y, rotation.z]);
+                //[postion.x, postion.y, postion.z] //[rotation.x, rotation.y, rotation.z]
+            vwf_view.kernel.setProperty(avatarName, "position", postion);
+            vwf_view.kernel.setProperty(avatarName, "rotation", rotation);
             }
         }
     }

+ 3 - 3
support/proxy/vwf.example.com/aframe/avatar.vwf.yaml

@@ -13,7 +13,7 @@ methods:
                 "extends": "http://vwf.example.com/aframe/abox.vwf",
                 "properties": {
                     "color": myColor,
-                    "position": [0,0,0.5],
+                    "position": "0 0 0.5",
                     "height": 2
                 },
               "children": {
@@ -23,8 +23,8 @@ methods:
                         "color": myColor,
                         "value": this.id,
                         "side": "double",
-                        "rotation": [0, 180, 0],
-                        "position": [0, 1, 0.5]
+                        "rotation": "0 180 0",
+                        "position": "0 1 0.5"
                     }
                   }
                 }