Merge branch 'playground'
This commit is contained in:
commit
f18642eff9
BIN
data/g3d/test.g3db
Normal file
BIN
data/g3d/test.g3db
Normal file
Binary file not shown.
4748
data/g3d/test.g3dj
Normal file
4748
data/g3d/test.g3dj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
data/g3d/tree.png
Normal file
BIN
data/g3d/tree.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.1 KiB |
177
data/g3d/treeA.g3dj
Normal file
177
data/g3d/treeA.g3dj
Normal file
@ -0,0 +1,177 @@
|
||||
{
|
||||
"version": [ 0, 1],
|
||||
"id": "",
|
||||
"meshes": [
|
||||
{
|
||||
"attributes": ["POSITION", "NORMAL", "TEXCOORD0"],
|
||||
"vertices": [
|
||||
-0.003717, -0.043092, 0.000001, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, -0.019798, 0.000000, -0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, -0.009898, 0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.000001, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, -0.009898, 0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, -0.019798, 0.000000, 0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, 0.009901, 0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, 0.009901, 0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, 0.019801, 0.000000, -0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.019801, 0.000000, 0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, 0.009901, -0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, 0.009901, -0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, -0.009898, -0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, -0.009898, -0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.000052, 1.708732, 0.000001, 0.000000, 1.000000, 0.000000, 0.627643, 0.963260,
|
||||
-0.056858, 1.692897, -0.056805, -0.359325, 0.861232, -0.359325, 0.811107, 0.943917,
|
||||
-0.080388, 1.692897, 0.000001, -0.508194, 0.861232, 0.000000, 0.930977, 0.971962,
|
||||
-0.112293, 1.619116, -0.112239, -0.584552, 0.562639, -0.584552, 0.871491, 0.884983,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 1.012361, 0.910828,
|
||||
-0.176420, 1.422079, -0.176367, -0.675863, 0.293832, -0.675863, 0.903795, 0.728324,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 1.035246, 0.751852,
|
||||
-0.210746, 1.159339, -0.210693, -0.704306, 0.088870, -0.704306, 0.922129, 0.451029,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 1.045340, 0.473093,
|
||||
-0.210605, 0.903175, -0.210552, -0.705252, -0.072024, -0.705252, 0.936767, 0.254108,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 1.052424, 0.274946,
|
||||
-0.180964, 0.617981, -0.180911, -0.685263, -0.246529, -0.685263, 0.956801, 0.142573,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 1.061122, 0.161660,
|
||||
-0.116291, 0.378825, -0.116238, -0.610279, -0.505051, -0.610279, 0.991689, 0.079506,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 1.074527, 0.095355,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 1.038003, 0.052079,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 1.090933, 0.063214,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 0.090933, 0.063214,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 0.038003, 0.052079,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 0.127500, 0.036749,
|
||||
-0.000051, 0.290116, -0.083580, 0.000000, -0.817194, -0.576312, 0.994047, 0.033372,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 1.127500, 0.036749,
|
||||
-0.000051, 0.378825, -0.164386, 0.000000, -0.505051, -0.863063, 0.893772, 0.053663,
|
||||
-0.000052, 0.617981, -0.255847, 0.000000, -0.246529, -0.969115, 0.836458, 0.114704,
|
||||
-0.000052, 0.903175, -0.297766, 0.000000, -0.072024, -0.997375, 0.812221, 0.226047,
|
||||
-0.000052, 1.159339, -0.297966, 0.000000, 0.088870, -0.996033, 0.797565, 0.423137,
|
||||
-0.000052, 1.422079, -0.249421, 0.000000, 0.293832, -0.955840, 0.781975, 0.700922,
|
||||
-0.000052, 1.619116, -0.158731, 0.000000, 0.562639, -0.826655, 0.759783, 0.858997,
|
||||
-0.000052, 1.692897, -0.080335, 0.000000, 0.861232, -0.508194, 0.728165, 0.921879,
|
||||
0.056754, 1.692897, -0.056805, 0.359325, 0.861232, -0.359325, 0.652361, 0.910987,
|
||||
0.112189, 1.619116, -0.112239, 0.584552, 0.562639, -0.584552, 0.659906, 0.845090,
|
||||
0.176316, 1.422079, -0.176367, 0.675863, 0.293832, -0.675863, 0.665734, 0.684958,
|
||||
0.210643, 1.159339, -0.210693, 0.704306, 0.088870, -0.704306, 0.670277, 0.405750,
|
||||
0.210502, 0.903175, -0.210552, 0.705252, -0.072024, -0.705252, 0.675032, 0.207335,
|
||||
0.180860, 0.617981, -0.180910, 0.685263, -0.246529, -0.685263, 0.684415, 0.093825,
|
||||
0.116188, 0.378825, -0.116237, 0.610279, -0.505051, -0.610279, 0.723612, 0.027920,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 1.018456, 0.011649,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 0.018456, 0.011649,
|
||||
0.083530, 0.290116, 0.000002, 0.576159, -0.817316, 0.000000, 0.267608, 0.018648,
|
||||
0.164335, 0.378825, 0.000002, 0.863063, -0.505051, 0.000000, 0.457225, 0.035136,
|
||||
0.255796, 0.617981, 0.000002, 0.969115, -0.246529, 0.000000, 0.515690, 0.098717,
|
||||
0.297716, 0.903175, 0.000002, 0.997375, -0.072024, 0.000000, 0.532803, 0.211513,
|
||||
0.297915, 1.159339, 0.000002, 0.996033, 0.088870, 0.000000, 0.541872, 0.409545,
|
||||
0.249370, 1.422079, 0.000002, 0.955840, 0.293832, 0.000000, 0.550746, 0.688375,
|
||||
0.158680, 1.619116, 0.000002, 0.826655, 0.562639, 0.000000, 0.562378, 0.848006,
|
||||
0.080284, 1.692897, 0.000001, 0.508194, 0.861232, 0.000000, 0.577714, 0.913236,
|
||||
0.056754, 1.692897, 0.056808, 0.359325, 0.861232, 0.359325, 0.500528, 0.928224,
|
||||
0.112188, 1.619116, 0.112242, 0.584552, 0.562670, 0.584552, 0.459880, 0.866817,
|
||||
0.176316, 1.422079, 0.176370, 0.675863, 0.293832, 0.675863, 0.433163, 0.709519,
|
||||
0.210642, 1.159339, 0.210696, 0.704306, 0.088870, 0.704306, 0.415507, 0.432148,
|
||||
0.210501, 0.903175, 0.210555, 0.705252, -0.072024, 0.705252, 0.399773, 0.235351,
|
||||
0.180860, 0.617981, 0.180914, 0.685263, -0.246529, 0.685263, 0.375517, 0.124299,
|
||||
0.116187, 0.378825, 0.116241, 0.610279, -0.505051, 0.610279, 0.325269, 0.063109,
|
||||
0.059049, 0.290116, 0.059103, 0.407361, -0.817347, 0.407392, 0.248452, 0.040330,
|
||||
-0.000053, 0.290116, 0.083583, 0.000000, -0.817316, 0.576159, 0.199939, 0.056802,
|
||||
-0.000053, 0.378825, 0.164389, 0.000000, -0.505051, 0.863063, 0.234895, 0.086200,
|
||||
-0.000053, 0.617981, 0.255850, 0.000000, -0.246529, 0.969115, 0.262269, 0.150492,
|
||||
-0.000052, 0.903175, 0.297769, 0.000000, -0.072024, 0.997375, 0.278892, 0.262611,
|
||||
-0.000052, 1.159339, 0.297968, 0.000000, 0.088870, 0.996033, 0.291619, 0.459894,
|
||||
-0.000052, 1.422079, 0.249424, 0.000000, 0.293832, 0.955840, 0.308400, 0.737559,
|
||||
-0.000052, 1.619116, 0.158734, 0.000000, 0.562670, 0.826655, 0.340691, 0.894603,
|
||||
-0.000052, 1.692897, 0.080338, 0.000000, 0.861232, 0.508194, 0.411564, 0.953109,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 0.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 0.186319, 0.915857,
|
||||
-0.176420, 1.422079, 0.176369, -0.675863, 0.293832, 0.675863, 0.173739, 0.755927,
|
||||
-0.210747, 1.159339, 0.210696, -0.704306, 0.088870, 0.704306, 0.168491, 0.476740,
|
||||
-0.210606, 0.903175, 0.210555, -0.705252, -0.072024, 0.705252, 0.164886, 0.278291,
|
||||
-0.180964, 0.617981, 0.180913, -0.685263, -0.246529, 0.685263, 0.160531, 0.164632,
|
||||
-0.116292, 0.378825, 0.116240, -0.610279, -0.505051, 0.610279, 0.153922, 0.097744,
|
||||
-0.059154, 0.290116, 0.059102, -0.407453, -0.817255, 0.407483, 0.145909, 0.064880,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 0.074527, 0.095355,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 0.061122, 0.161660,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 0.052424, 0.274946,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 0.045340, 0.473093,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 0.035246, 0.751852,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 0.012361, 0.910828,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 1.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 1.186319, 0.915857
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"id": "mpart1",
|
||||
"type": "TRIANGLES",
|
||||
"indices": [
|
||||
0, 1, 2, 3, 4, 5, 0, 2, 6, 3, 7, 4,
|
||||
0, 6, 8, 3, 9, 7, 0, 8, 10, 3, 11, 9,
|
||||
0, 10, 12, 3, 13, 11, 12, 1, 0, 3, 5, 13,
|
||||
1, 5, 4, 1, 4, 2, 2, 4, 7, 2, 7, 6,
|
||||
6, 7, 9, 6, 9, 8, 8, 9, 11, 8, 11, 10,
|
||||
10, 11, 13, 10, 13, 12, 5, 1, 12, 5, 12, 13,
|
||||
14, 15, 16, 16, 15, 17, 16, 17, 18, 18, 17, 19,
|
||||
18, 19, 20, 20, 19, 21, 20, 21, 22, 22, 21, 23,
|
||||
22, 23, 24, 24, 23, 25, 24, 25, 26, 26, 25, 27,
|
||||
26, 27, 28, 28, 27, 29, 28, 29, 30, 31, 32, 33,
|
||||
29, 34, 35, 27, 36, 34, 27, 34, 29, 25, 37, 36,
|
||||
25, 36, 27, 23, 38, 37, 23, 37, 25, 21, 39, 38,
|
||||
21, 38, 23, 19, 40, 39, 19, 39, 21, 17, 41, 40,
|
||||
17, 40, 19, 15, 42, 41, 15, 41, 17, 15, 14, 42,
|
||||
42, 14, 43, 42, 43, 44, 42, 44, 41, 41, 44, 45,
|
||||
41, 45, 40, 40, 45, 46, 40, 46, 39, 39, 46, 47,
|
||||
39, 47, 38, 38, 47, 48, 38, 48, 37, 37, 48, 49,
|
||||
37, 49, 36, 36, 49, 50, 36, 50, 34, 34, 50, 35,
|
||||
51, 52, 33, 49, 53, 52, 49, 52, 50, 48, 54, 53,
|
||||
48, 53, 49, 47, 55, 54, 47, 54, 48, 46, 56, 55,
|
||||
46, 55, 47, 45, 57, 56, 45, 56, 46, 44, 58, 57,
|
||||
44, 57, 45, 43, 59, 58, 43, 58, 44, 43, 14, 59,
|
||||
59, 14, 60, 59, 60, 61, 59, 61, 58, 58, 61, 62,
|
||||
58, 62, 57, 57, 62, 63, 57, 63, 56, 56, 63, 64,
|
||||
56, 64, 55, 55, 64, 65, 55, 65, 54, 54, 65, 66,
|
||||
54, 66, 53, 53, 66, 67, 53, 67, 52, 52, 67, 33,
|
||||
67, 68, 33, 66, 69, 68, 66, 68, 67, 65, 70, 69,
|
||||
65, 69, 66, 64, 71, 70, 64, 70, 65, 63, 72, 71,
|
||||
63, 71, 64, 62, 73, 72, 62, 72, 63, 61, 74, 73,
|
||||
61, 73, 62, 60, 75, 74, 60, 74, 61, 60, 14, 75,
|
||||
75, 14, 76, 75, 76, 77, 75, 77, 74, 74, 77, 78,
|
||||
74, 78, 73, 73, 78, 79, 73, 79, 72, 72, 79, 80,
|
||||
72, 80, 71, 71, 80, 81, 71, 81, 70, 70, 81, 82,
|
||||
70, 82, 69, 69, 82, 83, 69, 83, 68, 68, 83, 33,
|
||||
83, 31, 33, 82, 84, 31, 82, 31, 83, 81, 85, 84,
|
||||
81, 84, 82, 80, 86, 85, 80, 85, 81, 79, 87, 86,
|
||||
79, 86, 80, 78, 88, 87, 78, 87, 79, 77, 89, 88,
|
||||
77, 88, 78, 90, 16, 18, 90, 18, 91, 90, 14, 16
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"diffuse": [ 0.900000, 0.900000, 0.900000],
|
||||
"specular": [ 0.100000, 0.100000, 0.100000],
|
||||
"textures": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"filename": "tree.png",
|
||||
"type": "DIFFUSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "treeA_root",
|
||||
"parts": [
|
||||
{
|
||||
"meshpartid": "mpart1",
|
||||
"materialid": "_tree.png",
|
||||
"uvMapping": [[ 0]]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"animations": []
|
||||
}
|
@ -14,3 +14,4 @@ include ':vtm-web-js'
|
||||
include ':vtm-ios'
|
||||
include ':vtm-jeo'
|
||||
include ':vtm-jeo-desktop'
|
||||
include ':vtm-playground'
|
||||
|
@ -82,7 +82,7 @@ public abstract class GdxMap implements ApplicationListener {
|
||||
mMapRenderer.onSurfaceChanged(w, h);
|
||||
|
||||
InputMultiplexer mux = new InputMultiplexer();
|
||||
mux.addProcessor(new InputHandler(mMap));
|
||||
mux.addProcessor(new InputHandler(this));
|
||||
//mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
|
||||
// new MapController(mMap)));
|
||||
mux.addProcessor(new MotionHandler(mMap));
|
||||
|
@ -16,10 +16,12 @@ public class InputHandler implements InputProcessor {
|
||||
private ViewController mViewport;
|
||||
private final Map mMap;
|
||||
private GenericLayer mGridLayer;
|
||||
private final GdxMap mGdxApp;
|
||||
|
||||
public InputHandler(Map map) {
|
||||
mViewport = map.viewport();
|
||||
mMap = map;
|
||||
public InputHandler(GdxMap map) {
|
||||
mMap = map.getMap();
|
||||
mViewport = mMap.viewport();
|
||||
mGdxApp = map;
|
||||
}
|
||||
|
||||
private boolean mActiveScale;
|
||||
@ -30,8 +32,8 @@ public class InputHandler implements InputProcessor {
|
||||
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
//if (onKeyDown(keycode))
|
||||
// return true;
|
||||
if (mGdxApp.onKeyDown(keycode))
|
||||
return true;
|
||||
|
||||
switch (keycode) {
|
||||
case Input.Keys.ESCAPE:
|
||||
|
@ -1,23 +0,0 @@
|
||||
repositories {
|
||||
// libgdx
|
||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'application'
|
||||
|
||||
mainClassName = 'org.oscim.jeo.test.LayerTest'
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs = ['src']
|
||||
main.resources.srcDirs = ['resources']
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':vtm-jeo')
|
||||
compile project(':vtm-desktop')
|
||||
// compile project(':vtm-themes')
|
||||
}
|
||||
|
||||
run { ignoreExitValue = true }
|
28
vtm-playground/build.gradle
Normal file
28
vtm-playground/build.gradle
Normal file
@ -0,0 +1,28 @@
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'application'
|
||||
|
||||
mainClassName = 'org.oscim.gdx.GdxMapApp'
|
||||
|
||||
// package vtm native libs into jar
|
||||
task copyLibs(type: Copy) {
|
||||
from(zipTree("../vtm-ext-libs/gdx/vtm-jni-natives.jar"))
|
||||
into("${buildDir}/assets")
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) { compileTask ->
|
||||
compileTask.dependsOn copyLibs
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs = ['src']
|
||||
main.resources.srcDirs = ["${buildDir}/assets"]
|
||||
output.resourcesDir = 'assets'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':vtm-desktop')
|
||||
compile project(':vtm-extras')
|
||||
compile project(':vtm-jeo')
|
||||
}
|
||||
|
||||
run { ignoreExitValue = true }
|
38
vtm-playground/src/org/oscim/test/AnimatorTest.java
Normal file
38
vtm-playground/src/org/oscim/test/AnimatorTest.java
Normal file
@ -0,0 +1,38 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.core.BoundingBox;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
public class AnimatorTest extends GdxMap {
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
MapRenderer.setBackgroundColor(0xff000000);
|
||||
|
||||
TileSource ts = new OSciMap4TileSource();
|
||||
initDefaultLayers(ts, false, false, false);
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 4);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
if (keycode == Input.Keys.NUM_1) {
|
||||
mMap.animator().animateTo(new BoundingBox(53.1, 8.8, 53.2, 8.9));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new AnimatorTest(), null, 256);
|
||||
}
|
||||
}
|
58
vtm-playground/src/org/oscim/test/BitmapLayerTest.java
Normal file
58
vtm-playground/src/org/oscim/test/BitmapLayerTest.java
Normal file
@ -0,0 +1,58 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources.HillShadeHD;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources.OpenStreetMap;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources.StamenToner;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources.StamenWatercolor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
public class BitmapLayerTest extends GdxMap {
|
||||
|
||||
final Logger log = LoggerFactory.getLogger(BitmapTileLayer.class);
|
||||
|
||||
BitmapTileLayer mLayer = null;
|
||||
|
||||
@Override
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
if (keycode == Input.Keys.NUM_1) {
|
||||
mMap.layers().remove(mLayer);
|
||||
mLayer = new BitmapTileLayer(mMap, new OpenStreetMap());
|
||||
mMap.layers().set(2, mLayer);
|
||||
return true;
|
||||
} else if (keycode == Input.Keys.NUM_2) {
|
||||
mMap.layers().remove(mLayer);
|
||||
mLayer = new BitmapTileLayer(mMap, new StamenWatercolor());
|
||||
mMap.layers().set(2, mLayer);
|
||||
return true;
|
||||
} else if (keycode == Input.Keys.NUM_3) {
|
||||
mMap.layers().remove(mLayer);
|
||||
mLayer = new BitmapTileLayer(mMap, new HillShadeHD());
|
||||
mMap.layers().set(2, mLayer);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
MapRenderer.setBackgroundColor(0xff888888);
|
||||
|
||||
mLayer = new BitmapTileLayer(mMap, new StamenToner());
|
||||
mMap.layers().add(mLayer);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new BitmapLayerTest(), null, 256);
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.IRenderTheme;
|
||||
import org.oscim.theme.ThemeLoader;
|
||||
import org.oscim.tiling.source.mapfile.MapFileTileSource;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
public class ExternalRenderThemeTest extends GdxMap {
|
||||
|
||||
VectorTileLayer mapLayer;
|
||||
|
||||
@Override
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
String name = null;
|
||||
if (keycode == Input.Keys.NUM_1)
|
||||
name = "themes/freizeitkarte/theme.xml";
|
||||
if (keycode == Input.Keys.NUM_2)
|
||||
name = "themes/elevate/theme.xml";
|
||||
if (keycode == Input.Keys.NUM_3)
|
||||
name = "themes/vmap/theme.xml";
|
||||
|
||||
if (name == null)
|
||||
return false;
|
||||
|
||||
try {
|
||||
IRenderTheme theme = ThemeLoader.load(name);
|
||||
mapLayer.setRenderTheme(theme);
|
||||
MapRenderer.setBackgroundColor(theme.getMapBackground());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
mMap.clearMap();
|
||||
mMap.updateMap(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
mMap.setMapPosition(53.08, 8.83, 1 << 14);
|
||||
|
||||
// TileSource tileSource = new OSciMap4TileSource();
|
||||
|
||||
MapFileTileSource tileSource = new MapFileTileSource();
|
||||
// tileSource.setMapFile("/home/jeff/src/vtm/Freizeitkarte_DEU_NW.map");
|
||||
tileSource.setMapFile("/home/jeff/germany.map");
|
||||
|
||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||
mapLayer = l;
|
||||
|
||||
// mMap.getLayers().add(new BuildingLayer(mMap, l.getTileLayer()));
|
||||
mMap.layers().add(new LabelLayer(mMap, l));
|
||||
|
||||
try {
|
||||
IRenderTheme theme = ThemeLoader
|
||||
.load("themes/freizeitkarte/theme.xml");
|
||||
// IRenderTheme theme =
|
||||
// ThemeLoader.load("themes/elevate/theme.xml");
|
||||
// IRenderTheme theme = ThemeLoader.load("themes/vmap/theme.xml");
|
||||
l.setRenderTheme(theme);
|
||||
MapRenderer.setBackgroundColor(theme.getMapBackground());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// mMap.getLayers().add(new GenericLayer(mMap, new MeshRenderer()));
|
||||
// mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new ExternalRenderThemeTest(), null, 256);
|
||||
}
|
||||
}
|
209
vtm-playground/src/org/oscim/test/LineRenderTest.java
Normal file
209
vtm-playground/src/org/oscim/test/LineRenderTest.java
Normal file
@ -0,0 +1,209 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint.Cap;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.renderer.ElementRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.renderer.elements.LineLayer;
|
||||
import org.oscim.renderer.elements.LineTexLayer;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
public class LineRenderTest extends GdxMap {
|
||||
|
||||
GeometryBuffer mGeom = new GeometryBuffer(2, 1);
|
||||
GeometryBuffer mLine = new GeometryBuffer(2, 1);
|
||||
|
||||
static boolean fixedLineWidth = true;
|
||||
LineTest l = new LineTest();
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
MapRenderer.setBackgroundColor(0xff000000);
|
||||
|
||||
// TileSource ts = new OSciMap4TileSource();
|
||||
// ts.setOption("url", "http://opensciencemap.org/tiles/vtm");
|
||||
// initDefaultLayers(ts, false, false, false);
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 4);
|
||||
|
||||
GeometryBuffer g = mLine;
|
||||
g.startLine();
|
||||
g.addPoint(-100, 0);
|
||||
g.addPoint(100, 0);
|
||||
|
||||
addLines(l, 0, true, false);
|
||||
|
||||
mMap.layers().add(new GenericLayer(mMap, l));
|
||||
}
|
||||
|
||||
void addLines(LineTest l, int layer, boolean addOutline, boolean fixed) {
|
||||
|
||||
GeometryBuffer g = mLine;
|
||||
|
||||
LineStyle line1, line2, line3, line4;
|
||||
|
||||
if (fixed) {
|
||||
line1 = new LineStyle(Color.RED, 0.5f);
|
||||
line2 = new LineStyle(Color.GREEN, 1);
|
||||
line3 = new LineStyle(Color.BLUE, 2);
|
||||
line4 = new LineStyle(Color.LTGRAY, 3);
|
||||
|
||||
} else {
|
||||
line1 = new LineStyle(0, null, Color.fade(Color.RED, 0.5f), 4.0f,
|
||||
Cap.BUTT, false, 0, 0, 0, 0, 1f, false);
|
||||
|
||||
line2 = new LineStyle(0, null, Color.GREEN, 6.0f, Cap.BUTT, true, 0, 0,
|
||||
0, 0, 1f, false);
|
||||
|
||||
line4 = new LineStyle(0, null, Color.LTGRAY, 2.0f, Cap.ROUND, false, 0,
|
||||
0, 0, 0, 1f, false);
|
||||
}
|
||||
|
||||
line3 = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, true, 4,
|
||||
Color.CYAN, 1, 0, 0, false);
|
||||
|
||||
LineStyle outline = new LineStyle(0, null, Color.BLUE, 2.0f, Cap.ROUND, false, 0,
|
||||
0, 0, 0, 1f, true);
|
||||
|
||||
LineStyle outline2 = new LineStyle(0, null, Color.RED, 2.0f, Cap.ROUND, false, 0,
|
||||
0, 0, 0, 0, true);
|
||||
|
||||
LineLayer ol = l.layers.addLineLayer(0, outline);
|
||||
LineLayer ol2 = l.layers.addLineLayer(5, outline2);
|
||||
|
||||
LineLayer ll = l.layers.addLineLayer(10, line1);
|
||||
ll.addLine(g.translate(0, -20));
|
||||
ll.addLine(g.translate(0, 10.5f));
|
||||
addCircle(-200, -200, 100, ll);
|
||||
|
||||
if (addOutline)
|
||||
ol.addOutline(ll);
|
||||
|
||||
ll = l.layers.addLineLayer(20, line2);
|
||||
ll.addLine(g.translate(0, 10.5f));
|
||||
ll.addLine(g.translate(0, 10.5f));
|
||||
addCircle(200, -200, 100, ll);
|
||||
|
||||
if (addOutline)
|
||||
ol.addOutline(ll);
|
||||
|
||||
LineTexLayer lt = l.layers.getLineTexLayer(30);
|
||||
lt.line = line3;
|
||||
lt.addLine(g.translate(0, 10.5f));
|
||||
lt.addLine(g.translate(0, 10.5f));
|
||||
addCircle(200, 200, 100, lt);
|
||||
|
||||
// if (addOutline)
|
||||
// ol2.addOutline(ll);
|
||||
|
||||
ll = l.layers.addLineLayer(40, line4);
|
||||
ll.addLine(g.translate(0, 10.5f));
|
||||
ll.addLine(g.translate(0, 10.5f));
|
||||
addCircle(-200, 200, 100, ll);
|
||||
|
||||
if (addOutline)
|
||||
ol2.addOutline(ll);
|
||||
}
|
||||
|
||||
void addCircle(float cx, float cy, float radius, LineLayer ll) {
|
||||
GeometryBuffer g = mGeom;
|
||||
|
||||
g.clear();
|
||||
g.startLine();
|
||||
g.addPoint(cx, cy);
|
||||
g.addPoint(cx, cy);
|
||||
|
||||
for (int i = 0; i < 60; i++) {
|
||||
double d = Math.toRadians(i * 6);
|
||||
g.setPoint(1, cx + (float) Math.sin(d) * radius,
|
||||
cy + (float) Math.cos(d) * radius);
|
||||
ll.addLine(g);
|
||||
}
|
||||
}
|
||||
|
||||
void addCircle(float cx, float cy, float radius, LineTexLayer ll) {
|
||||
GeometryBuffer g = mGeom;
|
||||
|
||||
g.clear();
|
||||
g.startLine();
|
||||
g.addPoint(cx, cy);
|
||||
g.addPoint(cx, cy);
|
||||
|
||||
for (int i = 0; i < 60; i++) {
|
||||
double d = Math.toRadians(i * 6);
|
||||
g.setPoint(1, cx + (float) Math.sin(d) * radius,
|
||||
cy + (float) Math.cos(d) * radius);
|
||||
ll.addLine(g);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
if (keycode < Input.Keys.NUM_1 || keycode > Input.Keys.NUM_4)
|
||||
return false;
|
||||
|
||||
synchronized (l) {
|
||||
l.clear();
|
||||
|
||||
GeometryBuffer g = mLine;
|
||||
g.clear();
|
||||
g.startLine();
|
||||
g.addPoint(-100, 0);
|
||||
g.addPoint(100, 0);
|
||||
|
||||
if (keycode == Input.Keys.NUM_1)
|
||||
addLines(l, 0, true, true);
|
||||
else if (keycode == Input.Keys.NUM_2)
|
||||
addLines(l, 0, true, false);
|
||||
else if (keycode == Input.Keys.NUM_3)
|
||||
addLines(l, 0, false, true);
|
||||
else if (keycode == Input.Keys.NUM_4)
|
||||
addLines(l, 0, false, false);
|
||||
}
|
||||
|
||||
mMap.updateMap(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class LineTest extends ElementRenderer {
|
||||
|
||||
public LineTest() {
|
||||
mMapPosition.scale = 0;
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
layers.clear();
|
||||
setReady(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void update(GLViewport v) {
|
||||
|
||||
if (mMapPosition.scale == 0)
|
||||
mMapPosition.copy(v.pos);
|
||||
|
||||
if (!isReady()) {
|
||||
compile();
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void setMatrix(MapPosition pos, Matrices m, boolean
|
||||
// project) {
|
||||
// m.useScreenCoordinates(true, 8f);
|
||||
// }
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new LineRenderTest(), null, 256);
|
||||
}
|
||||
}
|
110
vtm-playground/src/org/oscim/test/LineTest.java
Normal file
110
vtm-playground/src/org/oscim/test/LineTest.java
Normal file
@ -0,0 +1,110 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.renderer.ElementRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.renderer.elements.LineLayer;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
public class LineTest extends GdxMap {
|
||||
|
||||
@Override
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
if (keycode == Input.Keys.NUM_1) {
|
||||
angle++;
|
||||
mMap.render();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if (keycode == Input.Keys.NUM_2) {
|
||||
angle--;
|
||||
mMap.render();
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float angle = 0;
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
mMap.layers().add(new GenericLayer(mMap, new ElementRenderer() {
|
||||
boolean init;
|
||||
|
||||
LineLayer ll = layers.addLineLayer(0,
|
||||
new LineStyle(Color.fade(Color.CYAN, 0.5f), 1.5f));
|
||||
|
||||
GeometryBuffer g = new GeometryBuffer(10, 1);
|
||||
|
||||
@Override
|
||||
protected void update(GLViewport v) {
|
||||
if (!init) {
|
||||
mMapPosition.copy(v.pos);
|
||||
init = true;
|
||||
|
||||
// g.addPoint(0, 0);
|
||||
// g.addPoint(0, 1);
|
||||
// g.addPoint(0.1f, 0);
|
||||
//
|
||||
// g.addPoint(1, 1);
|
||||
// g.addPoint(2, 0);
|
||||
//
|
||||
// g.addPoint(2, 1);
|
||||
// g.addPoint(2, 0);
|
||||
//
|
||||
// g.addPoint(3, 1);
|
||||
// g.addPoint(3, 0);
|
||||
// g.addPoint(3, 1);
|
||||
//
|
||||
// for (int i = 0; i < 60; i++){
|
||||
// g.startLine();
|
||||
// g.addPoint(0, 0);
|
||||
// g.addPoint(0, 1);
|
||||
// }
|
||||
//
|
||||
// g.scale(100, 100);
|
||||
//
|
||||
// ll.addLine(g);
|
||||
//
|
||||
// compile();
|
||||
}
|
||||
|
||||
layers.clear();
|
||||
layers.setBaseLayers(ll);
|
||||
g.clear();
|
||||
for (int i = 0; i < 60; i++) {
|
||||
g.startLine();
|
||||
g.addPoint(-1, 0);
|
||||
g.addPoint(0, 0);
|
||||
g.addPoint((float) Math.cos(Math.toRadians(angle)),
|
||||
(float) Math.sin(Math.toRadians(angle)));
|
||||
}
|
||||
|
||||
g.scale(100, 100);
|
||||
|
||||
ll.addLine(g);
|
||||
|
||||
compile();
|
||||
|
||||
angle = Gdx.input.getX() / 2f % 360;
|
||||
|
||||
MapRenderer.animate();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new LineTest(), null, 256);
|
||||
}
|
||||
}
|
32
vtm-playground/src/org/oscim/test/MapTest.java
Normal file
32
vtm-playground/src/org/oscim/test/MapTest.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MapTest extends GdxMap {
|
||||
|
||||
final Logger log = LoggerFactory.getLogger(MeshTest.class);
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
|
||||
VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
|
||||
mMap.layers().add(new LabelLayer(mMap, l));
|
||||
|
||||
mMap.setMapPosition(53.08, 8.82, 1 << 17);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new MapTest(), null, 400);
|
||||
}
|
||||
}
|
37
vtm-playground/src/org/oscim/test/MapsforgeTest.java
Normal file
37
vtm-playground/src/org/oscim/test/MapsforgeTest.java
Normal file
@ -0,0 +1,37 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.source.mapfile.MapFileTileSource;
|
||||
|
||||
public class MapsforgeTest extends GdxMap {
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
MapRenderer.setBackgroundColor(0xff888888);
|
||||
|
||||
mMap.setMapPosition(53.072, 8.80, 1 << 15);
|
||||
// mMap.setMapPosition(52.5, 13.3, 1 << 15);
|
||||
|
||||
MapFileTileSource tileSource = new MapFileTileSource();
|
||||
tileSource.setMapFile("/home/jeff/germany.map");
|
||||
|
||||
VectorTileLayer l = mMap.setBaseMap(tileSource);
|
||||
|
||||
// mMap.getLayers().add(new BuildingLayer(mMap, l.getTileLayer()));
|
||||
mMap.layers().add(new LabelLayer(mMap, l));
|
||||
|
||||
// mMap.setTheme(VtmThemes.DEFAULT);
|
||||
// mMap.setTheme(VtmThemes.TRONRENDER);
|
||||
mMap.setTheme(VtmThemes.OSMARENDER);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new MapsforgeTest(), null, 400);
|
||||
}
|
||||
}
|
46
vtm-playground/src/org/oscim/test/MeshTest.java
Normal file
46
vtm-playground/src/org/oscim/test/MeshTest.java
Normal file
@ -0,0 +1,46 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.s3db.S3DBLayer;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
|
||||
public class MeshTest extends GdxMapApp {
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
//MapRenderer.setBackgroundColor(0xf0f0f0);
|
||||
|
||||
//VectorTileLayer l = mMap.setBaseMap(new OSciMap4TileSource());
|
||||
//mMap.setTheme(VtmThemes.DEFAULT);
|
||||
|
||||
mMap.setBackgroundMap(new BitmapTileLayer(mMap, new DefaultSources.StamenToner()));
|
||||
|
||||
TileSource ts = new OSciMap4TileSource("http://opensciencemap.org/tiles/s3db");
|
||||
S3DBLayer tl = new S3DBLayer(mMap, ts);
|
||||
|
||||
//BuildingLayer tl = new BuildingLayer(mMap, l);
|
||||
|
||||
//OffscreenRenderer or = new OffscreenRenderer(mMap.getWidth(),
|
||||
// mMap.getHeight());
|
||||
//or.setRenderer(tl.getRenderer());
|
||||
|
||||
mMap.layers().add(tl);
|
||||
|
||||
//mMap.layers().add(new GenericLayer(mMap, or));
|
||||
|
||||
//mMap.layers().add(new LabelLayer(mMap, l));
|
||||
|
||||
//mMap.setMapPosition(7.707, 81.689, 1 << 17);
|
||||
|
||||
mMap.setMapPosition(53.08, 8.82, 1 << 17);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
init();
|
||||
run(new MeshTest(), null, 400);
|
||||
}
|
||||
}
|
123
vtm-playground/src/org/oscim/test/RuleVisitorTest.java
Normal file
123
vtm-playground/src/org/oscim/test/RuleVisitorTest.java
Normal file
@ -0,0 +1,123 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import static org.oscim.utils.ColorUtil.saturate;
|
||||
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.RenderTheme;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.theme.rule.Rule;
|
||||
import org.oscim.theme.rule.Rule.RuleVisitor;
|
||||
import org.oscim.theme.styles.AreaStyle;
|
||||
import org.oscim.theme.styles.AreaStyle.AreaBuilder;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.theme.styles.LineStyle.LineBuilder;
|
||||
import org.oscim.theme.styles.RenderStyle;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
|
||||
public class RuleVisitorTest extends GdxMap {
|
||||
|
||||
final Logger log = LoggerFactory.getLogger(RuleVisitorTest.class);
|
||||
RenderTheme mTheme;
|
||||
double mSaturation = 1;
|
||||
|
||||
@Override
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
VectorTileLayer l = (VectorTileLayer) mMap.layers().get(1);
|
||||
RenderTheme t = (RenderTheme) l.getTheme();
|
||||
|
||||
if (keycode == Input.Keys.NUM_1) {
|
||||
mSaturation += 0.1;
|
||||
t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
|
||||
t.updateStyles();
|
||||
mMap.render();
|
||||
return true;
|
||||
}
|
||||
if (keycode == Input.Keys.NUM_2) {
|
||||
mSaturation -= 0.1;
|
||||
t.traverseRules(new SaturateLineStyles(mSaturation, true, true, true));
|
||||
t.updateStyles();
|
||||
mMap.render();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onKeyDown(keycode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
MapRenderer.setBackgroundColor(0xf0f0f0);
|
||||
|
||||
TileSource ts = new OSciMap4TileSource();
|
||||
VectorTileLayer l = mMap.setBaseMap(ts);
|
||||
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
RenderTheme t = (RenderTheme) l.getTheme();
|
||||
mTheme = t;
|
||||
//t.traverseRules(new DesaturateAreaStyles());
|
||||
//t.traverseRules(new DesaturateLineStyles());
|
||||
t.traverseRules(new SaturateLineStyles(0.5, true, true, true));
|
||||
t.updateStyles();
|
||||
|
||||
//mMap.setMapPosition(7.707, 81.689, 1 << 16);
|
||||
|
||||
mMap.setMapPosition(53.08, 8.82, 1 << 16);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new RuleVisitorTest(), null, 400);
|
||||
}
|
||||
|
||||
static class SaturateLineStyles extends RuleVisitor {
|
||||
private final LineBuilder lineBuilder = new LineBuilder();
|
||||
private final AreaBuilder areaBuilder = new AreaBuilder();
|
||||
|
||||
private final double saturation;
|
||||
private final boolean modifyArea;
|
||||
private final boolean modifyLine;
|
||||
private final boolean relative;
|
||||
|
||||
public SaturateLineStyles(double saturation, boolean relative, boolean modArea,
|
||||
boolean modLine) {
|
||||
this.saturation = saturation;
|
||||
this.modifyArea = modArea;
|
||||
this.modifyLine = modLine;
|
||||
this.relative = relative;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Rule r) {
|
||||
for (RenderStyle style : r.styles) {
|
||||
|
||||
if (modifyLine && style instanceof LineStyle) {
|
||||
LineStyle s = (LineStyle) style;
|
||||
|
||||
s.set(lineBuilder.set(s)
|
||||
.color(saturate(s.color, saturation, relative))
|
||||
.stippleColor(saturate(s.stippleColor, saturation, relative))
|
||||
.build());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (modifyArea && style instanceof AreaStyle) {
|
||||
AreaStyle s = (AreaStyle) style;
|
||||
|
||||
s.set(areaBuilder.set(s)
|
||||
.color(saturate(s.color, saturation, relative))
|
||||
.blendColor(saturate(s.blendColor, saturation, relative))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
super.apply(r);
|
||||
}
|
||||
}
|
||||
}
|
70
vtm-playground/src/org/oscim/test/TessellatorTest.java
Normal file
70
vtm-playground/src/org/oscim/test/TessellatorTest.java
Normal file
@ -0,0 +1,70 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import static java.lang.System.out;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.utils.Tessellator;
|
||||
|
||||
import com.badlogic.gdx.utils.SharedLibraryLoader;
|
||||
|
||||
public class TessellatorTest extends Tessellator{
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
|
||||
GeometryBuffer e = new GeometryBuffer(128, 3);
|
||||
|
||||
int size = Tile.SIZE;
|
||||
|
||||
float x1 = -1;
|
||||
float y1 = -1;
|
||||
float x2 = size + 1;
|
||||
float y2 = size + 1;
|
||||
|
||||
// always clear geometry before starting
|
||||
// a different type.
|
||||
e.clear();
|
||||
e.startPolygon();
|
||||
e.addPoint(x1, y1);
|
||||
e.addPoint(x2, y1);
|
||||
e.addPoint(x2, y2);
|
||||
e.addPoint(x1, y2);
|
||||
|
||||
y1 = 5;
|
||||
y2 = size - 5;
|
||||
x1 = 5;
|
||||
x2 = size - 5;
|
||||
|
||||
e.startHole();
|
||||
e.addPoint(x1, y1);
|
||||
e.addPoint(x2, y1);
|
||||
e.addPoint(x2, y2);
|
||||
e.addPoint(x1, y2);
|
||||
|
||||
addMesh(e);
|
||||
}
|
||||
|
||||
static void addMesh(GeometryBuffer geom) {
|
||||
int numRings = 2;
|
||||
int[] result = new int[2];
|
||||
|
||||
long ctx = Tessellator.tessellate(geom.points, 0, geom.index, 0, numRings, result);
|
||||
out.println("ok" + Arrays.toString(result));
|
||||
|
||||
short[] coordinates = new short[100];
|
||||
|
||||
while (Tessellator.tessGetVertices(ctx, coordinates, 2) > 0) {
|
||||
out.println(Arrays.toString(coordinates));
|
||||
}
|
||||
|
||||
while (Tessellator.tessGetIndices(ctx, coordinates) > 0) {
|
||||
out.println(Arrays.toString(coordinates));
|
||||
}
|
||||
|
||||
Tessellator.tessFinish(ctx);
|
||||
}
|
||||
|
||||
}
|
48
vtm-playground/src/org/oscim/test/ThemeTest.java
Normal file
48
vtm-playground/src/org/oscim/test/ThemeTest.java
Normal file
@ -0,0 +1,48 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.oscim.awt.AwtGraphics;
|
||||
import org.oscim.backend.AssetAdapter;
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.core.TagSet;
|
||||
import org.oscim.theme.IRenderTheme;
|
||||
import org.oscim.theme.ThemeLoader;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.theme.styles.RenderStyle;
|
||||
|
||||
public class ThemeTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
AwtGraphics.init();
|
||||
AssetAdapter.g = new AssetAdapter() {
|
||||
@Override
|
||||
public InputStream openFileAsStream(String name) {
|
||||
try {
|
||||
return new FileInputStream("/home/jeff/src/vtm/OpenScienceMap/vtm/assets/"
|
||||
+ name);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
IRenderTheme t = ThemeLoader.load(VtmThemes.DEFAULT);
|
||||
|
||||
TagSet tags = new TagSet();
|
||||
tags.add(new Tag("highway", "trunk_link"));
|
||||
tags.add(new Tag("brigde", "yes"));
|
||||
tags.add(new Tag("oneway", "yes"));
|
||||
|
||||
RenderStyle[] ri = t.matchElement(GeometryType.LINE, tags, 16);
|
||||
|
||||
for (RenderStyle r : ri) {
|
||||
System.out.println("class: " + r.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
127
vtm-playground/src/org/oscim/test/TileRenderTest.java
Normal file
127
vtm-playground/src/org/oscim/test/TileRenderTest.java
Normal file
@ -0,0 +1,127 @@
|
||||
package org.oscim.test;
|
||||
|
||||
import org.oscim.core.MercatorProjection;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.layers.tile.MapTile.TileNode;
|
||||
import org.oscim.layers.tile.TileLoader;
|
||||
import org.oscim.layers.tile.TileManager;
|
||||
import org.oscim.layers.tile.TileSet;
|
||||
import org.oscim.layers.tile.VectorTileRenderer;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLoader;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.DebugTheme;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.bitmap.DefaultSources;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
|
||||
public class TileRenderTest extends GdxMap {
|
||||
|
||||
static boolean loadOneTile = true;
|
||||
static int tileX = 34365 >> 2;
|
||||
static int tileY = 21333 >> 2;
|
||||
static byte tileZ = 14;
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
final TileManager tileManager;
|
||||
|
||||
MapRenderer.setBackgroundColor(0xff888888);
|
||||
MapTile tile = new MapTile(null, tileX, tileY, tileZ);
|
||||
|
||||
double w = 1.0 / (1 << tile.zoomLevel);
|
||||
double minLon = MercatorProjection.toLongitude(tile.x);
|
||||
double maxLon = MercatorProjection.toLongitude(tile.x + w);
|
||||
double minLat = MercatorProjection.toLatitude(tile.y + w);
|
||||
double maxLat = MercatorProjection.toLatitude(tile.y);
|
||||
|
||||
mMap.setMapPosition(minLat + (maxLat - minLat) / 2, minLon
|
||||
+ (maxLon - minLon) / 2, 1 << tile.zoomLevel);
|
||||
|
||||
// mMap.setMapPosition(53.0521, 8.7951, 1 << 15);
|
||||
|
||||
if (loadOneTile) {
|
||||
|
||||
tile = new MapTile(new TileNode(), tileX, tileY, tileZ);
|
||||
// setup tile quad-tree, expected for locking
|
||||
// tile.node= new ;
|
||||
tile.node.parent = tile.node;
|
||||
tile.node.parent.parent = tile.node;
|
||||
|
||||
// setup TileSet contatining one tile
|
||||
final TileSet tiles = new TileSet();
|
||||
tiles.cnt = 1;
|
||||
tiles.tiles[0] = tile;
|
||||
tiles.lockTiles();
|
||||
|
||||
tileManager = new TileManager(mMap, 0, 32, 100) {
|
||||
@Override
|
||||
public boolean getActiveTiles(TileSet tileSet) {
|
||||
if (tileSet == null)
|
||||
tileSet = new TileSet(1);
|
||||
|
||||
tileSet.setTiles(tiles);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseTiles(TileSet tileSet) {
|
||||
tileSet.releaseTiles();
|
||||
}
|
||||
};
|
||||
} else {
|
||||
// create TileManager and calculate tiles for current position
|
||||
tileManager = new TileManager(mMap, 0, 32, 100);
|
||||
tileManager.init();
|
||||
tileManager.update(mMap.getMapPosition());
|
||||
}
|
||||
|
||||
final VectorTileLoader[] tileLoader = { null };
|
||||
|
||||
VectorTileLayer l = new VectorTileLayer(mMap, tileManager,
|
||||
new VectorTileRenderer(), 1) {
|
||||
|
||||
protected TileLoader createLoader() {
|
||||
tileLoader[0] = new VectorTileLoader(this) {
|
||||
|
||||
public boolean loadTile(MapTile tile) {
|
||||
mTile = tile;
|
||||
return super.loadTile(tile);
|
||||
}
|
||||
};
|
||||
return tileLoader[0];
|
||||
};
|
||||
};
|
||||
|
||||
TileSource tileSource = new OSciMap4TileSource();
|
||||
|
||||
l.setTileSource(tileSource);
|
||||
|
||||
//IRenderTheme theme = ThemeLoader.load(VtmThemes.TRONRENDER);
|
||||
//l.setRenderTheme(theme);
|
||||
l.setRenderTheme(new DebugTheme());
|
||||
|
||||
if (loadOneTile) {
|
||||
tileLoader[0].loadTile(tile);
|
||||
tileManager.jobCompleted(tile, true);
|
||||
} else {
|
||||
MapTile t;
|
||||
while ((t = tileManager.getTileJob()) != null) {
|
||||
tileLoader[0].loadTile(t);
|
||||
tileManager.jobCompleted(t, true);
|
||||
}
|
||||
}
|
||||
|
||||
mMap.setBackgroundMap(new BitmapTileLayer(mMap, new DefaultSources.StamenToner()));
|
||||
|
||||
mMap.layers().add(l);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new TileRenderTest(), null, 256);
|
||||
}
|
||||
}
|
48
vtm-playground/src/org/oscim/test/gdx/poi3d/Gdx3DTest.java
Normal file
48
vtm-playground/src/org/oscim/test/gdx/poi3d/Gdx3DTest.java
Normal file
@ -0,0 +1,48 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.tile.vector.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
|
||||
public class Gdx3DTest extends GdxMap {
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
MapRenderer.setBackgroundColor(0xff888888);
|
||||
|
||||
mMap.setMapPosition(53.1, 8.8, 1 << 15);
|
||||
|
||||
TileSource ts = new OSciMap4TileSource();
|
||||
// initDefaultLayers(ts, false, false, false);
|
||||
|
||||
VectorTileLayer mMapLayer = mMap.setBaseMap(ts);
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
// mMap.setTheme(VtmThemes.TRONRENDER);
|
||||
|
||||
mMap.layers().add(new BuildingLayer(mMap, mMapLayer));
|
||||
|
||||
// mMap.getLayers().add(new GenericLayer(mMap, new GridRenderer()));
|
||||
|
||||
// ts = new OSciMap4TileSource("http://opensciencemap.org/tiles/s3db");
|
||||
// VectorTileLayer tl = new VectorTileLayer(mMap, 16, 16, 20);
|
||||
// tl.setTileSource(ts);
|
||||
// tl.setRenderTheme(ThemeLoader.load(VtmThemes.DEFAULT));
|
||||
// mMap.getLayers().add(tl);
|
||||
// mMap.getLayers().add(new BuildingLayer(mMap, tl.getTileLayer()));
|
||||
|
||||
mMap.layers().add(new Poi3DLayer(mMap, mMapLayer));
|
||||
|
||||
mMap.layers().add(new LabelLayer(mMap, mMapLayer));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new Gdx3DTest(), null, 320);
|
||||
}
|
||||
}
|
237
vtm-playground/src/org/oscim/test/gdx/poi3d/GdxModelLayer.java
Normal file
237
vtm-playground/src/org/oscim/test/gdx/poi3d/GdxModelLayer.java
Normal file
@ -0,0 +1,237 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.event.Event;
|
||||
import org.oscim.layers.Layer;
|
||||
import org.oscim.map.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.model.Node;
|
||||
|
||||
public class GdxModelLayer extends Layer implements Map.UpdateListener {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(GdxModelLayer.class);
|
||||
|
||||
GdxRenderer3D g3d;
|
||||
|
||||
//VectorTileLayer mTileLayer;
|
||||
|
||||
public GdxModelLayer(Map map) {
|
||||
super(map);
|
||||
// tileLayer.addHook(new TileLoaderProcessHook() {
|
||||
//
|
||||
// @Override
|
||||
// public boolean process(MapTile tile, ElementLayers layers, MapElement element) {
|
||||
//
|
||||
// if (!element.tags.contains(TREE_TAG))
|
||||
// return false;
|
||||
//
|
||||
// Poi3DTileData td = get(tile);
|
||||
// PointF p = element.getPoint(0);
|
||||
// SymbolItem s = SymbolItem.pool.get();
|
||||
// s.x = p.x;
|
||||
// s.y = p.y;
|
||||
// td.symbols.push(s);
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
//mTileLayer = tileLayer;
|
||||
|
||||
mRenderer = g3d = new GdxRenderer3D(mMap);
|
||||
|
||||
// Material mat = new
|
||||
// Material(ColorAttribute.createDiffuse(Color.BLUE));
|
||||
// ModelBuilder modelBuilder = new ModelBuilder();
|
||||
// long attributes = Usage.Position | Usage.Normal |
|
||||
// Usage.TextureCoordinates;
|
||||
|
||||
// mModel = modelBuilder.createSphere(10f, 10f, 10f, 12, 12,
|
||||
// mat, attributes);
|
||||
|
||||
assets = new AssetManager();
|
||||
assets.load("data/g3d/test.g3db", Model.class);
|
||||
loading = true;
|
||||
}
|
||||
|
||||
// TileSet mTileSet = new TileSet();
|
||||
// TileSet mPrevTiles = new TileSet();
|
||||
//
|
||||
// LinkedHashMap<Tile, Array<SharedModel>> mTileMap =
|
||||
// new LinkedHashMap<Tile, Array<SharedModel>>();
|
||||
|
||||
boolean loading;
|
||||
Model mModel;
|
||||
AssetManager assets;
|
||||
|
||||
private void doneLoading() {
|
||||
Model model = assets.get("data/g3d/test.g3db", Model.class);
|
||||
for (int i = 0; i < model.nodes.size; i++) {
|
||||
Node node = model.nodes.get(i);
|
||||
log.debug("loader node " + node.id);
|
||||
|
||||
if (node.id.equals("test_root")) {
|
||||
node = node.getChild("Building", false, false);
|
||||
log.debug("loader node " + node.id);
|
||||
|
||||
node.rotation.setFromAxis(1, 0, 0, 90);
|
||||
mModel = model;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
loading = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapEvent(Event ev, MapPosition pos) {
|
||||
|
||||
// if (ev == Map.CLEAR_EVENT) {
|
||||
// mTileSet = new TileSet();
|
||||
// mPrevTiles = new TileSet();
|
||||
// mTileMap = new LinkedHashMap<Tile, Array<SharedModel>>();
|
||||
// synchronized (g3d) {
|
||||
// g3d.instances.clear();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
if (loading && assets.update()) {
|
||||
doneLoading();
|
||||
// Renderable renderable = new Renderable();
|
||||
// new SharedModel(mModel).getRenderable(renderable);
|
||||
// Shader shader = new DefaultShader(renderable, true, false,
|
||||
// false, false, 1, 0, 0, 0);
|
||||
|
||||
g3d.instances.add(new SharedModel(mModel));
|
||||
|
||||
}
|
||||
if (loading)
|
||||
return;
|
||||
|
||||
int x = 17185 << 1;
|
||||
int y = 10662 << 1;
|
||||
int z = 16;
|
||||
double scale = 1 / (1 << z);
|
||||
|
||||
g3d.cam.setMapPosition(x * scale - pos.x, y * scale - pos.y, scale / pos.scale);
|
||||
|
||||
//
|
||||
// // log.debug("update");
|
||||
//
|
||||
// mTileLayer.tileRenderer().getVisibleTiles(mTileSet);
|
||||
//
|
||||
// if (mTileSet.cnt == 0) {
|
||||
// mTileSet.releaseTiles();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// boolean changed = false;
|
||||
//
|
||||
// Array<SharedModel> added = new Array<SharedModel>();
|
||||
// Array<SharedModel> removed = new Array<SharedModel>();
|
||||
|
||||
// for (int i = 0; i < mTileSet.cnt; i++) {
|
||||
// MapTile t = mTileSet.tiles[i];
|
||||
// if (mPrevTiles.contains(t))
|
||||
// continue;
|
||||
//
|
||||
// Array<SharedModel> instances = new Array<SharedModel>();
|
||||
//
|
||||
// Poi3DTileData ld = (Poi3DTileData) t.getData(POI_DATA);
|
||||
// if (ld == null)
|
||||
// continue;
|
||||
//
|
||||
// for (SymbolItem it : ld.symbols) {
|
||||
//
|
||||
// SharedModel inst = new SharedModel(mModel);
|
||||
// inst.userData = it;
|
||||
// // float r = 0.5f + 0.5f * (float) Math.random();
|
||||
// // float g = 0.5f + 0.5f * (float) Math.random();
|
||||
// // float b = 0.5f + 0.5f * (float) Math.random();
|
||||
//
|
||||
// // inst.transform.setTranslation(new Vector3(it.x, it.y,
|
||||
// // 10));
|
||||
// // inst.materials.get(0).set(ColorAttribute.createDiffuse(r,
|
||||
// // g, b, 0.8f));
|
||||
// instances.add(inst);
|
||||
// added.add(inst);
|
||||
// }
|
||||
//
|
||||
// if (instances.size == 0)
|
||||
// continue;
|
||||
//
|
||||
// log.debug("add " + t + " " + instances.size);
|
||||
//
|
||||
// changed = true;
|
||||
//
|
||||
// mTileMap.put(t, instances);
|
||||
// }
|
||||
//
|
||||
// for (int i = 0; i < mPrevTiles.cnt; i++) {
|
||||
// MapTile t = mPrevTiles.tiles[i];
|
||||
// if (mTileSet.contains(t))
|
||||
// continue;
|
||||
//
|
||||
// Array<SharedModel> instances = mTileMap.get(t);
|
||||
// if (instances == null)
|
||||
// continue;
|
||||
//
|
||||
// changed = true;
|
||||
//
|
||||
// removed.addAll(instances);
|
||||
// mTileMap.remove(t);
|
||||
// log.debug("remove " + t);
|
||||
// }
|
||||
//
|
||||
// mPrevTiles.releaseTiles();
|
||||
//
|
||||
// int zoom = mTileSet.tiles[0].zoomLevel;
|
||||
//
|
||||
// TileSet tmp = mPrevTiles;
|
||||
// mPrevTiles = mTileSet;
|
||||
// mTileSet = tmp;
|
||||
//
|
||||
// if (!changed)
|
||||
// return;
|
||||
//
|
||||
// // scale aka tree height
|
||||
// float scale = (float) (1f / (1 << (17 - zoom))) * 8;
|
||||
//
|
||||
// double tileX = (pos.x * (Tile.SIZE << zoom));
|
||||
// double tileY = (pos.y * (Tile.SIZE << zoom));
|
||||
//
|
||||
// synchronized (g3d) {
|
||||
//
|
||||
// for (Entry<Tile, Array<SharedModel>> e : mTileMap.entrySet()) {
|
||||
// Tile t = e.getKey();
|
||||
//
|
||||
// float dx = (float) (t.tileX * Tile.SIZE - tileX);
|
||||
// float dy = (float) (t.tileY * Tile.SIZE - tileY);
|
||||
//
|
||||
// for (SharedModel inst : e.getValue()) {
|
||||
// SymbolItem it = (SymbolItem) inst.userData;
|
||||
//
|
||||
// // variable height
|
||||
// float s = scale + (it.x * it.y) % 3;
|
||||
// float r = (it.x * it.y) % 360;
|
||||
//
|
||||
// inst.transform.idt();
|
||||
// inst.transform.scale(s, s, s);
|
||||
// inst.transform.translate((dx + it.x) / s, (dy + it.y) / s, 0);
|
||||
// inst.transform.rotate(0, 0, 1, r);
|
||||
//
|
||||
// // inst.transform.setToTranslationAndScaling((dx +
|
||||
// // it.x), (dy + it.y),
|
||||
// // 0, s, s, s);
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.map.Viewport;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.LayerRenderer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.graphics.g3d.Environment;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.Renderable;
|
||||
import com.badlogic.gdx.graphics.g3d.Shader;
|
||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class GdxModelRenderer extends LayerRenderer {
|
||||
static final Logger log = LoggerFactory.getLogger(GdxModelRenderer.class);
|
||||
|
||||
ModelBatch modelBatch;
|
||||
public MapCamera cam;
|
||||
Map mMap;
|
||||
|
||||
boolean loading;
|
||||
|
||||
public Environment lights;
|
||||
|
||||
public Array<SharedModel> instances = new Array<SharedModel>();
|
||||
|
||||
public Shader shader;
|
||||
public RenderContext renderContext;
|
||||
public Model model;
|
||||
private ModelBatch mBatch = new ModelBatch();
|
||||
|
||||
public GdxModelRenderer(Map map) {
|
||||
mMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setup() {
|
||||
|
||||
modelBatch = new ModelBatch(new DefaultShaderProvider());
|
||||
|
||||
lights = new Environment();
|
||||
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1.f));
|
||||
lights.add(new DirectionalLight().set(0.3f, 0.3f, 0.3f, 0, 1, -0.2f));
|
||||
|
||||
cam = new MapCamera(mMap);
|
||||
|
||||
renderContext =
|
||||
new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
|
||||
|
||||
// shader = new DefaultShader(renderable.material,
|
||||
// renderable.mesh.getVertexAttributes(), true, false, 1, 0, 0, 0);
|
||||
// shader.init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void update(GLViewport v) {
|
||||
// if (loading && assets.update())
|
||||
// doneLoading();
|
||||
|
||||
if (!isReady()) {
|
||||
cam.setPosition(v.pos);
|
||||
setReady(true);
|
||||
}
|
||||
|
||||
// if (changed) {
|
||||
// cam.update(position, matrices);
|
||||
// }
|
||||
}
|
||||
|
||||
Vector3 tempVector = new Vector3();
|
||||
float[] mBox = new float[8];
|
||||
|
||||
Renderable r = new Renderable();
|
||||
|
||||
@Override
|
||||
protected void render(GLViewport v) {
|
||||
if (instances.size == 0)
|
||||
return;
|
||||
|
||||
// GLUtils.checkGlError(">" + TAG);
|
||||
|
||||
GL.glDepthMask(true);
|
||||
|
||||
if (v.pos.zoomLevel < 16)
|
||||
GL.glClear(GL20.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
// set state that is expected after modelBatch.end();
|
||||
// modelBatch keeps track of its own state
|
||||
GLState.enableVertexArrays(-1, -1);
|
||||
GLState.bindTex2D(-1);
|
||||
GLState.useProgram(-1);
|
||||
GLState.test(false, false);
|
||||
GLState.blend(false);
|
||||
|
||||
cam.update(v);
|
||||
|
||||
Viewport p = mMap.viewport();
|
||||
p.getMapExtents(mBox, 10);
|
||||
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
|
||||
|
||||
float dx = (float) (cam.mMapPosition.x - v.pos.x)
|
||||
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
|
||||
float dy = (float) (cam.mMapPosition.y - v.pos.y)
|
||||
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
|
||||
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
mBox[i] *= scale;
|
||||
mBox[i] -= dx;
|
||||
mBox[i + 1] *= scale;
|
||||
mBox[i + 1] -= dy;
|
||||
}
|
||||
|
||||
//int w = mMap.getWidth() / 2;
|
||||
//int h = mMap.getHeight() / 2;
|
||||
//float sqRadius = (w * w + h * h) / scale;
|
||||
|
||||
synchronized (this) {
|
||||
if (instances.size == 0)
|
||||
return;
|
||||
|
||||
//renderContext.begin();
|
||||
|
||||
// if (shader == null) {
|
||||
// r = instances.get(0).getRenderable(r);
|
||||
// DefaultShader.Config c = new DefaultShader.Config();
|
||||
// c.numBones = 0;
|
||||
// c.numDirectionalLights = 1;
|
||||
// r.environment = lights;
|
||||
//
|
||||
// shader = new DefaultShader(r, c);
|
||||
// shader.init();
|
||||
// }
|
||||
mBatch.begin(cam);
|
||||
//shader.begin(cam, renderContext);
|
||||
|
||||
for (SharedModel instance : instances) {
|
||||
instance.transform.getTranslation(tempVector);
|
||||
//instance.getRenderables(renderables, pool);
|
||||
// if (tempVector.x * tempVector.x + tempVector.y * tempVector.y > sqRadius)
|
||||
// continue;
|
||||
// tempVector.scl(0.8f, 0.8f, 1);
|
||||
// if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
|
||||
// continue;
|
||||
|
||||
mBatch.render(instance);
|
||||
|
||||
//shader.render(r);
|
||||
}
|
||||
mBatch.end();
|
||||
|
||||
//shader.end();
|
||||
//renderContext.end();
|
||||
}
|
||||
|
||||
GL.glDepthMask(false);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void dispose () {
|
||||
// modelBatch.dispose();
|
||||
// assets.dispose();
|
||||
// assets = null;
|
||||
// axesModel.dispose();
|
||||
// axesModel = null;
|
||||
// }
|
||||
}
|
198
vtm-playground/src/org/oscim/test/gdx/poi3d/GdxRenderer3D.java
Normal file
198
vtm-playground/src/org/oscim/test/gdx/poi3d/GdxRenderer3D.java
Normal file
@ -0,0 +1,198 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.map.Viewport;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.LayerRenderer;
|
||||
import org.oscim.utils.geom.GeometryUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.graphics.g3d.Environment;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.Renderable;
|
||||
import com.badlogic.gdx.graphics.g3d.Shader;
|
||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
|
||||
import com.badlogic.gdx.graphics.g3d.shaders.DefaultShader;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class GdxRenderer3D extends LayerRenderer {
|
||||
static final Logger log = LoggerFactory.getLogger(GdxRenderer3D.class);
|
||||
|
||||
ModelBatch modelBatch;
|
||||
public MapCamera cam;
|
||||
Map mMap;
|
||||
|
||||
boolean loading;
|
||||
|
||||
public Environment lights;
|
||||
|
||||
public Array<SharedModel> instances = new Array<SharedModel>();
|
||||
|
||||
public Shader shader;
|
||||
public RenderContext renderContext;
|
||||
public Model model;
|
||||
|
||||
public GdxRenderer3D(Map map) {
|
||||
mMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setup() {
|
||||
|
||||
modelBatch = new ModelBatch(new DefaultShaderProvider());
|
||||
|
||||
lights = new Environment();
|
||||
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 1.0f, 1.0f, 1.f));
|
||||
lights.add(new DirectionalLight().set(0.3f, 0.3f, 0.3f, 0, 1, -0.2f));
|
||||
|
||||
cam = new MapCamera(mMap);
|
||||
|
||||
renderContext =
|
||||
new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED, 1));
|
||||
|
||||
// shader = new DefaultShader(renderable.material,
|
||||
// renderable.mesh.getVertexAttributes(), true, false, 1, 0, 0, 0);
|
||||
// shader.init();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void update(GLViewport v) {
|
||||
// if (loading && assets.update())
|
||||
// doneLoading();
|
||||
|
||||
if (!isReady()) {
|
||||
cam.setPosition(v.pos);
|
||||
setReady(true);
|
||||
}
|
||||
|
||||
// if (changed) {
|
||||
// cam.update(position, matrices);
|
||||
// }
|
||||
}
|
||||
|
||||
Vector3 tempVector = new Vector3();
|
||||
float[] mBox = new float[8];
|
||||
|
||||
Renderable r = new Renderable();
|
||||
|
||||
@Override
|
||||
protected void render(GLViewport v) {
|
||||
if (instances.size == 0)
|
||||
return;
|
||||
|
||||
// GLUtils.checkGlError(">" + TAG);
|
||||
|
||||
GL.glDepthMask(true);
|
||||
|
||||
// if (position.zoomLevel < 17)
|
||||
// GL.glClear(GL20.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
// set state that is expected after modelBatch.end();
|
||||
// modelBatch keeps track of its own state
|
||||
GLState.enableVertexArrays(-1, -1);
|
||||
GLState.bindTex2D(-1);
|
||||
GLState.useProgram(-1);
|
||||
GLState.test(false, false);
|
||||
GLState.blend(false);
|
||||
|
||||
cam.update(v);
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
int cnt = 0;
|
||||
int rnd = 0;
|
||||
|
||||
Viewport p = mMap.viewport();
|
||||
p.getMapExtents(mBox, 10);
|
||||
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
|
||||
|
||||
float dx = (float) (cam.mMapPosition.x - v.pos.x)
|
||||
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
|
||||
float dy = (float) (cam.mMapPosition.y - v.pos.y)
|
||||
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
|
||||
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
mBox[i] *= scale;
|
||||
mBox[i] -= dx;
|
||||
mBox[i + 1] *= scale;
|
||||
mBox[i + 1] -= dy;
|
||||
}
|
||||
|
||||
int w = mMap.getWidth() / 2;
|
||||
int h = mMap.getHeight() / 2;
|
||||
|
||||
float sqRadius = (w * w + h * h) / scale;
|
||||
|
||||
synchronized (this) {
|
||||
if (instances.size == 0)
|
||||
return;
|
||||
|
||||
cnt = instances.size;
|
||||
|
||||
renderContext.begin();
|
||||
|
||||
if (shader == null) {
|
||||
r = instances.get(0).getRenderable(r);
|
||||
DefaultShader.Config c = new DefaultShader.Config();
|
||||
c.numBones = 0;
|
||||
c.numDirectionalLights = 1;
|
||||
r.environment = lights;
|
||||
// shader = new DefaultShader(r, true, false, false, false, 1,
|
||||
// 0, 0, 0);
|
||||
shader = new DefaultShader(r, c);
|
||||
shader.init();
|
||||
}
|
||||
|
||||
shader.begin(cam, renderContext);
|
||||
|
||||
for (SharedModel instance : instances) {
|
||||
instance.transform.getTranslation(tempVector);
|
||||
|
||||
if (tempVector.x * tempVector.x + tempVector.y * tempVector.y > sqRadius)
|
||||
continue;
|
||||
|
||||
tempVector.scl(0.8f, 0.8f, 1);
|
||||
|
||||
if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
|
||||
continue;
|
||||
|
||||
instance.getRenderable(r);
|
||||
// r.lights = lights;
|
||||
// r.environment = lights;
|
||||
shader.render(r);
|
||||
|
||||
rnd++;
|
||||
}
|
||||
|
||||
shader.end();
|
||||
renderContext.end();
|
||||
}
|
||||
log.debug(">>> " + (System.currentTimeMillis() - time) + " " + cnt + "/" + rnd);
|
||||
|
||||
GL.glDepthMask(false);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void dispose () {
|
||||
// modelBatch.dispose();
|
||||
// assets.dispose();
|
||||
// assets = null;
|
||||
// axesModel.dispose();
|
||||
// axesModel = null;
|
||||
// }
|
||||
}
|
164
vtm-playground/src/org/oscim/test/gdx/poi3d/GdxRenderer3D2.java
Normal file
164
vtm-playground/src/org/oscim/test/gdx/poi3d/GdxRenderer3D2.java
Normal file
@ -0,0 +1,164 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.map.Viewport;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.LayerRenderer;
|
||||
import org.oscim.utils.geom.GeometryUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.graphics.g3d.Environment;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
|
||||
import com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class GdxRenderer3D2 extends LayerRenderer {
|
||||
static final Logger log = LoggerFactory.getLogger(GdxRenderer3D2.class);
|
||||
|
||||
ModelBatch modelBatch;
|
||||
public MapCamera cam;
|
||||
Map mMap;
|
||||
|
||||
boolean loading;
|
||||
|
||||
public Environment lights;
|
||||
|
||||
public Array<SharedModel> instances = new Array<SharedModel>();
|
||||
|
||||
public GdxRenderer3D2(Map map) {
|
||||
mMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setup() {
|
||||
|
||||
// if (assets == null)
|
||||
// assets = new AssetManager();
|
||||
|
||||
// assets.load("data/g3d/invaders.g3dj", Model.class);
|
||||
// loading = true;
|
||||
|
||||
modelBatch = new ModelBatch(new DefaultShaderProvider());
|
||||
|
||||
lights = new Environment();
|
||||
// lights.ambientLight.set(1.0f, 1.0f, 1.0f, 1f);
|
||||
// lights.ambientLight.set(215 / 255f,
|
||||
// 240 / 255f,
|
||||
// 51 / 255f, 1f);
|
||||
|
||||
lights.add(new DirectionalLight().set(0.9f, 0.9f, 0.9f, 0, 1, -0.2f));
|
||||
|
||||
cam = new MapCamera(mMap);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void update(GLViewport v) {
|
||||
// if (loading && assets.update())
|
||||
// doneLoading();
|
||||
|
||||
if (!isReady()) {
|
||||
cam.setPosition(v.pos);
|
||||
setReady(true);
|
||||
}
|
||||
|
||||
// if (changed) {
|
||||
// cam.update(position, matrices);
|
||||
// }
|
||||
}
|
||||
|
||||
Vector3 tempVector = new Vector3();
|
||||
float[] mBox = new float[8];
|
||||
|
||||
@Override
|
||||
protected void render(GLViewport v) {
|
||||
if (instances.size == 0)
|
||||
return;
|
||||
|
||||
// GLUtils.checkGlError(">" + TAG);
|
||||
|
||||
GL.glDepthMask(true);
|
||||
|
||||
if (v.pos.zoomLevel < 17)
|
||||
GL.glClear(GL20.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
|
||||
// set state that is expected after modelBatch.end();
|
||||
// modelBatch keeps track of its own state
|
||||
GLState.enableVertexArrays(-1, -1);
|
||||
GLState.bindTex2D(-1);
|
||||
GLState.useProgram(-1);
|
||||
GLState.test(false, false);
|
||||
GLState.blend(false);
|
||||
|
||||
// GL.glCullFace(GL20.GL_BACK);
|
||||
// GL.glFrontFace(GL20.GL_CW);
|
||||
|
||||
cam.update(v);
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
int cnt = 0;
|
||||
int rnd = 0;
|
||||
|
||||
Viewport p = mMap.viewport();
|
||||
p.getMapExtents(mBox, 10);
|
||||
float scale = (float) (cam.mMapPosition.scale / v.pos.scale);
|
||||
|
||||
float dx =
|
||||
(float) (cam.mMapPosition.x - v.pos.x)
|
||||
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
|
||||
float dy =
|
||||
(float) (cam.mMapPosition.y - v.pos.y)
|
||||
* (Tile.SIZE << cam.mMapPosition.zoomLevel);
|
||||
|
||||
for (int i = 0; i < 8; i += 2) {
|
||||
mBox[i] *= scale;
|
||||
mBox[i] -= dx;
|
||||
mBox[i + 1] *= scale;
|
||||
mBox[i + 1] -= dy;
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
modelBatch.begin(cam);
|
||||
cnt = instances.size;
|
||||
|
||||
for (SharedModel instance : instances) {
|
||||
instance.transform.getTranslation(tempVector);
|
||||
tempVector.scl(0.9f, 0.9f, 1);
|
||||
if (!GeometryUtils.pointInPoly(tempVector.x, tempVector.y, mBox, 8, 0))
|
||||
continue;
|
||||
|
||||
modelBatch.render(instance);
|
||||
rnd++;
|
||||
}
|
||||
modelBatch.end();
|
||||
}
|
||||
log.debug(">>> " + (System.currentTimeMillis() - time) + " " + cnt + "/" + rnd);
|
||||
|
||||
// GLUtils.checkGlError("<" + TAG);
|
||||
|
||||
GL.glDepthMask(false);
|
||||
GL.glBindBuffer(GL20.GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
// GLState.bindTex2D(-1);
|
||||
// GLState.useProgram(-1);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void dispose () {
|
||||
// modelBatch.dispose();
|
||||
// assets.dispose();
|
||||
// assets = null;
|
||||
// axesModel.dispose();
|
||||
// axesModel = null;
|
||||
// }
|
||||
}
|
70
vtm-playground/src/org/oscim/test/gdx/poi3d/MapCamera.java
Normal file
70
vtm-playground/src/org/oscim/test/gdx/poi3d/MapCamera.java
Normal file
@ -0,0 +1,70 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
import com.badlogic.gdx.math.Matrix4;
|
||||
|
||||
public class MapCamera extends Camera {
|
||||
|
||||
private final Map mMap;
|
||||
|
||||
public MapCamera(Map map) {
|
||||
mMap = map;
|
||||
|
||||
this.near = 1;
|
||||
this.far = 8;
|
||||
}
|
||||
|
||||
MapPosition mMapPosition = new MapPosition();
|
||||
|
||||
public void setPosition(MapPosition pos) {
|
||||
mMapPosition.copy(pos);
|
||||
|
||||
this.viewportWidth = mMap.getWidth();
|
||||
this.viewportHeight = mMap.getHeight();
|
||||
}
|
||||
|
||||
public void setMapPosition(double x, double y, double scale) {
|
||||
mMapPosition.setScale(scale);
|
||||
mMapPosition.x = x;
|
||||
mMapPosition.y = y;
|
||||
}
|
||||
|
||||
public void update(GLViewport v) {
|
||||
double scale = (v.pos.scale * Tile.SIZE);
|
||||
|
||||
float x = (float) ((mMapPosition.x - v.pos.x) * scale);
|
||||
float y = (float) ((mMapPosition.y - v.pos.y) * scale);
|
||||
float z = (float) (v.pos.scale / mMapPosition.scale);
|
||||
|
||||
v.proj.get(projection.getValues());
|
||||
v.mvp.setTransScale(x, y, z);
|
||||
v.mvp.setValue(10, z);
|
||||
v.mvp.multiplyLhs(v.view);
|
||||
v.mvp.get(view.getValues());
|
||||
|
||||
combined.set(projection);
|
||||
|
||||
Matrix4.mul(combined.val, view.val);
|
||||
|
||||
//if (updateFrustum) {
|
||||
invProjectionView.set(combined);
|
||||
Matrix4.inv(invProjectionView.val);
|
||||
frustum.update(invProjectionView);
|
||||
//}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(boolean updateFrustum) {
|
||||
|
||||
}
|
||||
|
||||
}
|
258
vtm-playground/src/org/oscim/test/gdx/poi3d/Poi3DLayer.java
Normal file
258
vtm-playground/src/org/oscim/test/gdx/poi3d/Poi3DLayer.java
Normal file
@ -0,0 +1,258 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.core.PointF;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.event.Event;
|
||||
import org.oscim.layers.Layer;
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
import org.oscim.layers.tile.MapTile.TileData;
|
||||
import org.oscim.layers.tile.TileSet;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer.TileLoaderProcessHook;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.elements.ElementLayers;
|
||||
import org.oscim.renderer.elements.SymbolItem;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.model.Node;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class Poi3DLayer extends Layer implements Map.UpdateListener {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(Poi3DLayer.class);
|
||||
|
||||
static class Poi3DTileData extends TileData {
|
||||
public final List<SymbolItem> symbols = new List<SymbolItem>();
|
||||
|
||||
@Override
|
||||
protected void dispose() {
|
||||
SymbolItem.pool.releaseAll(symbols.clear());
|
||||
}
|
||||
}
|
||||
|
||||
final static String POI_DATA = Poi3DLayer.class.getSimpleName();
|
||||
final static Tag TREE_TAG = new Tag("natural", "tree");
|
||||
|
||||
private Poi3DTileData get(MapTile tile) {
|
||||
Poi3DTileData ld = (Poi3DTileData) tile.getData(POI_DATA);
|
||||
if (ld == null) {
|
||||
ld = new Poi3DTileData();
|
||||
tile.addData(POI_DATA, ld);
|
||||
}
|
||||
return ld;
|
||||
}
|
||||
|
||||
GdxRenderer3D g3d;
|
||||
VectorTileLayer mTileLayer;
|
||||
|
||||
public Poi3DLayer(Map map, VectorTileLayer tileLayer) {
|
||||
super(map);
|
||||
tileLayer.addHook(new TileLoaderProcessHook() {
|
||||
|
||||
@Override
|
||||
public boolean process(MapTile tile, ElementLayers layers, MapElement element) {
|
||||
|
||||
if (!element.tags.contains(TREE_TAG))
|
||||
return false;
|
||||
|
||||
Poi3DTileData td = get(tile);
|
||||
PointF p = element.getPoint(0);
|
||||
SymbolItem s = SymbolItem.pool.get();
|
||||
s.x = p.x;
|
||||
s.y = p.y;
|
||||
td.symbols.push(s);
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
mTileLayer = tileLayer;
|
||||
|
||||
mRenderer = g3d = new GdxRenderer3D(mMap);
|
||||
|
||||
// Material mat = new
|
||||
// Material(ColorAttribute.createDiffuse(Color.BLUE));
|
||||
// ModelBuilder modelBuilder = new ModelBuilder();
|
||||
// long attributes = Usage.Position | Usage.Normal |
|
||||
// Usage.TextureCoordinates;
|
||||
|
||||
// mModel = modelBuilder.createSphere(10f, 10f, 10f, 12, 12,
|
||||
// mat, attributes);
|
||||
|
||||
assets = new AssetManager();
|
||||
assets.load("data/g3d/treeA.g3dj", Model.class);
|
||||
loading = true;
|
||||
}
|
||||
|
||||
TileSet mTileSet = new TileSet();
|
||||
TileSet mPrevTiles = new TileSet();
|
||||
|
||||
LinkedHashMap<Tile, Array<SharedModel>> mTileMap =
|
||||
new LinkedHashMap<Tile, Array<SharedModel>>();
|
||||
|
||||
boolean loading;
|
||||
Model mModel;
|
||||
AssetManager assets;
|
||||
|
||||
private void doneLoading() {
|
||||
Model model = assets.get("data/g3d/treeA.g3dj", Model.class);
|
||||
for (int i = 0; i < model.nodes.size; i++) {
|
||||
Node node = model.nodes.get(i);
|
||||
|
||||
if (node.id.equals("treeA_root")) {
|
||||
node.rotation.setFromAxis(1, 0, 0, 90);
|
||||
mModel = model;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
loading = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapEvent(Event ev, MapPosition pos) {
|
||||
|
||||
if (ev == Map.CLEAR_EVENT) {
|
||||
mTileSet = new TileSet();
|
||||
mPrevTiles = new TileSet();
|
||||
mTileMap = new LinkedHashMap<Tile, Array<SharedModel>>();
|
||||
synchronized (g3d) {
|
||||
g3d.instances.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (loading && assets.update()) {
|
||||
doneLoading();
|
||||
// Renderable renderable = new Renderable();
|
||||
// new SharedModel(mModel).getRenderable(renderable);
|
||||
// Shader shader = new DefaultShader(renderable, true, false,
|
||||
// false, false, 1, 0, 0, 0);
|
||||
}
|
||||
if (loading)
|
||||
return;
|
||||
|
||||
// log.debug("update");
|
||||
|
||||
mTileLayer.tileRenderer().getVisibleTiles(mTileSet);
|
||||
|
||||
if (mTileSet.cnt == 0) {
|
||||
mTileSet.releaseTiles();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
Array<SharedModel> added = new Array<SharedModel>();
|
||||
Array<SharedModel> removed = new Array<SharedModel>();
|
||||
|
||||
for (int i = 0; i < mTileSet.cnt; i++) {
|
||||
MapTile t = mTileSet.tiles[i];
|
||||
if (mPrevTiles.contains(t))
|
||||
continue;
|
||||
|
||||
Array<SharedModel> instances = new Array<SharedModel>();
|
||||
|
||||
Poi3DTileData ld = (Poi3DTileData) t.getData(POI_DATA);
|
||||
if (ld == null)
|
||||
continue;
|
||||
|
||||
for (SymbolItem it : ld.symbols) {
|
||||
|
||||
SharedModel inst = new SharedModel(mModel);
|
||||
inst.userData = it;
|
||||
// float r = 0.5f + 0.5f * (float) Math.random();
|
||||
// float g = 0.5f + 0.5f * (float) Math.random();
|
||||
// float b = 0.5f + 0.5f * (float) Math.random();
|
||||
|
||||
// inst.transform.setTranslation(new Vector3(it.x, it.y,
|
||||
// 10));
|
||||
// inst.materials.get(0).set(ColorAttribute.createDiffuse(r,
|
||||
// g, b, 0.8f));
|
||||
instances.add(inst);
|
||||
added.add(inst);
|
||||
}
|
||||
|
||||
if (instances.size == 0)
|
||||
continue;
|
||||
|
||||
log.debug("add " + t + " " + instances.size);
|
||||
|
||||
changed = true;
|
||||
|
||||
mTileMap.put(t, instances);
|
||||
}
|
||||
|
||||
for (int i = 0; i < mPrevTiles.cnt; i++) {
|
||||
MapTile t = mPrevTiles.tiles[i];
|
||||
if (mTileSet.contains(t))
|
||||
continue;
|
||||
|
||||
Array<SharedModel> instances = mTileMap.get(t);
|
||||
if (instances == null)
|
||||
continue;
|
||||
|
||||
changed = true;
|
||||
|
||||
removed.addAll(instances);
|
||||
mTileMap.remove(t);
|
||||
log.debug("remove " + t);
|
||||
}
|
||||
|
||||
mPrevTiles.releaseTiles();
|
||||
|
||||
int zoom = mTileSet.tiles[0].zoomLevel;
|
||||
|
||||
TileSet tmp = mPrevTiles;
|
||||
mPrevTiles = mTileSet;
|
||||
mTileSet = tmp;
|
||||
|
||||
if (!changed)
|
||||
return;
|
||||
|
||||
// scale aka tree height
|
||||
float scale = (float) (1f / (1 << (17 - zoom))) * 8;
|
||||
|
||||
double tileX = (pos.x * (Tile.SIZE << zoom));
|
||||
double tileY = (pos.y * (Tile.SIZE << zoom));
|
||||
|
||||
synchronized (g3d) {
|
||||
|
||||
for (Entry<Tile, Array<SharedModel>> e : mTileMap.entrySet()) {
|
||||
Tile t = e.getKey();
|
||||
|
||||
float dx = (float) (t.tileX * Tile.SIZE - tileX);
|
||||
float dy = (float) (t.tileY * Tile.SIZE - tileY);
|
||||
|
||||
for (SharedModel inst : e.getValue()) {
|
||||
SymbolItem it = (SymbolItem) inst.userData;
|
||||
|
||||
// variable height
|
||||
float s = scale + (it.x * it.y) % 3;
|
||||
float r = (it.x * it.y) % 360;
|
||||
|
||||
inst.transform.idt();
|
||||
inst.transform.scale(s, s, s);
|
||||
inst.transform.translate((dx + it.x) / s, (dy + it.y) / s, 0);
|
||||
inst.transform.rotate(0, 0, 1, r);
|
||||
|
||||
// inst.transform.setToTranslationAndScaling((dx +
|
||||
// it.x), (dy + it.y),
|
||||
// 0, s, s, s);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
g3d.instances.removeAll(removed, true);
|
||||
g3d.instances.addAll(added);
|
||||
g3d.cam.setMapPosition(pos.x, pos.y, 1 << zoom);
|
||||
}
|
||||
}
|
||||
}
|
461
vtm-playground/src/org/oscim/test/gdx/poi3d/SharedModel.java
Normal file
461
vtm-playground/src/org/oscim/test/gdx/poi3d/SharedModel.java
Normal file
@ -0,0 +1,461 @@
|
||||
package org.oscim.test.gdx.poi3d;
|
||||
|
||||
import com.badlogic.gdx.graphics.g3d.Material;
|
||||
import com.badlogic.gdx.graphics.g3d.Model;
|
||||
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||
import com.badlogic.gdx.graphics.g3d.Renderable;
|
||||
import com.badlogic.gdx.graphics.g3d.RenderableProvider;
|
||||
import com.badlogic.gdx.graphics.g3d.model.Animation;
|
||||
import com.badlogic.gdx.graphics.g3d.model.MeshPart;
|
||||
import com.badlogic.gdx.graphics.g3d.model.Node;
|
||||
import com.badlogic.gdx.graphics.g3d.model.NodeAnimation;
|
||||
import com.badlogic.gdx.graphics.g3d.model.NodeKeyframe;
|
||||
import com.badlogic.gdx.graphics.g3d.model.NodePart;
|
||||
import com.badlogic.gdx.math.Matrix4;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.math.collision.BoundingBox;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ArrayMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.Pool;
|
||||
|
||||
/** An instance of a {@link Model}, allows to specify global transform and modify the materials, as it
|
||||
* has a copy of the model's materials. Multiple instances can be created from the same Model,
|
||||
* all sharing the meshes and textures of the Model. The Model owns the meshes and textures, to
|
||||
* dispose of these, the Model has to be disposed. Therefor, the Model must outlive all its ModelInstances</p>
|
||||
*
|
||||
* The ModelInstance creates a full copy of all materials, nodes and animations.
|
||||
* @author badlogic, xoppa */
|
||||
public class SharedModel implements RenderableProvider {
|
||||
/** the materials of the model, used by nodes that have a graphical representation FIXME not sure if superfluous, allows modification of materials without having to traverse the nodes **/
|
||||
public final Array<Material> materials = new Array<Material>();
|
||||
/** root nodes of the model **/
|
||||
public final Array<Node> nodes = new Array<Node>();
|
||||
/** animations of the model, modifying node transformations **/
|
||||
public final Array<Animation> animations = new Array<Animation>();
|
||||
/** the {@link Model} this instances derives from **/
|
||||
public final Model model;
|
||||
/** the world transform **/
|
||||
public Matrix4 transform;
|
||||
/** user definable value, which is passed to the shader. */
|
||||
public Object userData;
|
||||
|
||||
/** Constructs a new ModelInstance with all nodes and materials of the given model.
|
||||
* @param model The {@link Model} to create an instance of. */
|
||||
public SharedModel(final Model model) {
|
||||
this(model, (String[])null);
|
||||
}
|
||||
|
||||
/** @param model The source {@link Model}
|
||||
* @param nodeId The ID of the root {@link Node} of the {@link Model} for the instance to contain
|
||||
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
|
||||
public SharedModel(final Model model, final String nodeId, boolean mergeTransform) {
|
||||
this(model, null, nodeId, false, false, mergeTransform);
|
||||
}
|
||||
|
||||
/** @param model The source {@link Model}
|
||||
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
|
||||
* @param nodeId The ID of the root {@link Node} of the {@link Model} for the instance to contain
|
||||
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
|
||||
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean mergeTransform) {
|
||||
this(model, transform, nodeId, false, false, mergeTransform);
|
||||
}
|
||||
|
||||
/** Recursively searches the mode for the specified node.
|
||||
* @param model The source {@link Model}
|
||||
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
|
||||
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
|
||||
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
|
||||
public SharedModel(final Model model, final String nodeId, boolean parentTransform, boolean mergeTransform) {
|
||||
this(model, null, nodeId, true, parentTransform, mergeTransform);
|
||||
}
|
||||
|
||||
/** Recursively searches the mode for the specified node.
|
||||
* @param model The source {@link Model}
|
||||
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
|
||||
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
|
||||
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
|
||||
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
|
||||
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean parentTransform, boolean mergeTransform) {
|
||||
this(model, transform, nodeId, true, parentTransform, mergeTransform);
|
||||
}
|
||||
|
||||
/** @param model The source {@link Model}
|
||||
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
|
||||
* @param recursive True to recursively search the Model's node tree, false to only search for a root node
|
||||
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
|
||||
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
|
||||
public SharedModel(final Model model, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform) {
|
||||
this(model, null, nodeId, recursive, parentTransform, mergeTransform);
|
||||
}
|
||||
|
||||
/** @param model The source {@link Model}
|
||||
* @param transform The {@link Matrix4} instance for this ModelInstance to reference or null to create a new matrix.
|
||||
* @param nodeId The ID of the {@link Node} within the {@link Model} for the instance to contain
|
||||
* @param recursive True to recursively search the Model's node tree, false to only search for a root node
|
||||
* @param parentTransform True to apply the parent's node transform to the instance (only applicable if recursive is true).
|
||||
* @param mergeTransform True to apply the source node transform to the instance transform, resetting the node transform. */
|
||||
public SharedModel(final Model model, final Matrix4 transform, final String nodeId, boolean recursive, boolean parentTransform, boolean mergeTransform) {
|
||||
this.model = model;
|
||||
this.transform = transform == null ? new Matrix4() : transform;
|
||||
nodePartBones.clear();
|
||||
Node copy, node = model.getNode(nodeId, recursive);
|
||||
this.nodes.add(copy = copyNode(null, node));
|
||||
if (mergeTransform) {
|
||||
this.transform.mul(parentTransform ? node.globalTransform : node.localTransform);
|
||||
copy.translation.set(0,0,0);
|
||||
copy.rotation.idt();
|
||||
copy.scale.set(1,1,1);
|
||||
} else if (parentTransform && copy.parent != null)
|
||||
this.transform.mul(node.parent.globalTransform);
|
||||
setBones();
|
||||
copyAnimations(model.animations);
|
||||
calculateTransforms();
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
|
||||
public SharedModel(final Model model, final String... rootNodeIds) {
|
||||
this(model, null, rootNodeIds);
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
|
||||
public SharedModel(final Model model, final Matrix4 transform, final String... rootNodeIds) {
|
||||
this.model = model;
|
||||
this.transform = transform == null ? new Matrix4() : transform;
|
||||
if (rootNodeIds == null)
|
||||
copyNodes(model.nodes);
|
||||
else
|
||||
copyNodes(model.nodes, rootNodeIds);
|
||||
copyAnimations(model.animations);
|
||||
calculateTransforms();
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
|
||||
public SharedModel(final Model model, final Array<String> rootNodeIds) {
|
||||
this(model, null, rootNodeIds);
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance with only the specified nodes and materials of the given model. */
|
||||
public SharedModel(final Model model, final Matrix4 transform, final Array<String> rootNodeIds) {
|
||||
this.model = model;
|
||||
this.transform = transform == null ? new Matrix4() : transform;
|
||||
copyNodes(model.nodes, rootNodeIds);
|
||||
copyAnimations(model.animations);
|
||||
calculateTransforms();
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance at the specified position. */
|
||||
public SharedModel(final Model model, Vector3 position) {
|
||||
this(model);
|
||||
this.transform.setToTranslation(position);
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance at the specified position. */
|
||||
public SharedModel(final Model model, float x, float y, float z) {
|
||||
this(model);
|
||||
this.transform.setToTranslation(x, y, z);
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance with the specified transform. */
|
||||
public SharedModel(final Model model, Matrix4 transform) {
|
||||
this(model, transform, (String[])null);
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance which is an copy of the specified ModelInstance. */
|
||||
public SharedModel(SharedModel copyFrom) {
|
||||
this(copyFrom, copyFrom.transform.cpy());
|
||||
}
|
||||
|
||||
/** Constructs a new ModelInstance which is an copy of the specified ModelInstance. */
|
||||
public SharedModel(SharedModel copyFrom, final Matrix4 transform) {
|
||||
this.model = copyFrom.model;
|
||||
this.transform = transform == null ? new Matrix4() : transform;
|
||||
copyNodes(copyFrom.nodes);
|
||||
copyAnimations(copyFrom.animations);
|
||||
calculateTransforms();
|
||||
}
|
||||
|
||||
/** @return A newly created ModelInstance which is a copy of this ModelInstance */
|
||||
public SharedModel copy() {
|
||||
return new SharedModel(this);
|
||||
}
|
||||
|
||||
private ObjectMap<NodePart, ArrayMap<Node, Matrix4>> nodePartBones = new ObjectMap<NodePart, ArrayMap<Node, Matrix4>>();
|
||||
private void copyNodes (Array<Node> nodes) {
|
||||
nodePartBones.clear();
|
||||
for(int i = 0, n = nodes.size; i<n; ++i) {
|
||||
final Node node = nodes.get(i);
|
||||
this.nodes.add(copyNode(null, node));
|
||||
}
|
||||
setBones();
|
||||
}
|
||||
|
||||
private void copyNodes (Array<Node> nodes, final String... nodeIds) {
|
||||
nodePartBones.clear();
|
||||
for(int i = 0, n = nodes.size; i<n; ++i) {
|
||||
final Node node = nodes.get(i);
|
||||
for (final String nodeId : nodeIds) {
|
||||
if (nodeId.equals(node.id)) {
|
||||
this.nodes.add(copyNode(null, node));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
setBones();
|
||||
}
|
||||
|
||||
private void copyNodes (Array<Node> nodes, final Array<String> nodeIds) {
|
||||
nodePartBones.clear();
|
||||
for(int i = 0, n = nodes.size; i<n; ++i) {
|
||||
final Node node = nodes.get(i);
|
||||
for (final String nodeId : nodeIds) {
|
||||
if (nodeId.equals(node.id)) {
|
||||
this.nodes.add(copyNode(null, node));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
setBones();
|
||||
}
|
||||
|
||||
private void setBones() {
|
||||
for (ObjectMap.Entry<NodePart,ArrayMap<Node, Matrix4>> e : nodePartBones.entries()) {
|
||||
if (e.key.invBoneBindTransforms == null)
|
||||
e.key.invBoneBindTransforms = new ArrayMap<Node, Matrix4>(true, e.value.size, Node.class, Matrix4.class);
|
||||
e.key.invBoneBindTransforms.clear();
|
||||
|
||||
for (final ObjectMap.Entry<Node, Matrix4> b : e.value.entries())
|
||||
e.key.invBoneBindTransforms.put(getNode(b.key.id), b.value); // Share the inv bind matrix with the model
|
||||
|
||||
e.key.bones = new Matrix4[e.value.size];
|
||||
for (int i = 0; i < e.key.bones.length; i++)
|
||||
e.key.bones[i] = new Matrix4();
|
||||
}
|
||||
}
|
||||
|
||||
private Node copyNode(Node parent, Node node) {
|
||||
Node copy = new Node();
|
||||
copy.id = node.id;
|
||||
//copy.boneId = node.boneId;
|
||||
copy.parent = parent;
|
||||
copy.translation.set(node.translation);
|
||||
copy.rotation.set(node.rotation);
|
||||
copy.scale.set(node.scale);
|
||||
copy.localTransform.set(node.localTransform);
|
||||
copy.globalTransform.set(node.globalTransform);
|
||||
for(NodePart nodePart: node.parts) {
|
||||
copy.parts.add(copyNodePart(nodePart));
|
||||
}
|
||||
for(Node child: node.children) {
|
||||
copy.children.add(copyNode(copy, child));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
private NodePart copyNodePart (NodePart nodePart) {
|
||||
NodePart copy = new NodePart();
|
||||
copy.meshPart = new MeshPart();
|
||||
copy.meshPart.id = nodePart.meshPart.id;
|
||||
copy.meshPart.indexOffset = nodePart.meshPart.indexOffset;
|
||||
copy.meshPart.numVertices = nodePart.meshPart.numVertices;
|
||||
copy.meshPart.primitiveType = nodePart.meshPart.primitiveType;
|
||||
copy.meshPart.mesh = nodePart.meshPart.mesh;
|
||||
|
||||
if (nodePart.invBoneBindTransforms != null)
|
||||
nodePartBones.put(copy, nodePart.invBoneBindTransforms);
|
||||
|
||||
// final int index = materials.indexOf(nodePart.material, false);
|
||||
// if (index < 0)
|
||||
// materials.add(copy.material = nodePart.material.copy());
|
||||
// else
|
||||
// copy.material = materials.get(index);
|
||||
//
|
||||
copy.material = nodePart.material;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
private void copyAnimations (final Iterable<Animation> source) {
|
||||
for (final Animation anim : source) {
|
||||
Animation animation = new Animation();
|
||||
animation.id = anim.id;
|
||||
animation.duration = anim.duration;
|
||||
for (final NodeAnimation nanim : anim.nodeAnimations) {
|
||||
final Node node = getNode(nanim.node.id);
|
||||
if (node == null)
|
||||
continue;
|
||||
NodeAnimation nodeAnim = new NodeAnimation();
|
||||
nodeAnim.node = node;
|
||||
for (final NodeKeyframe kf : nanim.keyframes) {
|
||||
NodeKeyframe keyframe = new NodeKeyframe();
|
||||
keyframe.keytime = kf.keytime;
|
||||
keyframe.rotation.set(kf.rotation);
|
||||
keyframe.scale.set(kf.scale);
|
||||
keyframe.translation.set(kf.translation);
|
||||
nodeAnim.keyframes.add(keyframe);
|
||||
}
|
||||
if (nodeAnim.keyframes.size > 0)
|
||||
animation.nodeAnimations.add(nodeAnim);
|
||||
}
|
||||
if (animation.nodeAnimations.size > 0)
|
||||
animations.add(animation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Traverses the Node hierarchy and collects {@link Renderable} instances for every
|
||||
* node with a graphical representation. Renderables are obtained from the provided
|
||||
* pool. The resulting array can be rendered via a {@link ModelBatch}.
|
||||
*
|
||||
* @param renderables the output array
|
||||
* @param pool the pool to obtain Renderables from
|
||||
*/
|
||||
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
|
||||
for(Node node: nodes) {
|
||||
getRenderables(node, renderables, pool);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return The renderable of the first node's first part. */
|
||||
public Renderable getRenderable(final Renderable out) {
|
||||
return getRenderable(out, nodes.get(0));
|
||||
}
|
||||
|
||||
/** @return The renderable of the node's first part. */
|
||||
public Renderable getRenderable(final Renderable out, final Node node) {
|
||||
return getRenderable(out, node, node.parts.get(0));
|
||||
}
|
||||
|
||||
public Renderable getRenderable(final Renderable out, final Node node, final NodePart nodePart) {
|
||||
nodePart.setRenderable(out);
|
||||
if (nodePart.bones == null && transform != null)
|
||||
out.worldTransform.set(transform).mul(node.globalTransform);
|
||||
else if (transform != null)
|
||||
out.worldTransform.set(transform);
|
||||
else
|
||||
out.worldTransform.idt();
|
||||
out.userData = userData;
|
||||
return out;
|
||||
}
|
||||
|
||||
protected void getRenderables(Node node, Array<Renderable> renderables, Pool<Renderable> pool) {
|
||||
if(node.parts.size > 0) {
|
||||
for(NodePart nodePart: node.parts) {
|
||||
renderables.add(getRenderable(pool.obtain(), node, nodePart));
|
||||
}
|
||||
}
|
||||
|
||||
for(Node child: node.children) {
|
||||
getRenderables(child, renderables, pool);
|
||||
}
|
||||
}
|
||||
|
||||
/** Calculates the local and world transform of all {@link Node} instances in this model, recursively.
|
||||
* First each {@link Node#localTransform} transform is calculated based on the translation, rotation and
|
||||
* scale of each Node. Then each {@link Node#calculateWorldTransform()}
|
||||
* is calculated, based on the parent's world transform and the local transform of each Node.
|
||||
* Finally, the animation bone matrices are updated accordingly.</p>
|
||||
*
|
||||
* This method can be used to recalculate all transforms if any of the Node's local properties (translation, rotation, scale)
|
||||
* was modified.
|
||||
*/
|
||||
public void calculateTransforms() {
|
||||
final int n = nodes.size;
|
||||
for(int i = 0; i < n; i++) {
|
||||
nodes.get(i).calculateTransforms(true);
|
||||
}
|
||||
for(int i = 0; i < n; i++) {
|
||||
nodes.get(i).calculateBoneTransforms(true);
|
||||
}
|
||||
}
|
||||
|
||||
/** Calculate the bounding box of this model instance.
|
||||
* This is a potential slow operation, it is advised to cache the result.
|
||||
* @param out the {@link BoundingBox} that will be set with the bounds.
|
||||
* @return the out parameter for chaining */
|
||||
public BoundingBox calculateBoundingBox(final BoundingBox out) {
|
||||
out.inf();
|
||||
return extendBoundingBox(out);
|
||||
}
|
||||
|
||||
/** Extends the bounding box with the bounds of this model instance.
|
||||
* This is a potential slow operation, it is advised to cache the result.
|
||||
* @param out the {@link BoundingBox} that will be extended with the bounds.
|
||||
* @return the out parameter for chaining */
|
||||
public BoundingBox extendBoundingBox(final BoundingBox out) {
|
||||
final int n = nodes.size;
|
||||
for(int i = 0; i < n; i++)
|
||||
nodes.get(i).extendBoundingBox(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** @param id The ID of the animation to fetch (case sensitive).
|
||||
* @return The {@link Animation} with the specified id, or null if not available. */
|
||||
public Animation getAnimation(final String id) {
|
||||
return getAnimation(id, true);
|
||||
}
|
||||
|
||||
/** @param id The ID of the animation to fetch.
|
||||
* @param ignoreCase whether to use case sensitivity when comparing the animation id.
|
||||
* @return The {@link Animation} with the specified id, or null if not available. */
|
||||
public Animation getAnimation(final String id, boolean ignoreCase) {
|
||||
final int n = animations.size;
|
||||
Animation animation;
|
||||
if (ignoreCase) {
|
||||
for (int i = 0; i < n; i++)
|
||||
if ((animation = animations.get(i)).id.equalsIgnoreCase(id))
|
||||
return animation;
|
||||
} else {
|
||||
for (int i = 0; i < n; i++)
|
||||
if ((animation = animations.get(i)).id.equals(id))
|
||||
return animation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// /** @param id The ID of the material to fetch.
|
||||
// * @return The {@link Material} with the specified id, or null if not available. */
|
||||
// public Material getMaterial(final String id) {
|
||||
// return getMaterial(id, true);
|
||||
// }
|
||||
//
|
||||
// /** @param id The ID of the material to fetch.
|
||||
// * @param ignoreCase whether to use case sensitivity when comparing the material id.
|
||||
// * @return The {@link Material} with the specified id, or null if not available. */
|
||||
// public Material getMaterial(final String id, boolean ignoreCase) {
|
||||
// final int n = materials.size;
|
||||
// Material material;
|
||||
// if (ignoreCase) {
|
||||
// for (int i = 0; i < n; i++)
|
||||
// if ((material = materials.get(i)).id.equalsIgnoreCase(id))
|
||||
// return material;
|
||||
// } else {
|
||||
// for (int i = 0; i < n; i++)
|
||||
// if ((material = materials.get(i)).id.equals(id))
|
||||
// return material;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
/** @param id The ID of the node to fetch.
|
||||
* @return The {@link Node} with the specified id, or null if not found. */
|
||||
public Node getNode(final String id) {
|
||||
return getNode(id, true);
|
||||
}
|
||||
|
||||
/** @param id The ID of the node to fetch.
|
||||
* @param recursive false to fetch a root node only, true to search the entire node tree for the specified node.
|
||||
* @return The {@link Node} with the specified id, or null if not found. */
|
||||
public Node getNode(final String id, boolean recursive) {
|
||||
return getNode(id, recursive, false);
|
||||
}
|
||||
|
||||
/** @param id The ID of the node to fetch.
|
||||
* @param recursive false to fetch a root node only, true to search the entire node tree for the specified node.
|
||||
* @param ignoreCase whether to use case sensitivity when comparing the node id.
|
||||
* @return The {@link Node} with the specified id, or null if not found. */
|
||||
public Node getNode(final String id, boolean recursive, boolean ignoreCase) {
|
||||
return Node.getNode(nodes, id, recursive, ignoreCase);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.oscim.jeo.test;
|
||||
package org.oscim.test.jeo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
@ -1,4 +1,4 @@
|
||||
package org.oscim.jeo.test;
|
||||
package org.oscim.test.jeo;
|
||||
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.TileGridLayer;
|
144
vtm-playground/src/org/oscim/test/renderer/AtlasTest.java
Normal file
144
vtm-playground/src/org/oscim/test/renderer/AtlasTest.java
Normal file
@ -0,0 +1,144 @@
|
||||
package org.oscim.test.renderer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.backend.canvas.Paint.Cap;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.renderer.ElementRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.atlas.TextureAtlas;
|
||||
import org.oscim.renderer.atlas.TextureAtlas.Rect;
|
||||
import org.oscim.renderer.atlas.TextureAtlas.Slot;
|
||||
import org.oscim.renderer.elements.LineLayer;
|
||||
import org.oscim.renderer.elements.TextItem;
|
||||
import org.oscim.renderer.elements.TextLayer;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.theme.styles.TextStyle;
|
||||
import org.oscim.theme.styles.TextStyle.TextBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AtlasTest extends GdxMap {
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
mMap.setMapPosition(0, 0, 1 << 4);
|
||||
mMap.layers().add(new GenericLayer(mMap, new AtlasRenderLayer()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new AtlasTest(), null, 400);
|
||||
}
|
||||
|
||||
static class AtlasRenderLayer extends ElementRenderer {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(AtlasRenderLayer.class);
|
||||
|
||||
public AtlasRenderLayer() {
|
||||
|
||||
TextureAtlas mAtlas = TextureAtlas.create(2048, 2048, 1);
|
||||
|
||||
LineLayer ll = layers.getLineLayer(0);
|
||||
ll.line = new LineStyle(Color.BLUE, 3, Cap.BUTT);
|
||||
ll.scale = 1f;
|
||||
|
||||
LineLayer ll2 = layers.getLineLayer(1);
|
||||
ll2.line = new LineStyle(Color.RED, 3, Cap.BUTT);
|
||||
ll2.scale = 1f;
|
||||
|
||||
LineLayer ll3 = layers.getLineLayer(2);
|
||||
ll3.line = new LineStyle(Color.GREEN, 3, Cap.BUTT);
|
||||
ll3.scale = 1f;
|
||||
|
||||
TextLayer tl = new TextLayer();
|
||||
TextStyle t = new TextBuilder().setFontSize(20).setColor(Color.BLACK).build();
|
||||
layers.setTextureLayers(tl);
|
||||
|
||||
float[] points = new float[10];
|
||||
|
||||
for (int i = 0; i < 400; i++) {
|
||||
int w = (int) (20 + Math.random() * 256);
|
||||
int h = (int) (20 + Math.random() * 56);
|
||||
Rect r = mAtlas.getRegion(w, h);
|
||||
if (r == null) {
|
||||
log.debug("no space left");
|
||||
continue;
|
||||
}
|
||||
r.x += 1;
|
||||
r.y += 1;
|
||||
|
||||
points[0] = r.x;
|
||||
points[1] = r.y;
|
||||
points[2] = r.x + (r.w - 2);
|
||||
points[3] = r.y;
|
||||
points[4] = r.x + (r.w - 2);
|
||||
points[5] = r.y + (r.h - 2);
|
||||
points[6] = r.x;
|
||||
points[7] = r.y + (r.h - 2);
|
||||
points[8] = r.x;
|
||||
points[9] = r.y;
|
||||
ll.addLine(points, 10, false);
|
||||
|
||||
r.x += 1;
|
||||
r.y += 1;
|
||||
points[0] = r.x;
|
||||
points[1] = r.y;
|
||||
points[2] = r.x + (w - 4);
|
||||
points[3] = r.y;
|
||||
points[4] = r.x + (w - 4);
|
||||
points[5] = r.y + (h - 4);
|
||||
points[6] = r.x;
|
||||
points[7] = r.y + (h - 4);
|
||||
points[8] = r.x;
|
||||
points[9] = r.y;
|
||||
|
||||
log.debug("add region: " + Arrays.toString(points));
|
||||
ll2.addLine(points, 10, false);
|
||||
|
||||
TextItem ti = TextItem.pool.get();
|
||||
ti.set(r.x + r.w / 2, r.y + r.h / 2, "" + i, t);
|
||||
|
||||
ti.x1 = 0;
|
||||
ti.y1 = 1; // (short) (size / 2);
|
||||
ti.x2 = 1; // (short) size;
|
||||
ti.y2 = 1;
|
||||
tl.addText(ti);
|
||||
}
|
||||
|
||||
for (Slot s = mAtlas.mSlots; s != null; s = s.next) {
|
||||
points[0] = s.x;
|
||||
points[1] = s.y;
|
||||
points[2] = s.x + s.w;
|
||||
points[3] = s.y;
|
||||
points[4] = s.x + s.w;
|
||||
points[5] = 2048;
|
||||
points[6] = s.x;
|
||||
points[7] = 2048;
|
||||
points[8] = s.x;
|
||||
points[9] = s.y;
|
||||
|
||||
ll3.addLine(points, 10, false);
|
||||
}
|
||||
|
||||
tl.prepare();
|
||||
//tl.labels = TextItem.pool.releaseAll(tl.labels);
|
||||
}
|
||||
|
||||
boolean initial = true;
|
||||
|
||||
@Override
|
||||
protected void update(GLViewport v) {
|
||||
|
||||
if (initial) {
|
||||
mMapPosition.copy(v.pos);
|
||||
initial = false;
|
||||
|
||||
compile();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
88
vtm-playground/src/org/oscim/test/renderer/BezierTest.java
Normal file
88
vtm-playground/src/org/oscim/test/renderer/BezierTest.java
Normal file
@ -0,0 +1,88 @@
|
||||
package org.oscim.test.renderer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.core.GeometryBuffer;
|
||||
import org.oscim.core.Point;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.renderer.ElementRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.elements.LineLayer;
|
||||
import org.oscim.theme.styles.LineStyle;
|
||||
import org.oscim.utils.geom.BezierPath;
|
||||
|
||||
public class BezierTest extends GdxMap {
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
mMap.layers().add(new GenericLayer(mMap, new BezierPathLayer()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new BezierTest(), null, 400);
|
||||
}
|
||||
|
||||
static class BezierPathLayer extends ElementRenderer {
|
||||
|
||||
public BezierPathLayer() {
|
||||
mMapPosition.scale = 0;
|
||||
|
||||
GeometryBuffer g = new GeometryBuffer(100, 1);
|
||||
g.startLine();
|
||||
|
||||
Point[] pts = new Point[10];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
pts[i] = new Point(i * 3, (i * i) % 3 * 4);
|
||||
pts[i].x *= 10;
|
||||
pts[i].y *= 10;
|
||||
// System.out.println(pts[i]);
|
||||
g.addPoint(pts[i]);
|
||||
}
|
||||
LineLayer ll = layers.addLineLayer(0, new LineStyle(Color.BLUE, 2f));
|
||||
ll.addLine(g);
|
||||
|
||||
List<Point> ctrl = BezierPath.cubicSplineControlPoints(pts, 0.1f);
|
||||
|
||||
g.clear();
|
||||
g.startLine();
|
||||
Point p0 = pts[0];
|
||||
|
||||
for (int j = 1, k = 0; j < pts.length; j++) {
|
||||
Point p1 = ctrl.get(k++);
|
||||
Point p2 = ctrl.get(k++);
|
||||
Point p3 = pts[j];
|
||||
System.out.println(">>> " + p1 + " " + p2);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
double mu = (i / 10f);
|
||||
Point p = BezierPath.cubicBezier(p0, p1, p2, p3, mu);
|
||||
g.addPoint(p);
|
||||
System.out.println(mu + " " + p);
|
||||
}
|
||||
p0 = p3;
|
||||
}
|
||||
ll = layers.addLineLayer(1, new LineStyle(Color.CYAN, 2f));
|
||||
ll.addLine(g);
|
||||
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
layers.clear();
|
||||
setReady(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized void update(GLViewport v) {
|
||||
|
||||
if (mMapPosition.scale == 0)
|
||||
mMapPosition.copy(v.pos);
|
||||
|
||||
if (!isReady()) {
|
||||
compile();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
164
vtm-playground/src/org/oscim/test/renderer/CustomRenderer.java
Normal file
164
vtm-playground/src/org/oscim/test/renderer/CustomRenderer.java
Normal file
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.test.renderer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.core.MapPosition;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.GLShader;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GLUtils;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.LayerRenderer;
|
||||
|
||||
/*
|
||||
* This is an example how to integrate custom OpenGL drawing routines as map overlay
|
||||
*
|
||||
* based on chapter 2 from:
|
||||
* https://github.com/dalinaum/opengl-es-book-samples/tree/master/Android
|
||||
* */
|
||||
|
||||
public class CustomRenderer extends LayerRenderer {
|
||||
|
||||
private final Map mMap;
|
||||
private final MapPosition mMapPosition;
|
||||
|
||||
private int mProgramObject;
|
||||
private int hVertexPosition;
|
||||
private int hMatrixPosition;
|
||||
|
||||
private FloatBuffer mVertices;
|
||||
private final float[] mVerticesData = {
|
||||
-200, -200, 1.0f,
|
||||
200, 200, 0,
|
||||
-200, 200, 0.5f,
|
||||
200, -200, 0.5f,
|
||||
};
|
||||
private boolean mInitialized;
|
||||
|
||||
public CustomRenderer(Map map) {
|
||||
mMap = map;
|
||||
mMapPosition = new MapPosition();
|
||||
}
|
||||
|
||||
// ---------- everything below runs in GLRender Thread ----------
|
||||
@Override
|
||||
protected void update(GLViewport v) {
|
||||
if (!mInitialized) {
|
||||
if (!init())
|
||||
return;
|
||||
|
||||
mInitialized = true;
|
||||
|
||||
// fix current MapPosition
|
||||
mMapPosition.copy(v.pos);
|
||||
|
||||
compile();
|
||||
}
|
||||
}
|
||||
|
||||
protected void compile() {
|
||||
// modify mVerticesData and put in FloatBuffer
|
||||
|
||||
mVertices.clear();
|
||||
mVertices.put(mVerticesData);
|
||||
mVertices.flip();
|
||||
|
||||
setReady(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void render(GLViewport v) {
|
||||
|
||||
// Use the program object
|
||||
GLState.useProgram(mProgramObject);
|
||||
|
||||
GLState.blend(true);
|
||||
GLState.test(false, false);
|
||||
|
||||
// unbind previously bound VBOs
|
||||
GL.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
|
||||
|
||||
// Load the vertex data
|
||||
//mVertices.position(0);
|
||||
GL.glVertexAttribPointer(hVertexPosition, 3, GL20.GL_FLOAT, false, 0, mVertices);
|
||||
//mVertices.position(2);
|
||||
//GL.glVertexAttribPointer(hVertexPosition, 2, GL20.GL_FLOAT, false, 4, mVertices);
|
||||
|
||||
GLState.enableVertexArrays(hVertexPosition, -1);
|
||||
|
||||
/* apply view and projection matrices */
|
||||
// set mvp (tmp) matrix relative to mMapPosition
|
||||
// i.e. fixed on the map
|
||||
|
||||
float ratio = 1f / mMap.getWidth();
|
||||
|
||||
v.mvp.setScale(ratio, ratio, 1);
|
||||
v.mvp.multiplyLhs(v.proj);
|
||||
v.mvp.setAsUniform(hMatrixPosition);
|
||||
|
||||
// Draw the triangle
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
GLUtils.checkGlError("...");
|
||||
}
|
||||
|
||||
private boolean init() {
|
||||
// Load the vertex/fragment shaders
|
||||
int programObject = GLShader.createProgram(vShaderStr, fShaderStr);
|
||||
|
||||
if (programObject == 0)
|
||||
return false;
|
||||
|
||||
// Handle for vertex position in shader
|
||||
hVertexPosition = GL.glGetAttribLocation(programObject, "a_pos");
|
||||
|
||||
hMatrixPosition = GL.glGetUniformLocation(programObject, "u_mvp");
|
||||
|
||||
// Store the program object
|
||||
mProgramObject = programObject;
|
||||
|
||||
mVertices = ByteBuffer.allocateDirect(mVerticesData.length * 4)
|
||||
.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private final static String vShaderStr = "" +
|
||||
"precision mediump float;"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
+ "attribute vec4 a_pos;"
|
||||
+ "varying float alpha;"
|
||||
+ "void main()"
|
||||
+ "{"
|
||||
+ " gl_Position = u_mvp * vec4(a_pos.xy, 0.0, 1.0);"
|
||||
+ " alpha = a_pos.z;"
|
||||
+ "}";
|
||||
|
||||
private final static String fShaderStr = "" +
|
||||
"precision mediump float;"
|
||||
+ "varying float alpha;"
|
||||
+ "void main()"
|
||||
+ "{"
|
||||
+ " gl_FragColor = vec4 (alpha, 1.0-alpha, 0.0, 0.7 );"
|
||||
+ "}";
|
||||
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
package org.oscim.test.renderer;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
import org.oscim.backend.GL20;
|
||||
import org.oscim.backend.canvas.Color;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.gdx.GdxMapApp;
|
||||
import org.oscim.layers.GenericLayer;
|
||||
import org.oscim.renderer.BufferObject;
|
||||
import org.oscim.renderer.ElementRenderer;
|
||||
import org.oscim.renderer.GLShader;
|
||||
import org.oscim.renderer.GLState;
|
||||
import org.oscim.renderer.GLUtils;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.utils.FastMath;
|
||||
|
||||
public class HexagonRenderTest extends GdxMap {
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
mMap.setMapPosition(0, 0, 1 << 4);
|
||||
mMap.layers().add(new GenericLayer(mMap, new HexagonRenderer()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
GdxMapApp.init();
|
||||
GdxMapApp.run(new HexagonRenderTest(), null, 400);
|
||||
}
|
||||
|
||||
/* This is an example how to integrate custom OpenGL drawing routines as map
|
||||
* overlay
|
||||
*
|
||||
* based on chapter 2 from:
|
||||
* https://github.com/dalinaum/opengl-es-book-samples/tree/master/Android */
|
||||
|
||||
static class HexagonRenderer extends ElementRenderer {
|
||||
|
||||
private int mProgramObject;
|
||||
private int hVertexPosition;
|
||||
private int hMatrixPosition;
|
||||
private int hColorPosition;
|
||||
private int hCenterPosition;
|
||||
|
||||
//private FloatBuffer mVertices;
|
||||
private boolean mInitialized;
|
||||
private BufferObject mVBO;
|
||||
|
||||
int mZoom = -1;
|
||||
float mCellScale = 60 * MapRenderer.COORD_SCALE;
|
||||
|
||||
@Override
|
||||
protected void update(GLViewport v) {
|
||||
if (!mInitialized) {
|
||||
if (!init()) {
|
||||
return;
|
||||
}
|
||||
mInitialized = true;
|
||||
|
||||
compile();
|
||||
mMapPosition.copy(v.pos);
|
||||
}
|
||||
|
||||
//if (mZoom != v.pos.zoomLevel) {
|
||||
// mMapPosition.copy(v.pos);
|
||||
// mZoom = v.pos.zoomLevel;
|
||||
//}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compile() {
|
||||
|
||||
float[] vertices = new float[12];
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
vertices[i * 2 + 0] = (float) Math.cos(Math.PI * 2 * i / 6) * mCellScale;
|
||||
vertices[i * 2 + 1] = (float) Math.sin(Math.PI * 2 * i / 6) * mCellScale;
|
||||
}
|
||||
FloatBuffer buf = MapRenderer.getFloatBuffer(12);
|
||||
buf.put(vertices);
|
||||
|
||||
mVBO = BufferObject.get(GL20.GL_ARRAY_BUFFER, 0);
|
||||
mVBO.loadBufferData(buf.flip(), 12 * 4);
|
||||
|
||||
setReady(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void render(GLViewport v) {
|
||||
|
||||
// Use the program object
|
||||
GLState.useProgram(mProgramObject);
|
||||
|
||||
GLState.blend(true);
|
||||
GLState.test(false, false);
|
||||
|
||||
// bind VBO data
|
||||
mVBO.bind();
|
||||
|
||||
// set VBO vertex layout
|
||||
GL.glVertexAttribPointer(hVertexPosition, 2, GL20.GL_FLOAT, false, 0, 0);
|
||||
|
||||
GLState.enableVertexArrays(hVertexPosition, -1);
|
||||
|
||||
/* apply view and projection matrices */
|
||||
// set mvp (tmp) matrix relative to mMapPosition
|
||||
// i.e. fixed on the map
|
||||
setMatrix(v);
|
||||
v.mvp.setAsUniform(hMatrixPosition);
|
||||
|
||||
final int offset_x = 4;
|
||||
final int offset_y = 16;
|
||||
|
||||
float h = (float) (Math.sqrt(3) / 2);
|
||||
for (int y = -offset_y; y < offset_y; y++) {
|
||||
for (int x = -offset_x; x < offset_x; x++) {
|
||||
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
|
||||
float yy = y * h + h / 2;
|
||||
|
||||
GL.glUniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
|
||||
|
||||
//float alpha = 1 + (float) Math.log10(FastMath.clamp(
|
||||
// (float) Math.sqrt(xx * xx + yy * yy) / offset_y, 0.0f, 1.0f)) * 2;
|
||||
|
||||
float alpha = (float) Math.sqrt(xx * xx + yy * yy) / offset_y;
|
||||
|
||||
float fy = (float) (y + offset_y) / (offset_y * 2);
|
||||
float fx = (float) (x + offset_x) / (offset_x * 2);
|
||||
float fz = FastMath.clamp(
|
||||
(float) (x < 0 || y < 0 ? 1 - Math.sqrt(fx * fx + fy
|
||||
* fy)
|
||||
: 0),
|
||||
0,
|
||||
1);
|
||||
|
||||
int c = 0xff << 24
|
||||
| (int) (0xff * fy) << 16
|
||||
| (int) (0xff * fx) << 8
|
||||
| (int) (0xff * fz);
|
||||
|
||||
GLUtils.setColor(hColorPosition, c, alpha);
|
||||
|
||||
GL.glDrawArrays(GL20.GL_TRIANGLE_FAN, 0, 6);
|
||||
}
|
||||
}
|
||||
|
||||
GLUtils.setColor(hColorPosition, Color.DKGRAY, 0.3f);
|
||||
|
||||
for (int y = -offset_y; y < offset_y; y++) {
|
||||
for (int x = -offset_x; x < offset_x; x++) {
|
||||
float xx = x * 2 + (y % 2 == 0 ? 1 : 0);
|
||||
float yy = y * h + h / 2;
|
||||
|
||||
GL.glUniform2f(hCenterPosition, xx * (mCellScale * 1.5f), yy * mCellScale);
|
||||
GL.glDrawArrays(GL20.GL_LINE_LOOP, 0, 6);
|
||||
}
|
||||
}
|
||||
|
||||
GLUtils.checkGlError("...");
|
||||
}
|
||||
|
||||
private boolean init() {
|
||||
// Load the vertex/fragment shaders
|
||||
int programObject = GLShader.createProgram(vShaderStr, fShaderStr);
|
||||
|
||||
if (programObject == 0)
|
||||
return false;
|
||||
|
||||
// Handle for vertex position in shader
|
||||
hVertexPosition = GL.glGetAttribLocation(programObject, "a_pos");
|
||||
|
||||
hMatrixPosition = GL.glGetUniformLocation(programObject, "u_mvp");
|
||||
|
||||
hColorPosition = GL.glGetUniformLocation(programObject, "u_color");
|
||||
|
||||
hCenterPosition = GL.glGetUniformLocation(programObject, "u_center");
|
||||
|
||||
// Store the program object
|
||||
mProgramObject = programObject;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private final static String vShaderStr = ""
|
||||
+ "#ifdef GLES\n"
|
||||
+ "precision mediump float;\n"
|
||||
+ "#endif\n"
|
||||
+ "uniform mat4 u_mvp;"
|
||||
+ "uniform vec2 u_center;"
|
||||
+ "attribute vec2 a_pos;"
|
||||
+ "void main()"
|
||||
+ "{"
|
||||
+ " gl_Position = u_mvp * vec4(u_center + a_pos, 0.0, 1.0);"
|
||||
+ "}";
|
||||
|
||||
private final static String fShaderStr = ""
|
||||
+ "#ifdef GLES\n"
|
||||
+ "precision mediump float;\n"
|
||||
+ "#endif\n"
|
||||
+ "varying float alpha;"
|
||||
+ "uniform vec4 u_color;"
|
||||
+ "void main()"
|
||||
+ "{"
|
||||
+ " gl_FragColor = u_color;"
|
||||
+ "}";
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.test.renderer;
|
||||
|
||||
import org.oscim.backend.CanvasAdapter;
|
||||
import org.oscim.renderer.ElementRenderer;
|
||||
import org.oscim.renderer.GLViewport;
|
||||
import org.oscim.renderer.elements.SymbolItem;
|
||||
import org.oscim.renderer.elements.SymbolLayer;
|
||||
|
||||
public class SymbolRenderLayer extends ElementRenderer {
|
||||
boolean initialize = true;
|
||||
|
||||
public SymbolRenderLayer() {
|
||||
SymbolLayer l = new SymbolLayer();
|
||||
layers.setTextureLayers(l);
|
||||
|
||||
SymbolItem it = SymbolItem.pool.get();
|
||||
it.billboard = false;
|
||||
|
||||
try {
|
||||
it.bitmap = CanvasAdapter.g.loadBitmapAsset("jar:symbols/cafe.png");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
l.addSymbol(it);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update(GLViewport v) {
|
||||
if (initialize) {
|
||||
initialize = false;
|
||||
mMapPosition.copy(v.pos);
|
||||
compile();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user