Skip to content
Snippets Groups Projects
Commit 03897fbe authored by Johannes Eder's avatar Johannes Eder
Browse files

text can now be displayed in 3d editor

parent 302db596
No related branches found
No related tags found
No related merge requests found
Showing
with 327 additions and 31 deletions
......@@ -17,6 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphicsGL.ui.objects;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.changeTransformationMatrix;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.createBillboardMatrix;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.drawLine;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.drawMaterialGroups;
......@@ -27,13 +28,14 @@ import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.restoreMatrix;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.rotate;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.saveMatrix;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.setColor;
import static org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives.tranformationMatrix;
import static org.fortiss.tooling.graphicsGL.ui.util.Graph3DUtil.convert;
import static org.fortiss.tooling.graphicsGL.util.Graphics3DModelElementFactory.BLACK;
import static org.fortiss.tooling.graphicsGL.util.Graphics3DModelElementFactory.BLUE;
import static org.fortiss.tooling.graphicsGL.util.Graphics3DModelElementFactory.WHITE;
import static org.lwjgl.util.glu.GLU.GLU_FILL;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.fortiss.tooling.graphicsGL.model.Color3D;
......@@ -42,10 +44,12 @@ import org.fortiss.tooling.graphicsGL.model.graph.CoordinateSystem3D;
import org.fortiss.tooling.graphicsGL.model.graph.Graph3D;
import org.fortiss.tooling.graphicsGL.model.graph.GraphLine3D;
import org.fortiss.tooling.graphicsGL.model.graph.GraphPoint3D;
import org.fortiss.tooling.graphicsGL.model.graph.GraphText3D;
import org.fortiss.tooling.graphicsGL.model.scene.Object3D;
import org.fortiss.tooling.graphicsGL.ui.camera.Camera;
import org.fortiss.tooling.graphicsGL.ui.picker.ModelObjectPicker;
import org.fortiss.tooling.graphicsGL.util.OBJLoaderUtil;
import org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives;
import org.fortiss.tooling.graphicsGL.ui.util.Graph3DUtil;
import org.lwjgl.util.glu.Sphere;
import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;
......@@ -65,22 +69,17 @@ public class Graph3DViewObject extends ViewObjectBase {
/** The highlighted model object. */
private GraphPoint3D highlighted;
/** for testing text rendering */
private List<Object3D> testText;
/** the distance between letters in a text */
static float DISTANCE_BEWTWEEN_LETTERS = 0.7f;
/** Hashmap of all letters which can be rendered */
HashMap<String, Object3D> letters;
/** Constructor. */
public Graph3DViewObject(Graph3D graph) {
this.graph = graph;
letters = Graph3DUtil.importLetters();
File objFile = new File("C:\\Users\\eder\\Desktop\\obj_letters\\A.obj");
try {
OBJLoaderUtil obj = new OBJLoaderUtil(objFile);
testText = obj.getLoadedObjects();
} catch(IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
/** Sets the currently highlighted point. */
......@@ -112,22 +111,32 @@ public class Graph3DViewObject extends ViewObjectBase {
drawLine(l.getStart().getPosition(), l.getEnd().getPosition());
}
renderText(c);
setColor(BLACK);
for(GraphText3D t : graph.getTextsList()) {
renderText(c, t.getText(), convert(t.getPosition()));
}
setColor(WHITE);
}
/**
* render Text
*
* @param c
*/
private void renderText(Camera c) {
/** Renders objects as billboards at the given position */
private void renderText(Camera c, String s, Vector3f pos) {
List<Object3D> toRender = new ArrayList<Object3D>();
for(int i = 0; i < s.length(); ++i) {
String st = s.charAt(i) + "";
toRender.add(this.letters.get(st));
}
renderText(c, toRender, pos);
}
/** Renders objects as billboards at the given position */
private void renderText(Camera c, List<Object3D> objects, Vector3f pos) {
if(testText == null)
return;
saveMatrix();
Vector3f look = new Vector3f();
Vector3f pos = new Vector3f(0, 10, 0);
// Vector3f pos = new Vector3f(0, 10, 0);
Vector3f right = new Vector3f();
Vector3f up;
......@@ -145,15 +154,17 @@ public class Graph3DViewObject extends ViewObjectBase {
createBillboardMatrix(bbmat, right, up, look, pos);
// apply the billboard
tranformationMatrix(bbmat);
changeTransformationMatrix(bbmat);
// rotate text so it is readable from left to right
rotate(new Vector4f(0, 0, 1, -90));
// draw the Text
for(Object3D o : testText) {
for(Object3D o : objects) {
drawMaterialGroups(o.getMesh().getMaterialGroupsList());
GLPrimitives.translate(0, DISTANCE_BEWTWEEN_LETTERS, 0);
}
restoreMatrix();
}
......
......@@ -122,7 +122,7 @@ import org.newdawn.slick.Color;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 182FAD3DA57D24F0C095DAF64F82BB99
* @ConQAT.Rating YELLOW Hash: 25892D6CA7A35E798D1B71AAEC81A964
*/
public class GLPrimitives {
/** The X unit vector. */
......@@ -276,12 +276,12 @@ public class GLPrimitives {
}
/** Sets as new transformation matrix. */
public static void tranformationMatrix(float[] floatBuffer) {
tranformationMatrix(FloatBufferUtils.toFloatBuffer(floatBuffer));
public static void changeTransformationMatrix(float[] floatBuffer) {
changetransformationMatrix(FloatBufferUtils.toFloatBuffer(floatBuffer));
}
/** Sets as new transformation matrix. */
public static void tranformationMatrix(FloatBuffer floatBuffer) {
public static void changetransformationMatrix(FloatBuffer floatBuffer) {
glMultMatrix(floatBuffer);
}
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.graphicsGL.ui.util;
import static org.fortiss.tooling.graphicsGL.ToolingGraphicsGLActivator.PLUGIN_ID;
import static org.fortiss.tooling.graphicsGL.ui.ToolingGraphicsGLUIActivator.getDefault;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import static org.fortiss.tooling.kernel.utils.ResourceUtils.getStringContentFromResource;
import java.util.HashMap;
import java.util.List;
import org.fortiss.tooling.graphicsGL.model.Positioned3DBase;
import org.fortiss.tooling.graphicsGL.model.scene.Object3D;
import org.fortiss.tooling.graphicsGL.util.OBJLoaderUtil;
import org.lwjgl.util.vector.Vector3f;
/**
*
* @author eder
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class Graph3DUtil {
/** Array of letters which can be rendered */
public static final char[] IMPORTED_LETTERS = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
/** Array of special characters which can be rendered */
public static final char[] SPECIAL_CHARACTERS = {'?'};
/** Converts a Positioned3DBase Vector in a Vector3f */
public static Vector3f convert(Positioned3DBase pos) {
return new Vector3f(pos.getPosition().getX(), pos.getPosition().getY(), pos.getPosition()
.getZ());
}
/** */
public static HashMap<String, Object3D> importLetters() {
HashMap<String, Object3D> mapping = new HashMap<String, Object3D>();
for(char l : IMPORTED_LETTERS) {
String path = "/data/letters/" + l;
Object3D o = getObject(path);
String key = "" + l;
mapping.put(key, o);
}
return mapping;
}
/** Returns the object loaded from the given path. */
private static Object3D getObject(String modelPath) {
try {
List<String> objData = getStringContentFromResource(PLUGIN_ID, modelPath + ".obj");
List<String> mtlData = getStringContentFromResource(PLUGIN_ID, modelPath + ".mtl");
return new OBJLoaderUtil(objData, mtlData).getLoadedObjects().get(0);
} catch(Exception ex) {
error(getDefault(), ex.getMessage(), ex);
}
return null;
}
}
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment