I am saving my layers independently to a database. But now I want to load the JSON to the specific layer. But I can only load the JSON for the stage.
How can i solve this?
Here is the generic procedure for serializing an individual layer:
var layerJSON=layer.toJSON();
Then you can deserialize that layerJSON and add the rehydrated layer to the stage like this:
var layer1=Kinetic.Node.create(layerJSON);
stage.add(layer1);
layer1.draw();
Remember that images and event handlers are not serialized so you will have to add them to the layers after deserializing.
A Demo: http://jsfiddle.net/m1erickson/LMEn6/
Related
We would like to know if it possible to initialize the viewer to only render an specific object id.
There is a tutorial to extract geometry from a model, but it involves using the derivative to convert geometry to OBJ.
https://forge.autodesk.com/en/docs/model-derivative/v2/tutorials/extract-geometry-from-source-file/
The idea is to create a catalog of objects based on the elements in a model (document). We usually work with Revit files.
Viewer works with dbIds (or nodeIds which are equivalent to objectIds) and may load bubbles (geometry constructs) selectively based on - see live sample here
viewer.loadModel(svfUrl,{ids:[dbIds...]})
Is there a way to deserialize a JSON response to a custom object in Swift WITHOUT having to individually map each element.
Currently I am doing it manually with SwiftyJSON but it still requires me to map every field redundantly:
var myproperty1 = json["myproperty1"].stringValue
However coming from a C# background it is as simple as one line of code:
JsonConvert.DeserializeObject<CustomObject>(jsonString); //No mapping needed.
Source - http://www.newtonsoft.com/json/help/html/DeserializeObject.htm
Since I am writing many API endpoints I would like to avoid all the boilerplate mapping code that can be prone to errors. Keep in mind that my JSON responses will be multiple levels deep with arrays of arrays. So any function would need to be recursive.
Similiar question : Automatic JSON serialization and deserialization of objects in Swift
You could use EVReflection for that. You can use code like:
var user:User = User(json:jsonString)
or
var jsonString:String = user.toJsonString()
See the GitHub page for more detailed sample code
You should be able to use key value coding for this. You'd have to make your object a subclass of NSObject for KVC to work, and then you could loop through the elements of the JSON data and use setValue:forKey to assign a value for each key in the dictionary.
Note that this would be dangerous: If the target object did not contain a value for a specific key then your code would crash, so your program would crash on JSON data that contained invalid keys. Not a good thing.
I use create.js library and want to load canvas objects from json data and import canvas object to json.
Previously I used fabric.js and there was function:
canvas.loadFromJSON(jsonData, function() {});
and
to import canvas to JSON data canvas.toJSON() or canvas.toDatalessJson(),
so I'm interested if this is possible in create.js too?
if yes how i can do it?
I am attempting to write a STEP loader that converts STEP to the THREE JS JSON format.
However, I have not seen anything in the JSON format information about creating a scene graph - i.e. a hierarchical scene structure.
Is it possible to do so?
Thanks - Imtiaz
If you are writing a Loader, you don't need Three.js JSON format as an intermediate step. As the other loaders do, just create the THREE.Geometry, THREE.Mesh, THREE.Object3D etc objects directly as you go about parsing the STEP file. Object3D is the basic container which you can use to create hierarchies. In addition to being able to contain meshes, you can .add() any number of other Object3Ds into Object3D.
If you still want to have this JSON step, the three JSON model format itself does not have support for hierarchies. But there is also (rather new I believe) Three.js object JSON format, which can store hierarchies. See THREE.ObjectLoader , it is in src/loaders/ObjectLoader.js
how to create and save a UIComponent information in JSON file? I'm using as3corelib but i'm unable to save object on disk in text file.
var encodedObjectString:String = com.adobe.serialization.json.JSON.encode(zorder.getItemAt(0));
Can I save UIObject in JSON text file?
I guess your serialization attempt goes via parent link of your UIObject you want to serialize, and then traverses child list encountering the same UIObject. Stack overflow.
In order to make a manual serialization, you need to serialize only part of your object's fields, excluding any and every link to DisplayObjects of any kind (UIObject class included). For this, perhaps it'll be better if you do a writeExternal() implementation for your object, perform a serialization via ByteArray, then use it as you want. Or, you can have your UIObject have a dedicated "data to serialize" object as property that will get serialized natively, and will only contain data that you want to serialize.
Here is a manual about externalizable objects.