[英]3D model vanishing when moving the camera away from the marker android (Kudan AR)
I am working on Augmented Reality using Kudan SDK in android. 我正在使用Android中的Kudan SDK进行增强现实。 I am trying to generate 3D model when the phone camera is pointing towards the marker.
手机摄像头指向标记时,我正在尝试生成3D模型。 I am able to achieve this.
我能够做到这一点。 But If I move the camera away from the marker the model is vanishing.
但是,如果我将相机从标记处移开,则模型将消失。 I dont want the 3D model to go away until unless the application is close or camera is closed.
我不希望3D模型消失,直到应用程序关闭或相机关闭。 I want to move the 3D model while I move the camera as well.
我也想在移动相机的同时移动3D模型。 Here is the code for inserting the marker and the 3D model.
这是用于插入标记和3D模型的代码。
private void addImageTrackable() {
// Initialise image trackable
trackable = new ARImageTrackable("Space");
trackable.loadFromAsset("user_pic.jpg");
// Get instance of image tracker manager
ARImageTracker trackableManager = ARImageTracker.getInstance();
// Add image trackable to image tracker manager
trackableManager.addTrackable(trackable);
}
private void addModelNode() {
// Import model
ARModelImporter modelImporter = new ARModelImporter();
modelImporter.loadFromAsset("cube.jet");
ARModelNode modelNode = (ARModelNode) modelImporter.getNode();
// Load model texture
ARTexture2D texture2D = new ARTexture2D();
texture2D.loadFromAsset("cube.png");
// Apply model texture to model texture material
ARLightMaterial material = new ARLightMaterial();
material.setTexture(texture2D);
material.setAmbient(0.8f, 0.8f, 0.8f);
// Apply texture material to models mesh nodes
for (ARMeshNode meshNode : modelImporter.getMeshNodes()) {
meshNode.setMaterial(material);
}
modelNode.rotateByDegrees(10, 1, 0, 0);
modelNode.scaleByUniform(3f);
modelNode.setPosition(1, 1, 2000);
modelNode.play();
// Add model node to image trackable
trackable.getWorld().addChild(modelNode);
modelNode.setVisible(true);
}
But I want to keep this 3D model even if I move away my camera away from marker. 但是,即使我将相机从标记上移开,我也希望保留3D模型。
The model is vanishing since there is no marker, of course. 该模型消失了,因为没有标记。 If you wish to keep drawing the model anyway at the same place, simply save the last position of the model on each frame, and draw the model at that position when the marker detection is lost.
如果您仍然希望继续在同一位置绘制模型,则只需将模型的最后位置保存在每帧上,然后在丢失标记检测的情况下在该位置绘制模型。 If you want to try and draw it at the exact same place in the world (and not the same place on screen), you can try using the device sensors to estimate the phone's movement and update the location of the model accordingly.
如果您想在世界上完全相同的位置(而不是屏幕上的相同位置)绘制它,可以尝试使用设备传感器来估计手机的移动并相应地更新模型的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.