我试图通过制造一个球并从中取出所有的网状球员来制作柔软的身体,并从该球体中制成柔软的身体。当我在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
找到了它。需要渲染每个顶点。
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);