1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.shapes;
\r
13 import java.net.URL;
\r
15 import org.eclipse.core.runtime.FileLocator;
\r
16 import org.eclipse.core.runtime.Path;
\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
28 public class FloorShape {
\r
30 private static String textureLocation = "src/jmetest/data/texture/Detail.jpg";
\r
32 public static Geometry getShape(Renderer renderer, float size, float texScale) {
\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
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
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
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
83 tex.setWrap(Texture.WM_WRAP_S_WRAP_T);
\r
85 shape.setRenderState(ts);
\r
86 shape.lockShadows();
\r