从模型构建器中LibGDX合并模型 [英] Merging Models from ModelBuilder in LibGDX

查看:161
本文介绍了从模型构建器中LibGDX合并模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来LibGDX 3D设备,我想知道我怎么可以合并使用创建的<一两个汽缸href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/utils/ModelBuilder.html#createCylinder%28float,%20float,%20float,%20int,%20int,%20com.badlogic.gdx.graphics.g3d.Material,%20long%29"相对=nofollow>模型构建器#createCylinder class.I有两个ModelInstances:

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);

然后,我使ModelInstance与<一个href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/ModelBatch.html#render%28com.badlogic.gdx.graphics.g3d.Renderable%29"相对=nofollow> ModelBatch#呈现。

推荐答案

而不是使用createCylinder(),你可以创建2个气瓶与MeshBuilder类,并与部分()撰写最终的圆筒。

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合并模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆