本文介绍了在 LibGDX 中从 ModelBuilder 合并模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 LibGDX 3D 设施的新手,我想知道如何合并使用 ModelBuilder#createCylinder 类.我有两个模型实例:
I'm a new to LibGDX 3D facilities and I'm wondering how I can merge two cylinders created using the ModelBuilder#createCylinder class.I have two ModelInstances :
- 第一个是白色圆柱体,
- 第二个具有相同属性的红色圆柱体
如何让只渲染一个圆柱体(实例/模型/对象/任何可以渲染的东西)由白色上面的红色组成(反之亦然).
How can get only one cylinder to render (instance / model / object / whatever can be rendered) composed of the red above the white one (or vice versa).
Pixmap pixmap1 = new Pixmap(1, 1, Format.RGBA8888);
pixmap1.setColor(Color.WHITE);
pixmap1.fill();
Texture white = new Texture(pixmap1);
//...
Texture red = new Texture(pixmap2);
model1 = modelBuilder.createCylinder(4f, 6f, 4f, 16,
new Material(
TextureAttribute.createDiffuse(white),
ColorAttribute.createSpecular(1,1,1,1),
FloatAttribute.createShininess(8f))
, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
model1I_white = new ModelInstance(model1, 0, 0, 0);
//...
model2I_red = new ModelInstance(model2, 0, 0, -2f);
然后我用 ModelBatch#render.
推荐答案
您可以使用 MeshBuilder 类创建 2 个圆柱体,并使用 part() 组合您的最终圆柱体,而不是使用 createCylinder().
Instead of using createCylinder(), you can create 2 cylinders with the MeshBuilder class, and compose your final cylinder with part().
meshBuilder.begin();
meshBuilder.cylinder(4f, 6f, 4f, 16);
Mesh cylinder1 = meshBuilder.end();
meshBuilder.begin();
meshBuilder.cylinder(4f, 6f, 4f, 16);
Mesh cylinder2 = meshBuilder.end();
modelBuilder.begin();
modelBuilder.part("cylinder1",
cylinder1,
Usage.Position | Usage.Normal | Usage.TextureCoordinates,
new Material(
TextureAttribute.createDiffuse(white),
ColorAttribute.createSpecular(1,1,1,1),
FloatAttribute.createShininess(8f)));
modelBuilder.part("cylinder2",
cylinder2,
Usage.Position | Usage.Normal | Usage.TextureCoordinates,
new Material(
TextureAttribute.createDiffuse(red),
ColorAttribute.createSpecular(1,1,1,1),
FloatAttribute.createShininess(8f)))
.mesh.transform(new Matrix4().translate(0, 0, -2f));
Model finalCylinder = modelBuilder.end();
这篇关于在 LibGDX 中从 ModelBuilder 合并模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!