+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.proconf.g3d.shapes;\r
-\r
-import java.net.URL;\r
-\r
-import org.eclipse.core.runtime.FileLocator;\r
-import org.eclipse.core.runtime.Path;\r
-\r
-import com.jme.image.Texture;\r
-import com.jme.renderer.ColorRGBA;\r
-import com.jme.renderer.Renderer;\r
-import com.jme.scene.Geometry;\r
-import com.jme.scene.TriMesh;\r
-import com.jme.scene.state.MaterialState;\r
-import com.jme.scene.state.TextureState;\r
-import com.jme.util.TextureManager;\r
-import com.jme.util.geom.BufferUtils;\r
-\r
-public class FloorShape {\r
- \r
- private static String textureLocation = "src/jmetest/data/texture/Detail.jpg";\r
-\r
- public static Geometry getShape(Renderer renderer, float size, float texScale) {\r
-\r
- float coords[] = new float[3 * 4];\r
- float normals[] = new float[3 * 4];\r
- float texcoords[] = new float[2 * 4];\r
- int indices[] = new int[] { 0, 2, 1, 1, 2, 3 };\r
- coords[0] = -size;\r
- coords[1] = 0.f;\r
- coords[2] = -size;\r
- coords[3] = size;\r
- coords[4] = 0.f;\r
- coords[5] = -size;\r
- coords[6] = -size;\r
- coords[7] = 0.f;\r
- coords[8] = size;\r
- coords[9] = size;\r
- coords[10] = 0.f;\r
- coords[11] = size;\r
- texcoords[0] = -size*texScale;\r
- texcoords[1] = -size*texScale;\r
- texcoords[2] = size*texScale;\r
- texcoords[3] = -size*texScale;\r
- texcoords[4] = -size*texScale;\r
- texcoords[5] = size*texScale;\r
- texcoords[6] = size*texScale;\r
- texcoords[7] = size*texScale;\r
- normals[0] = 0.f;\r
- normals[1] = 1.f;\r
- normals[2] = 0.f;\r
- normals[3] = 0.f;\r
- normals[4] = 1.f;\r
- normals[5] = 0.f;\r
- normals[6] = 0.f;\r
- normals[7] = 1.0f;\r
- normals[8] = 0.f;\r
- normals[9] = 0.f;\r
- normals[10] = 1.f;\r
- normals[11] = 0.f;\r
- \r
- TriMesh shape = new TriMesh("",BufferUtils.createFloatBuffer(coords),BufferUtils.createFloatBuffer(normals),null,BufferUtils.createFloatBuffer(texcoords),BufferUtils.createIntBuffer(indices));\r
- MaterialState ms = renderer.createMaterialState();\r
- ms.setEmissive(new ColorRGBA(0.5f,0.5f,0.5f,0.f));\r
- ms.setDiffuse(new ColorRGBA(1.f,1.f,1.f,0.f));\r
- ms.setShininess(128.f);\r
- shape.setRenderState(ms);\r
- shape.setCullMode(Geometry.CULL_NEVER);\r
-\r
- TextureState ts = renderer.createTextureState();\r
- URL url = FileLocator.find(com.jme.eclipse.Activator.getDefault().getBundle(),new Path(textureLocation),null);\r
- Texture tex = TextureManager.loadTexture(url, Texture.MM_LINEAR_LINEAR,\r
- Texture.FM_LINEAR);\r
- tex.setWrap(Texture.WM_WRAP_S_WRAP_T);\r
- ts.setTexture(tex);\r
- shape.setRenderState(ts);\r
- shape.lockShadows();\r
- return shape;\r
- \r
- }\r
-\r
-}\r