5

In my first 3D game i now want to render the floor, which is actually a plane (not a libgdx Plane) on y = 0.

I want to add a Texture to it, so i can have different floors in each level.

Now my question is: What is the best way to create and render this textured floor?

I thought about using basic Block Models made with ModelBuilder and then added a Texture, but as i can only see 1 of 6 faces a 2d Texture would be enough, so i thought about a Plane.

Can i add a Texture to a Plane, as it is a infinite face in 3D room? The last thing i then thought about were the Decals.

Are Decals what i am looking for? And how can i use them? Or do you have an other solution .

Any tutorial or other help would be great.

Thanks

Swati
  • 2,870
  • 7
  • 45
  • 87
Robert P
  • 9,398
  • 10
  • 58
  • 100

1 Answers1

7

First about Decals, decals are like Sprites but in 3d coordinate, use it like this:

private Decal decal; private DecalBatch decalBatch;

in show() or create()

decalBatch = new DecalBatch();
CameraGroupStrategy cameraGroupStrategy = new CameraGroupStrategy(camera);
decal = Decal.newDecal(textureRegion, true);
decal.setPosition(5, 8, 1);
decal.setScale(0.02f);
decalBatch.setGroupStrategy(cameraGroupStrategy);

in render()

//Add all your decals then flush()
decalBatch.add(decal);
decalBatch.flush();

also dispose with decalBatch.dispose();

notice that in future decal will be part of 3d, I personally do not encourage you to use Decals as myself using 3d plane and I saw some problems with it, to use 3d plane use like these, i paste some of my codes here

private Model createPlaneModel(final float width, final float height, final Material material, 
            final float u1, final float v1, final float u2, final float v2) {

modelBuilder.begin();
MeshPartBuilder bPartBuilder = modelBuilder.part("rect", 
GL10.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, 
material);
//NOTE ON TEXTURE REGION, MAY FILL OTHER REGIONS, USE GET region.getU() and so on
bPartBuilder.setUVRange(u1, v1, u2, v2);
        bPartBuilder.rect(
                -(width*0.5f), -(height*0.5f), 0, 
                (width*0.5f), -(height*0.5f), 0, 
                (width*0.5f), (height*0.5f), 0, 
                -(width*0.5f), (height*0.5f), 0,
                0, 0, -1);


        return (modelBuilder.end());
    }

texture can be added as attribute to material

material.set(new TextureAttribute(TextureAttribute.Diffuse, texture)

for transparent plane that has alpha add to other attribute

attributes.add( new BlendingAttribute(color.getFloat(3)));          
attributes.add( new FloatAttribute(FloatAttribute.AlphaTest, 0.5f));

material.set(attributes);

Init the ModelInstance to get model that returned

modelInstance = new ModelInstance(createPlaneModel(...))

render in render() with ModelBatch object

modelBatch.render(modelInstance );

see these links too. http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=11884

this is my benchmark on Plane vs Decals http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=12493

daniel
  • 697
  • 5
  • 15
  • So at the moment i shouldn't use Decals? And with the MeshPartBuilder i can build 2D rects in 3D space? Thats exactly what i am looking for, as i want to create tilebased floor. With this method every tile would be a rect with a texture as material. Am i right? – Robert P Feb 13 '14 at 10:48
  • You can use whatever you want it depends on your usage if you have lots of trasparent then use plane else use decal or model, also notice if you want to render sprites then add sprites after modelbatch, the order is important, as I wrote you can use both decals and model decal is a bit memory friendly but you should test both see what is good for you. notice if you add higher value in u and v you have repeated textures. – daniel Feb 13 '14 at 10:55