]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/proconf/g3d/shapes/FloorShape.java
git-svn-id: https://www.simantics.org/svn/simantics/3d/trunk@22279 ac1ea38d-2e2b...
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / proconf / g3d / shapes / FloorShape.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.shapes;\r
12 \r
13 import java.net.URL;\r
14 \r
15 import org.eclipse.core.runtime.FileLocator;\r
16 import org.eclipse.core.runtime.Path;\r
17 \r
18 import com.jme.image.Texture;\r
19 import com.jme.renderer.ColorRGBA;\r
20 import com.jme.renderer.Renderer;\r
21 import com.jme.scene.Geometry;\r
22 import com.jme.scene.TriMesh;\r
23 import com.jme.scene.state.MaterialState;\r
24 import com.jme.scene.state.TextureState;\r
25 import com.jme.util.TextureManager;\r
26 import com.jme.util.geom.BufferUtils;\r
27 \r
28 public class FloorShape {\r
29         \r
30         private static String textureLocation = "src/jmetest/data/texture/Detail.jpg";\r
31 \r
32         public static Geometry getShape(Renderer renderer, float size, float texScale) {\r
33 \r
34                 float coords[] = new float[3 * 4];\r
35                 float normals[] = new float[3 * 4];\r
36                 float texcoords[] = new float[2 * 4];\r
37                 int indices[] = new int[] { 0, 2, 1, 1, 2, 3 };\r
38                 coords[0] = -size;\r
39                 coords[1] = 0.f;\r
40                 coords[2] = -size;\r
41                 coords[3] = size;\r
42                 coords[4] = 0.f;\r
43                 coords[5] = -size;\r
44                 coords[6] = -size;\r
45                 coords[7] = 0.f;\r
46                 coords[8] = size;\r
47                 coords[9] = size;\r
48                 coords[10] = 0.f;\r
49                 coords[11] = size;\r
50                 texcoords[0] = -size*texScale;\r
51                 texcoords[1] = -size*texScale;\r
52                 texcoords[2] = size*texScale;\r
53                 texcoords[3] = -size*texScale;\r
54                 texcoords[4] = -size*texScale;\r
55                 texcoords[5] = size*texScale;\r
56                 texcoords[6] = size*texScale;\r
57                 texcoords[7] = size*texScale;\r
58                 normals[0] = 0.f;\r
59                 normals[1] = 1.f;\r
60                 normals[2] = 0.f;\r
61                 normals[3] = 0.f;\r
62                 normals[4] = 1.f;\r
63                 normals[5] = 0.f;\r
64                 normals[6] = 0.f;\r
65                 normals[7] = 1.0f;\r
66                 normals[8] = 0.f;\r
67                 normals[9] = 0.f;\r
68                 normals[10] = 1.f;\r
69                 normals[11] = 0.f;\r
70       \r
71         TriMesh shape = new TriMesh("",BufferUtils.createFloatBuffer(coords),BufferUtils.createFloatBuffer(normals),null,BufferUtils.createFloatBuffer(texcoords),BufferUtils.createIntBuffer(indices));\r
72         MaterialState ms = renderer.createMaterialState();\r
73         ms.setEmissive(new ColorRGBA(0.5f,0.5f,0.5f,0.f));\r
74         ms.setDiffuse(new ColorRGBA(1.f,1.f,1.f,0.f));\r
75         ms.setShininess(128.f);\r
76         shape.setRenderState(ms);\r
77         shape.setCullMode(Geometry.CULL_NEVER);\r
78 \r
79         TextureState ts = renderer.createTextureState();\r
80         URL url = FileLocator.find(com.jme.eclipse.Activator.getDefault().getBundle(),new Path(textureLocation),null);\r
81         Texture tex = TextureManager.loadTexture(url, Texture.MM_LINEAR_LINEAR,\r
82                 Texture.FM_LINEAR);\r
83         tex.setWrap(Texture.WM_WRAP_S_WRAP_T);\r
84         ts.setTexture(tex);\r
85         shape.setRenderState(ts);\r
86         shape.lockShadows();\r
87         return shape;\r
88        \r
89     }\r
90 \r
91 }\r