ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder mpb = modelBuilder.part("parts",
GL20.GL_TRIANGLES,
Usage.Position | Usage.Normal | Usage.ColorUnpacked,
new Material(ColorAttribute.createDiffuse(Color.WHITE)));
mpb.setColor(1f, 1f, 1f, 1f);
mpb.box(0, -1.5f, 0, 10, 1, 10);
mpb.setColor(1f, 0f, 1f, 1f);
mpb.sphere(2f, 2f, 2f, 10, 10);
model = modelBuilder.end();
instance = new ModelInstance(model);
不加投影
加上投影需要绘制两部分,一个是阴影,先绘制,需要使用DepthShader
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.ColorUnpacked,
new Material(ColorAttribute.createDiffuse(Color.WHITE)));
mpb.setColor(1f, 1f, 1f, 1f);
mpb.box(0, -1.5f, 0, 10, 1, 10);
mpb.setColor(1f, 0f, 1f, 1f);
mpb.sphere(2f, 2f, 2f, 10, 10);
model = modelBuilder.end();
instance = new ModelInstance(model);
shadowBatch = new ModelBatch(new DepthShaderProvider());
绘制投影
shadowLight.begin(Vector3.Zero, cam.direction);
shadowBatch.begin(shadowLight.getCamera());
shadowBatch.render(instance);
shadowBatch.end();
shadowLight.end();
//绘制模型
modelBatch.begin(cam);
modelBatch.render(instance, environment);
modelBatch.end();