2017-06-05 2 views
1

J'ai transmis un entier de java à javascript, et maintenant je veux utiliser la valeur pour changer l'altitude d'un objet.Wikitude Passer une valeur de java à JavaScript pour l'utiliser dans AR.RelativeLocation

J'ai ajouté à RelativeLoction var location = new AR.RelativeLocation(null, 8, 0, a);

Le problème est-il ne tient pas compte de la valeur que je suis passé qui est de 10 et de prendre un 0. Je sais que la valeur passée correctement de cette var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a; qui montre Altitude: 10.

code Javascript:

var World = { 
    loaded: false, 
    rotating: false, 

    init: function initFn() { 
     this.createModelAtLocation(); 
    }, 



    createModelAtLocation: function createModelAtLocationFn() { 

     /* 
      First a location where the model should be displayed will be defined. This location will be relativ to the user. 
     */ 
     var location = new AR.RelativeLocation(null, 8, 0, a); 

     /* 
      Next the model object is loaded. 
     */ 
     var modelArrow = new AR.Model("assets/arrow.wt3", { 
        onLoaded: this.worldLoaded, 
        scale: { 
         x: 0.005, 
         y: 0.005, 
         z: 0.003 
        }, 
        rotate: { 
            x: 0.0, 
            y: 90.0, 
            z: 0.0 
            }, 
            translate: { 
             x: 0, 
             y: 0, 
             z: 0 
            } 

       }); 



     var indicatorImage = new AR.ImageResource("assets/indi.png"); 

     var indicatorDrawable = new AR.ImageDrawable(indicatorImage, 0.1, { 
      verticalAnchor: AR.CONST.VERTICAL_ANCHOR.TOP 
     }); 

     /* 
      Putting it all together the location and 3D model is added to an AR.GeoObject. 
     */ 
     var obj = new AR.GeoObject(location, { 
      drawables: { 
       cam: [modelArrow], 
       indicator: [indicatorDrawable] 
      } 
     }); 
    }, 

    worldLoaded: function worldLoadedFn() { 
     World.loaded = true; 
     var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a; 
     e.parentElement.removeChild(e); 
    } 
}; 

    var a = 0; 
    var altitude = 0; 

     function setAltitude(altitude){ 
       a = altitude; 
      } 

World.init(); 

Modifier après la réponse d'Alex:

maintenant un objet d l'altitude ne montre pas si je manque quelque chose

var World = { 
    location: null, 
    loaded: false, 
    rotating: false, 

    init: function initFn() { 
     this.createModelAtLocation(); 
    }, 

    createModelAtLocation: function createModelAtLocationFn() { 

     /* 

      First a location where the model should be displayed will be defined. This location will be relativ to the user. 
     */ 
     //var location = new AR.RelativeLocation(null, 8, 0, a); 
     World.location = new AR.RelativeLocation(null, 8, 0, a); 

     /* 
      Next the model object is loaded. 
     */ 
     var modelArrow = new AR.Model("assets/arrow.wt3", { 
        onLoaded: this.worldLoaded, 
        scale: { 
         x: 0.005, 
         y: 0.005, 
         z: 0.003 
        }, 
        rotate: { 
            x: 0.0, 
            y: 90.0, 
            z: 0.0 
            }, 
            translate: { 
             x: 0, 
             y: 0, 
             z: 0 
            } 

       }); 



     var indicatorImage = new AR.ImageResource("assets/indi.png"); 

     var indicatorDrawable = new AR.ImageDrawable(indicatorImage, 0.1, { 
      verticalAnchor: AR.CONST.VERTICAL_ANCHOR.TOP 
     }); 

     /* 
      Putting it all together the location and 3D model is added to an AR.GeoObject. 
     */ 
     var obj = new AR.GeoObject(location, { 
      drawables: { 
       cam: [modelArrow], 
       indicator: [indicatorDrawable] 
      } 
     }); 
    }, 

    worldLoaded: function worldLoadedFn() { 
     World.loaded = true; 
     var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a; 
     e.parentElement.removeChild(e); 
    } 
}; 
    var a = 0; 
    var altitude = 0; 

     function setAltitude(altitude){ 
       //a = altitude; 
       //World.location.altitudeDelta = altitude; 
       World.location.a = altitude; 
      } 

World.init(); 

Répondre

0

j'ai réussi à résoudre le problème ici est la réponse si quelqu'un est intéressé

var World = { 
    //location: null, 
    loaded: false, 
    rotating: false, 

    loadValuesFromJava: function loadValuesFromJavaFn(Altitude){ 
     a = Altitude; 
     this.createModelAtLocation(); 
    }, 

    /*init: function initFn() { 
     this.createModelAtLocation(); 
    },*/ 

    createModelAtLocation: function createModelAtLocationFn() { 

     /* 

      First a location where the model should be displayed will be defined. This location will be relativ to the user. 
     */ 
     var location = new AR.RelativeLocation(null, 8, 0, a); 
     //World.location = new AR.RelativeLocation(null, 8, 0, a); 

     /* 
      Next the model object is loaded. 
     */ 
     var modelArrow = new AR.Model("assets/arrow.wt3", { 
        onLoaded: this.worldLoaded, 
        scale: { 
         x: 0.005, 
         y: 0.005, 
         z: 0.003 
        }, 
        rotate: { 
            x: 0.0, 
            y: 90.0, 
            z: 0.0 
            }, 
            translate: { 
             x: 0, 
             y: 0, 
             z: 0 
            } 

       }); 



     var indicatorImage = new AR.ImageResource("assets/indi.png"); 

     var indicatorDrawable = new AR.ImageDrawable(indicatorImage, 0.1, { 
      verticalAnchor: AR.CONST.VERTICAL_ANCHOR.TOP 
     }); 

     /* 
      Putting it all together the location and 3D model is added to an AR.GeoObject. 
     */ 
     var obj = new AR.GeoObject(location, { 
      drawables: { 
       cam: [modelArrow], 
       indicator: [indicatorDrawable] 
      } 
     }); 
    }, 



    worldLoaded: function worldLoadedFn() { 
     World.loaded = true; 
     var e = document.getElementById('loadingMessage').innerHTML = "Altitude: " + a; 
     e.parentElement.removeChild(e); 
    } 
}; 

var a = 0; 
var Altitude = 0; 
    /*var a = 0; 
    var altitude = 0; 

     function setAltitude(altitude){ 
       a = altitude; 
       //World.location.altitudeDelta = altitude; 
       //World.location.altitudeDelta = altitude; 
      }*/ 

//World.init(); 
//World.loadValuesFromJava(); 
0

Gardez à l'esprit que Model.onLoaded est asynchrone. Mon hypothèse est que l'ordre dans lequel les choses se passent est: init() -> createModelAtLocation() -> java définit l'altitude -> worldLoaded().

Ce que vous pouvez faire pour éviter cela est:

var World = { 
    location: null, 
    ... 
    World.location = new AR.RelativeLocation(null, 8, 0, a); 
    ... 
}; 

function setAltitude(altitude){ 
    World.location.altitudeDelta = altitude; 
} 
+0

Je l'ai essayé, mais maintenant le modèle et la L'altitude ne montre pas. Pour cette ligne 'World.location.altitudeDelta = altitude;' j'ai aussi essayé 'World.location.a = altitude;' et j'ai obtenu le même résultat. – user2325177