【问题标题】:Missing Mesh class on RenderScript support libraryRenderScript 支持库上缺少 Mesh 类
【发布时间】:2014-07-03 17:53:13
【问题描述】:

我关注 this sample 是为了了解 RenderScript。我在 project.properties 中添加了以下内容:

renderscript.target=19
renderscript.support.mode=true
sdk.buildtools=23.0.2

我编写了我的 .rs 文件,ScriptC_myfilename 是在 gen 文件夹中生成的,但 android.support.v8.renderscript 无法解析为类型,因此我添加了位于 sdk 的 renderscript-v8.jar /build-tools/android-4.4W/renderscript/lib 作为库(配置构建路径 >> 库 >> 添加外部 JAR),问题已解决。

编码后,由于此错误,我无法编译代码,在 gen 文件夹的 ScriptC_filename.java 上找到:

Mesh cannot be resolved to a Type

我搜索了这个问题,试图找到丢失的类,我不知道,也许手动实现这个类作为我项目的一部分,所以 Eclipse 将被允许导入它并修复错误,但我我有点困惑,因为即使在 android docs 上也没有引用 Mesh 类。

我也尝试在sdk\build-tools\android-4.4.2\renderscript\lib导入renderscript-v8.jar,以及添加@ 987654328@但没有成功。

我不知道这是否有帮助,但这是我的 ScriptC_Snow.java 文件(这里的所有内容都是生成的,我没有编辑它),cmets 是 Eclipse 上显示的错误

    public class ScriptC_Snow extends ScriptC {
    private static final String __rs_resource_name = "snow";

    public  ScriptC_Snow(RenderScript rs) {
        this(rs,
             rs.getApplicationContext().getResources(),
             rs.getApplicationContext().getResources().getIdentifier(
                 __rs_resource_name, "raw",
                 rs.getApplicationContext().getPackageName()));
    }

    public  ScriptC_Snow(RenderScript rs, Resources resources, int id) {
        super(rs, resources, id);
        __MESH = Element.MESH(rs); //the method MESH(RenderScript) is undefined for the type Element
        __F32_2 = Element.F32_2(rs);
    }

    private Element __F32_2;
    private Element __MESH;
    private FieldPacker __rs_fp_F32_2;
    private FieldPacker __rs_fp_MESH;
    private final static int mExportVarIdx_snowMesh = 0;
    private Mesh mExportVar_snowMesh; // Mesh cannot be resolved to a type
    public synchronized void set_snowMesh(Mesh v) { // Mesh cannot be resolved to a type
        setVar(mExportVarIdx_snowMesh, v);
        mExportVar_snowMesh = v; // Mesh cannot be resolved to a type
    }

    public Mesh get_snowMesh() { // Mesh cannot be resolved to a type
        return mExportVar_snowMesh; // Mesh cannot be resolved to a type
    }

    public Script.FieldID getFieldID_snowMesh() {
        return createFieldID(mExportVarIdx_snowMesh, null);
    }

    private final static int mExportVarIdx_snow = 1;
    private ScriptField_Snow mExportVar_snow;
    public void bind_snow(ScriptField_Snow v) {
        mExportVar_snow = v;
        if (v == null) bindAllocation(null, mExportVarIdx_snow);
        else bindAllocation(v.getAllocation(), mExportVarIdx_snow);
    }

    public ScriptField_Snow get_snow() {
        return mExportVar_snow;
    }

    private final static int mExportVarIdx_wind = 2;
    private Float2 mExportVar_wind;
    public synchronized void set_wind(Float2 v) {
        mExportVar_wind = v;
        FieldPacker fp = new FieldPacker(8);
        fp.addF32(v);
        int []__dimArr = new int[1];
        __dimArr[0] = 4;
        setVar(mExportVarIdx_wind, fp, __F32_2, __dimArr);
    }

    public Float2 get_wind() {
        return mExportVar_wind;
    }

    public Script.FieldID getFieldID_wind() {
        return createFieldID(mExportVarIdx_wind, null);
    }

    private final static int mExportVarIdx_grav = 3;
    private Float2 mExportVar_grav;
    public synchronized void set_grav(Float2 v) {
        mExportVar_grav = v;
        FieldPacker fp = new FieldPacker(8);
        fp.addF32(v);
        int []__dimArr = new int[1];
        __dimArr[0] = 4;
        setVar(mExportVarIdx_grav, fp, __F32_2, __dimArr);
    }

    public Float2 get_grav() {
        return mExportVar_grav;
    }

    public Script.FieldID getFieldID_grav() {
        return createFieldID(mExportVarIdx_grav, null);
    }

    private final static int mExportFuncIdx_initSnow = 0;
    public void invoke_initSnow() {
        invoke(mExportFuncIdx_initSnow);
    }

}

这是我的渲染脚本代码(.rs 文件):

#pragma version(1)

#pragma rs java_package_name(com.mypackage.script)

#include "rs_graphics.rsh"

rs_mesh snowMesh;

typedef struct __attribute__((packed, aligned(4))) Snow {
enter code here
    float2 velocity;
    float2 position;
    uchar4 color;
enter code here
} Snow_t;

Snow_t *snow;

float2 wind;
float2 grav;

int root() {

    rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    rsgDrawMesh(snowMesh);
    return 0;

}

void init() {

    grav.x = 0;
    grav.y = 18;
    wind.x = rsRand(50)+20;
    wind.y = rsRand(4) - 2;

}

void initSnow() {
enter code here
    const float w = rsgGetWidth();
    const float h = rsgGetHeight();

    int snowCount = rsAllocationGetDimX(rsGetAllocation(snow));

    Snow_t *pSnow = snow;
    for (int i=0; i < snowCount; i++) {
        pSnow->position.x = rsRand(w);
        pSnow->position.y = rsRand(h);

        pSnow->velocity.y = rsRand(60);
        pSnow->velocity.x = rsRand(100);
        pSnow->velocity.x -= 50;

        uchar4 c = rsPackColorTo8888(255, 255, 255);
        pSnow->color = c;
        pSnow++;

    }

}

我只使用 SDK Manager 来获取文件,有什么我遗漏的吗?任何人都可以给我一个链接来下载最新版本的 renderscript-v8.jar 吗?是否有任何链接可以用来查看丢失的类,以便在我的项目中实现它,以便允许 Eclipse 导入和使用它?

提前致谢。

【问题讨论】:

  • 你能发布你的 RenderScript 代码吗?

标签: java android eclipse renderscript


【解决方案1】:

您不能将支持库与 rs_graphics.rsh 一起使用。它不支持像 rs_mesh、rs_font 或 rs_program* 这样的对象。支持库仅用于访问 RenderScript 计算。

【讨论】:

  • 哦,我现在看到docs.eoeandroid.com/reference/android/renderscript/…。 Mesh 类已弃用。但是,如果我不能使用 re_mesh,无论如何都可以使用渲染脚本来膨胀 1000 个粒子?我知道 OpenGL,但 RenderScript 看起来更好。你有什么建议吗?我想为各种粒子设置动画,只是出于学习的原因。谢谢@StephenHines
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多