Wikitude将值从java传递到JavaScript,以便在AR.RelativeLocation中使用它
我将一个整数从java传递到javascript,现在我想使用该值来更改对象的高度 我将a添加到RelativeLocationWikitude将值从java传递到JavaScript,以便在AR.RelativeLocation中使用它,javascript,android,wikitude,Javascript,Android,Wikitude,我将一个整数从java传递到javascript,现在我想使用该值来更改对象的高度 我将a添加到RelativeLocationvar location=新的AR.RelativeLocation(null,8,0,a) 问题是它忽略了我传递的值,即10,并将a作为0。我知道从这个var e=document.getElementById('loadingMessage')正确传递的值显示高度:10 Javascript代码: var World = { loaded: false,
var location=新的AR.RelativeLocation(null,8,0,a)代码>
问题是它忽略了我传递的值,即10,并将a作为0。我知道从这个var e=document.getElementById('loadingMessage')正确传递的值代码>显示高度:10
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();
在Alex的回答后编辑:
现在物体和高度都没有显示,我不确定我是否遗漏了什么
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();
请记住Model.onload是异步的。我的假设是,事情发生的顺序是:init()->createModelAtLocation()->java sets altitude->worldLoaded()
要避免这种情况,您可以采取以下措施:
var World = {
location: null,
...
World.location = new AR.RelativeLocation(null, 8, 0, a);
...
};
function setAltitude(altitude){
World.location.altitudeDelta = altitude;
}
请记住Model.onload是异步的。我的假设是,事情发生的顺序是:init()->createModelAtLocation()->java sets altitude->worldLoaded()
要避免这种情况,您可以采取以下措施:
var World = {
location: null,
...
World.location = new AR.RelativeLocation(null, 8, 0, a);
...
};
function setAltitude(altitude){
World.location.altitudeDelta = altitude;
}
我设法解决了这个问题,如果有人感兴趣,这里是答案
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();
我设法解决了这个问题,如果有人感兴趣,这里是答案
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();
我试过了,但是现在模型和高度都显示不出来了。对于此行World.location.altitudeDelta=海拔代码>我也试过World.location.a=海拔代码>得到了同样的结果。我试过了,但是现在模型和高度都没有显示出来。对于此行World.location.altitudeDelta=海拔代码>我也试过World.location.a=海拔代码>并得到相同的结果。