Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使纹理可点击_Android_Opengl Es_3d Modelling - Fatal编程技术网

Android 使纹理可点击

Android 使纹理可点击,android,opengl-es,3d-modelling,Android,Opengl Es,3d Modelling,我已经在3D模型上添加了多个纹理,我只想在我的活动类中,当任何纹理被点击或点击时,都能得到通知。 欢迎任何帮助或建议 public static int loadTexture(final InputStream is) { Log.v("GLUtil", "Loading texture '" + is + "' from stream..."); final int[] textureHandle = new int[1];

我已经在3D模型上添加了多个纹理,我只想在我的活动类中,当任何纹理被点击或点击时,都能得到通知。 欢迎任何帮助或建议

public static int loadTexture(final InputStream is) {
            Log.v("GLUtil", "Loading texture '" + is + "' from stream...");

            final int[] textureHandle = new int[1];

            GLES20.glGenTextures(1, textureHandle, 0);
            GLUtil.checkGlError("glGenTextures");

            if (textureHandle[0] != 0) {
                Log.i("GLUtil", "Handler: " + textureHandle[0]);

                final BitmapFactory.Options options = new BitmapFactory.Options();
                options.inScaled = false;

                // Read in the resource
                final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
                if (bitmap == null) {
                    throw new RuntimeException("couldnt load bitmap");
                }

                // Bind to the texture in OpenGL
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
                GLUtil.checkGlError("glBindTexture");

                // Set filtering
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                        GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
                GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                        GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

                // Load the bitmap into the bound texture.
                GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
                GLUtil.checkGlError("texImage2D");
                // Recycle the bitmap, since its data has been loaded into OpenGL.
                bitmap.recycle();

            }

            if (textureHandle[0] == 0) {
                throw new RuntimeException("Error loading texture.");
            }

            return textureHandle[0];
        }

嗯,你无法检测到纹理上的点击。每个纹理都绑定到三维模型的特定面。您想要的是当用户单击纹理绑定到的其中一个多边形时进行检测。感谢@ProXicT的评论。有这样的链接吗?你需要弄清楚哪些纹理绑定到哪些多边形上。在将纹理应用于多边形时,您基本上知道这些信息。然后,只需测试多边形与从您的位置投射到3D光标位置的光线之间的碰撞(看看从2D到3D的未投射光标)。我肯定会使用彩色模型来区分模型的所有部分。正如我所说,我以前从来没有做过这样的事情,但我相信网上有一些技术介绍。谢谢,我会尝试为每个部分使用不同的颜色。感谢againIMHO,您无法检测到纹理上的点击。每个纹理都绑定到三维模型的特定面。您想要的是当用户单击纹理绑定到的其中一个多边形时进行检测。感谢@ProXicT的评论。有这样的链接吗?你需要弄清楚哪些纹理绑定到哪些多边形上。在将纹理应用于多边形时,您基本上知道这些信息。然后,只需测试多边形与从您的位置投射到3D光标位置的光线之间的碰撞(看看从2D到3D的未投射光标)。我肯定会使用彩色模型来区分模型的所有部分。正如我所说,我以前从来没有做过这样的事情,但我相信网上有一些技术介绍。谢谢,我会尝试为每个部分使用不同的颜色。再次感谢