Aug 25, 2014

30. UV Unwrap + Texture

Mesh surfaces are usually textured.




Texture is a 2D image, and the 3D surface has to be UV mapped into 2D space.




In Blender, we select all vertices in the Edit Mode. Then using Mesh header menu, we select UV Unwrap and Smart UV Project. The UV should now appear in the UV/Image Editor. We should create a new image file.




Next from the UVs header menu, we have to select Export UV Layout, and save the image.




Any image editing software can be used. We could even make the edits in UV/Image Editor in Blender. However, the software used most often is GIMP. The Bucket Fill tool quickly adds a pattern to the different slots for different surfaces. We have to make sure the patterns are tileable. If we need more control, we could also write a script to create a texture image.




In the GIMP, the different slot corresponding to different surfaces, are filled in with a suitable pattern.




After exporting the structure with a material and texture, we create a pyramid folder in Textures folder and put the files there, after renaming them.


// JMonkey30.java

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Spatial;
import com.jme3.system.AppSettings;

public class JMonkey30 extends SimpleApplication {
    public static void main(String[] args) {
        // App Settings
        AppSettings settings = new AppSettings(true);
        settings.setTitle("Pyramid!");
        settings.setFrameRate(60);
        JMonkey30 app = new JMonkey30();
        app.setSettings(settings);
        app.setDisplayFps(false);
        app.setDisplayStatView(false);
        app.start();
    }

    @Override
    public void simpleInitApp() {
        flyCam.setEnabled(false); // disable camera inputs
        viewPort.setBackgroundColor(ColorRGBA.LightGray); // background
        // Load model
        Spatial pyramid = assetManager.loadModel(
                "Textures/pyramid/pyramid.mesh.xml");
        // Ambient light
        AmbientLight ambient = new AmbientLight();
        ambient.setColor(ColorRGBA.White);
        rootNode.addLight(ambient);
        
        // Initial Rotation
        pyramid.rotate(45*FastMath.DEG_TO_RAD, 0, 0);
        rootNode.attachChild(pyramid);
    }

    @Override
    public void simpleUpdate(float tpf) {
        // Rotation per frame
        rootNode.rotate(0,0.005f,.005f);
    }

    @Override
    public void simpleRender(RenderManager rm) {
    }
}


Output:




No comments:

Post a Comment