如何在我的代码中添加具有 shapefactory 形状(立方体)的自定义纹理?
How to add custom texture with shapefactory shape (cube) in my code?
我在我的项目中创建了一个白色立方体,如下所示。现在我想给它添加纹理。我该怎么做?
MaterialFactory.makeOpaqueWithColor(this, new Color(android.graphics.Color.WHITE))
.thenAccept(
material -> {
modelRenderable =
ShapeFactory.makeCube(new Vector3(0.8f, 0.15f, 0.8f),
new Vector3(0.0f, 0.0f, 0.0f),
material);
});
您必须创建一个纹理 material 并将其设置为您创建的形状,如下所示:
//sampler for the texture
val sampler = Texture.Sampler.builder()
.setWrapMode(Texture.Sampler.WrapMode.REPEAT)
.build()
Texture.builder()
.setSampler(sampler)
.setSource(this, R.drawable.your_drawable_texture)
.build()
.thenCompose { texture ->
MaterialFactory.makeOpaqueWithTexture(this, texture)
}
.thenAccept { material ->
ShapeFactory.makeCube(vector, vector, material)
}
我在我的项目中创建了一个白色立方体,如下所示。现在我想给它添加纹理。我该怎么做?
MaterialFactory.makeOpaqueWithColor(this, new Color(android.graphics.Color.WHITE))
.thenAccept(
material -> {
modelRenderable =
ShapeFactory.makeCube(new Vector3(0.8f, 0.15f, 0.8f),
new Vector3(0.0f, 0.0f, 0.0f),
material);
});
您必须创建一个纹理 material 并将其设置为您创建的形状,如下所示:
//sampler for the texture
val sampler = Texture.Sampler.builder()
.setWrapMode(Texture.Sampler.WrapMode.REPEAT)
.build()
Texture.builder()
.setSampler(sampler)
.setSource(this, R.drawable.your_drawable_texture)
.build()
.thenCompose { texture ->
MaterialFactory.makeOpaqueWithTexture(this, texture)
}
.thenAccept { material ->
ShapeFactory.makeCube(vector, vector, material)
}