如何动态更改使用RajawaliVR渲染的图像(How to dynamically change the image rendered using RajawaliVR)

编程入门 行业动态 更新时间:2024-10-27 06:28:41
如何动态更改使用RajawaliVR渲染的图像(How to dynamically change the image rendered using RajawaliVR) public class MyRenderer extends RajawaliCardboardRenderer { public MyRenderer(Context context) { super(context); } @Override public void initScene() { Log.d("debug1","initScene()"); Sphere sphere = createPhotoSphereWithTexture(new Texture("photo",R.drawable.image)); getCurrentScene().addChild(sphere); getCurrentCamera().setPosition(Vector3.ZERO); getCurrentCamera().setFieldOfView(75); } private static Sphere createPhotoSphereWithTexture(ATexture texture) { Material material = new Material(); material.setColor(0); try { material.addTexture(texture); } catch (ATexture.TextureException e) { throw new RuntimeException(e); } Sphere sphere = new Sphere(50, 64, 32); sphere.setScaleX(-1); sphere.setMaterial(material); return sphere; } }

目前,RajawaliVR库中预装了一个固定图像。 用于在开始时仅调用一次图像的方法。 我想在意志上改变图像。 任何熟悉使用rajawaliVR库的人都会知道我在问什么,提前谢谢。

public class MyRenderer extends RajawaliCardboardRenderer { public MyRenderer(Context context) { super(context); } @Override public void initScene() { Log.d("debug1","initScene()"); Sphere sphere = createPhotoSphereWithTexture(new Texture("photo",R.drawable.image)); getCurrentScene().addChild(sphere); getCurrentCamera().setPosition(Vector3.ZERO); getCurrentCamera().setFieldOfView(75); } private static Sphere createPhotoSphereWithTexture(ATexture texture) { Material material = new Material(); material.setColor(0); try { material.addTexture(texture); } catch (ATexture.TextureException e) { throw new RuntimeException(e); } Sphere sphere = new Sphere(50, 64, 32); sphere.setScaleX(-1); sphere.setMaterial(material); return sphere; } }

Currently there is a fixed image that is preloaded in the RajawaliVR library. The method that is used to set the image in called just once at the beginning. I want to change the image on will. Anyone who is familiar with using the rajawaliVR library will know what I am asking ,Thanks in advance.

最满意答案

得到解决方案后,您可以动态更改对象的图像纹理,如果在某些外部触发器上,则可以使用此代码示例。 每当触发触发时,您都可以调用changeImage方法。 别忘了在RajawaliCardboardRenderer中声明方法changeImage。 在MyRenderer对象上调用changeImage方法。

public class MyRenderer extends RajawaliCardboardRenderer { public MyRenderer(Context context) { super(context); } @Override public void initScene() { Log.d("debug1","initScene()"); Sphere sphere = createPhotoSphereWithTexture(new Texture("photo",R.drawable.image)); getCurrentScene().addChild(sphere); getCurrentCamera().setPosition(Vector3.ZERO); getCurrentCamera().setFieldOfView(75); } private static Sphere createPhotoSphereWithTexture(ATexture texture) { Material material = new Material(); material.setColor(0); try { material.addTexture(texture); } catch (ATexture.TextureException e) { throw new RuntimeException(e); } Sphere sphere = new Sphere(50, 64, 32); sphere.setScaleX(-1); sphere.setMaterial(material); return sphere; } public void changeImage() { Log.d("debug1", "" + getCurrentScene().getNumChildren()); ArrayList<Object3D> objectList = getCurrentScene().getChildrenCopy(); Material material = objectList.get(0).getMaterial(); for (ATexture texture : material.getTextureList()) { material.removeTexture(texture); texture = null; } Texture t = new Texture("sphereTexture",R.drawable.newImage); t.shouldRecycle(true); try { material.addTexture(t); } catch (Exception e){e.printStackTrace();} } }

Got the solution, you can dynamically change the image texture of your object say on some external trigger then you can use this code sample. You can call the changeImage method whenever a triggered is fired. Dont forget to declare the method changeImage in RajawaliCardboardRenderer. Call the changeImage method on MyRenderer object.

public class MyRenderer extends RajawaliCardboardRenderer { public MyRenderer(Context context) { super(context); } @Override public void initScene() { Log.d("debug1","initScene()"); Sphere sphere = createPhotoSphereWithTexture(new Texture("photo",R.drawable.image)); getCurrentScene().addChild(sphere); getCurrentCamera().setPosition(Vector3.ZERO); getCurrentCamera().setFieldOfView(75); } private static Sphere createPhotoSphereWithTexture(ATexture texture) { Material material = new Material(); material.setColor(0); try { material.addTexture(texture); } catch (ATexture.TextureException e) { throw new RuntimeException(e); } Sphere sphere = new Sphere(50, 64, 32); sphere.setScaleX(-1); sphere.setMaterial(material); return sphere; } public void changeImage() { Log.d("debug1", "" + getCurrentScene().getNumChildren()); ArrayList<Object3D> objectList = getCurrentScene().getChildrenCopy(); Material material = objectList.get(0).getMaterial(); for (ATexture texture : material.getTextureList()) { material.removeTexture(texture); texture = null; } Texture t = new Texture("sphereTexture",R.drawable.newImage); t.shouldRecycle(true); try { material.addTexture(t); } catch (Exception e){e.printStackTrace();} } }

更多推荐

本文发布于:2023-08-07 06:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   动态   RajawaliVR   dynamically   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!