1

我试图通过制作一个球体并从中取出所有网格部件并从该球体制作一个柔软的身体来制作一个柔软的身体。当我在 libgdx 中渲染它时,我使用了一个球体模型,以便软体可见,它随着软体的移动而转换,但很少有顶点粘在生成位置(原点)上,谁能建议我我做错了什么?

这是我的创建方法:

ModelBuilder modelBuilder1;
        modelBuilder1 = new ModelBuilder();
        final Material material = new Material(ColorAttribute.createDiffuse(Color.RED));
        final long attributes = VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal;
        final Model sphere = modelBuilder1.createSphere(2f, 2f, 2f, 24, 24, material, attributes);
        meshPart = sphere.meshParts.get(0);
        indexMap = BufferUtils.newShortBuffer(meshPart.size);
        positionOffset = meshPart.mesh.getVertexAttribute(VertexAttributes.Usage.Position).offset;
        normalOffset = meshPart.mesh.getVertexAttribute(VertexAttributes.Usage.Normal).offset;
        softBodyBall = new btSoftBody(worldInfo, meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset, 3, meshPart.mesh.getIndicesBuffer(), meshPart.offset, meshPart.size, indexMap, 0);
        softBodyBall.setPose(true, false);
        dynamicsWorld.addSoftBody(softBodyBall);
        btSoftBody.Material pm = softBodyBall.appendMaterial();
        softBodyBall.generateBendingConstraints(2, pm);
        pm.setKLST(0.9f);
        pm.setFlags(0);
        softBodyBall.generateBendingConstraints(2, pm);
        softBodyBall.setConfig_piterations(7);
        softBodyBall.setConfig_kDF(0.2f);
        softBodyBall.randomizeConstraints();
        softBodyBall.setTotalMass(1);
        softBodyBall.translate(new Vector3(1, 5, 1));
        instance = new ModelInstance(sphere);

这是我的渲染方法

 softBodyBall.getVertices(meshPart.mesh.getVerticesBuffer(), softBodyBall.getNodeCount(), meshPart.mesh.getVertexSize(), 0);
        softBodyBall.getWorldTransform(instance.transform);
        final float delta = Math.min(1f / 30f, Gdx.graphics.getDeltaTime());
        dynamicsWorld.stepSimulation(delta, 5, 1f / 30f);
        batch.begin(camera);
        batch.render(instance,environment);
        batch.render(instances, environment);
        batch.end();

这是图像的样子: https ://drive.google.com/file/d/1-9UjdlyIAotZPgrLKaoG0Dm5UEVLdzY1/view?usp=sharing

4

1 回答 1

0

找到了。需要渲染每个顶点。

softBodyBall.getVertices(meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset, normalOffset,
                meshPart.mesh.getIndicesBuffer(), meshPart.offset, meshPart.size, indexMap, 0);

这而不是

softBodyBall.getVertices(meshPart.mesh.getVerticesBuffer(), softBodyBall.getNodeCount(), meshPart.mesh.getVertexSize(), 0);
于 2019-08-05T10:24:15.110 回答