Mesh surfaces are usually textured.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgryzoUvli2fA-aY1lE2nOLQ313e11DvHXjyaRoN73IlrBGSoozZYtAf61eE6NDkXddwmDGJf7YYQAAVeYTQ5jv_zJfKExFjB0dDHFZUqQ-tcHhZyy792CEq5VJMQAN0JVO41Cz-bcNqjYz/s1600/java30+-+1.png)
Texture is a 2D image, and the 3D surface has to be UV mapped into 2D space.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgexZsTWYu_JMxjrXonhxdHD72yCRyLG1PiYDQwLZF8bNJml0A4kMe8RGf1e71c7-FPt0pRx2jZF7n1QwCMMUNpUmf1oiPzFuYg-_MA_HtrzCQey6UgUWPqYO3JduWZDcwoA-8ULreXtoLy/s1600/java30+-+2.png)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggvxRIfSgrVoJnDiBO_sr10piqLimVnbWbbBRSADp_pPT9li1F9igj_840Uth6ueR-KivrxS2-XRVPaJMF3NNwJbHOPn8Noaq3lTcY7Xo-717UM2so-oGe4qmeNf7zzQzEtVcy2mHHmk5J/s1600/java30+-+3.png)
Next from the UVs header menu, we have to select Export UV Layout, and save the image.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3jcPMllihuQdmgv6cCAGLAetwU0THofU5qW-cH3wOcAUEN4KxZZpt6iAfRczvgGx_j8RW5c4jZ8CimOgw328gFMowYwInlrwdghWAyTz9EGH2XY76HnHgBpPrgGb2r7fAvMqFGE7uPDNj/s1600/java30+-+4.png)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOXz_EyPtDm_a5rFxZWAZIzrmLp4MQ6Fl-fbHyFyJPm-QwNUxlW1O2jwsmnuW3xcvsG_I1YHbAGBlvVM3xLihwuhnSUT_XUy_5mhjZyKLXkDZFqPsvyjGBUCT44sQGUAQxCeFRQKjlLCOs/s1600/java30+-+5.png)
In the GIMP, the different slot corresponding to different surfaces, are filled in with a suitable pattern.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAgGtkVL7KBmSuOw5yAYYBM0YdYcBwACy4k8ax2wxQXlcP1lbAp3hSsGaCNxvGjzxQxvLS4lhOZHP4gzjjcX8UhDkEkpTbHNq0UFo_Q8US6-YvGOGclrgUCwCPJFGq1aCsrDudMB2FsKKr/s1600/java30+-+6.png)
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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvoJsClVKqmddZJlTtAB05Sanv2j6COaD3cdZ1ukmiY7-UUB_gtRdsvpzaR7K4mL60msAAlBFRvPIUWMPiOMASq51qrNifgPaCG3_1kuAkxb_z-e8jCy-oz4293Y7WMxCCn_YeFQxhl1nR/s1600/java30+-+7.png)
// 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