I'm trying to parse in TileMapObjects from an object layer from the Tiled map I have created with Tiled map editor using the libgdx framework. I have already successfully parsed in other types of map objects such as RectangleMapObjects using the following code:
bouncyPlatforms = Array<BouncyPlatforms>()
for (`object` in map.layers.get("bouncyPlatformLayer").objects.getByType(RectangleMapObject::class.java)) {
val rect = `object`.rectangle
bouncyPlatforms.add(BouncyPlatforms(screen, rect.x / 100, rect.y / 100))
}
However, when I try to parse in a TileMapObject with the following code:
foregroundImages = Array<ForegroundEnvironment>()
for(`object` in map.layers.get("foregroundLayer").objects.getByType(TiledMapTileMapObject::class.java)) {
foregroundImages.add(ForegroundEnvironment(screen, 1f, 1f)) //(1,1) used for (x,y) while learning how to load TileMapObjects. Positioning still needs to be done
}
I am met with the following error:
Exception in thread "LWJGL Application"
java.lang.IllegalStateException: map.layers.get("foregroundLayer")
must not be null.
I have 10 TileMapObjects in the "foregroundLayer" so either I am not referring to them correctly or the program is not able to detect that they are there. Can anyone help me resolve this issue?
Related
Map shows correctly, then I check that the map is fully loaded before I do the moveCamera on it. The map then shows the correct area as defined by the bounds. But after the move, the setOnCameraIdleListener is never called as is expected. Here is the bit of code of question
map.setOnMapLoadedCallback(GoogleMap.OnMapLoadedCallback {
Log.e(tag, "setOnMapLoadedCallback")
//set camera bounds
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100))
})
map.setOnCameraIdleListener {
//create snapshot
Log.e(tag, "setOnCameraIdleListener")
}
I am using lite mode for the map and according to the documentation it looks like it should be supported but I couldn't find anything definite.
What may I be missing?
UPDATE:
Here is how I worked around this bug in the SDK.
Created a val defined as the callback.
private val snapshotReadyCallback : GoogleMap.SnapshotReadyCallback = GoogleMap.SnapshotReadyCallback {
SaveSnapshot(it)
}
"it" is a bitmap of the map. You could do the saving directly in the callback but I call a function instead.
Within setOnMapLoadedCallback did the following
gmap?.setOnMapLoadedCallback {
gmap?.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100))
//2 seconds lag to ensure camera has had time to move
//since camera move override doesnt work in setOnMapLoadedCallback
handler.postDelayed({ // Do something after 2s = 2000ms
gmap?.snapshot(snapshotReadyCallback)
}, 2000)
}
Adding the delay to grab the snapshot allowed enough time for the camera to have moved already. It will then call the snapshotReadyCallback which will then call a function that does the actual saving.
i have been trying to load the json model with any of these loader
1)OBJLoader()
2)JSONLoader()
3)AssimpJSONLoader()
But in all case i am able to load the object but not able to see on the threejs scene.
Here is small section of my loading code
var loader2= new THREE.ObjectLoader();//new THREE.JSONLoader();
loader2.load( 'Models/bed.json', function ( object ) {
for (var i = 0; i < object.children.length; i++)
{
object.children[i].visible=true;
object.children[i].material.color = 0xffb830;
}
scene.add( object );
});
Problem is when i use the obj loader it will say use JSONLoader .when i use json loader it gives me error
"Uncaught TypeError: Cannot read property 'length' of undefined".
If you try to load the object given in the link you will get the whole picture.
Here is the link of my object .
I cant understand is it the issue with my json file loader or not
As the same file is being used by some other developer and use code like this
THREE.JSONLoader.prototype.loadAjaxJSON
Any direction on the resolution to resolve issue will be welcome.
I'm trying to decide on the best Javascript 3D library for my project.
I like Three.js a bit more than Scene.js, but the coding style of Scene.js seems more efficient, because I need to create about 100 objects on the fly, and this would mean declaring hundreds of variables with Three.js.
In Three.js it seems that for each different object you need to define variables and add them to the scene, like this :
var renderer = new THREE.WebGLRenderer();
var camera =
new THREE.PerspectiveCamera(
VIEW_ANGLE,
ASPECT,
NEAR,
FAR);
var scene = new THREE.Scene();
var sphere = new THREE.Mesh(
new THREE.SphereGeometry(
50,
16,
16),
sphereMaterial);
scene.add(sphere);
while in Scene.js, objects are created in a JSON-like structure, like this :
var scene = SceneJS.createScene({
nodes:[
{
type:"material",
color: { r: 0.3, g: 0.3, b: 1.0 },
nodes:[
{
type: "rotate",
id: "myRotate",
y: 1.0,
angle: 0,
nodes: [
{
type:"geometry",
source:{
type:"teapot"
}
}
]
}
]
}
]
});
Now my question is, if it's possible to use a more JSON-like coding style with Three.js as well?
I already found out about THREE.JSONLoader, but since Three.js doesn't have very good documentation, I find it very hard to discover if this would be right for me. It seems to be more aimed at converted models from 3D-software, but I really need to build the objects myself.
Yes you can use JSON to define geometries in Three.js. You can parse JSON directly like this (untested, but at least the idea is there):
var json = { .... }; // your JSON geometry, not as string but already parsed object
var loader = new THREE.JSONLoader();
var result = loader.parse(json, texturePath);
var mesh = new THREE.Mesh(result.geometry, result.materials);
This can be used to define only geometries (and materials).
I agree that the documentation is sparse. Fortunately all Three.js JSON formats are pretty much human readable. You can check existing example models or take a look at https://github.com/mrdoob/three.js/wiki/JSON-Model-format-3.1 for geometry JSON format to use with JSONLoader.
For complex scene hierarchies (multiple geometries, lights etc) you can use the apparently undocumented ObjectLoader JSON format pretty much in a similar fashion as the JSONLoader format. For checking out the ObjectLoader JSON format, I suggest reading the source at src/loaders/ObjectLoader.js and/or generating sample files using http://threejs.org/editor/ (File->Export Scene / Object)
You could take a look at GLGE's 'Quick Notation': http://www.glge.org/ (I've not looked deeply into that BTW, so I'm not sure if it fits your needs).
If you use SceneJS, be sure first that its features cover your requirements, because it has a narrower feature set than THREE.js, being intended more for high detail visualisation rather than for a wide range of rendering effects.
If I were you though, I would jump in and write your own open source JSON layer for THREE.js, starting with what you need. I'm sure you would get contributors filling in the rest soon enough.
I cant seem to find a solution, anyways basically im trying to add a new dynamic texture to a 3D model using Away3d engine with flash
var myImage:BitmapData = new BitmapData(256, 256, true,0xFFFFFFFF);
// i cant seem to reference this to my 3D model in the example: Myevent(enter frame):
myModel.material = new TextureMaterial(new BitmapTexture(myImage))
I have tried different things along the above method, i have checked the away3d docs and cant find something similar for my current situation:
Im using the latest Away3d lib, and flash player 11...all my models works and load with there original embedded materialtTextures, im just trying to change them to a bitmap or texture that i have dynamically created
Take a look here:
https://github.com/away3d/away3d-tutorials-fp11/blob/master/tutorials/materials/basic_shading/src/Basic_Shading.as
They use Away3D’s Cast utility class to create BitmapTexture objects and they also add a bunch of different texture maps - hopefully this helps
** EDIT --- This Tutorial Does Work **
Added
public bmt:BtiMapTexture;
....
private function initMaterials():void {
this.bmt = new BitmapTexture(new BitmapData(256,256, true, 0x222277FF));
sphereMaterial = new TextureMaterial(Cast.bitmapTexture(this.bmt));
sphereMaterial.specularMap = Cast.bitmapTexture(this.bmt);
sphereMaterial.lightPicker = lightPicker;
}
And I got a nice blue sphere
My solution is:
var mesh:Mesh = 'the mesh for changing'
for each (var item:SubMesh in mesh.subMeshes) {
item.material = null;
}
mesh.material = new ColorMaterial(0xFF00FF);
I am trying to serialize & deserialize Vector. using ByteArray
Here is my code:
public static function serializeToString(value:Object):String{
if(value==null){
throw new Error("null isn't a legal serialization candidate");
}
var bytes:ByteArray = new ByteArray();
bytes.writeObject(value);
bytes.position = 0;
return Base64.encodeByteArray( bytes ).toString();
}
public static function readObjectFromStringBytes(value:String):Object{
var result:ByteArray= Base64.decodeToByteArray(value);
result.position=0;
return result.readObject();
}
No matter what I do, I keep having this error:
RangeError: Error #2006: The supplied index is out of bounds.
at flash.utils::ByteArray/readObject()
I am dipertly looking for a solution ..
Thanks in advance
Sameer
I found the problem reason after days of frustration ..
The loader SWF published for player 9, the content SWF published for player 10,
I simply republished the loader for player 10, and the Error #2006 disappeared from the loaded SWF
What I wonder about, is that the content uses Vector. type, which is player 10 feature,
how come it played correctly inside an older loader ?! Why there is no descriptive regarding different player versions ??
Try getting rid of the .position = 0 lines. They aren't necessary and the second one may be what is causing your issue. Also note that toString() is unecessary, as encodeByteArray already returns a String.
In case you want to send or receive the serialized object graph to server-side code without converting to a string first, see this link.