Load CreateJS canvas from json data - html

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?

Related

How to request WFS service from geoserver and load geojson data as a layer in cesium?

How can I load GeoJSON data dynamically from Geoserver, and load it to Cesium.js?
Cesium currently does not support loading in GeoJSON directly via some sort of "WFSProvider". That being said, the Cesium team apparently has plans to support WFS 3.0 sometime in the future.
For now, you would need to manually make an HTTP request to the WFS server for GeoJSON and load it into Cesium using the Cesium.GeoJsonDataSource class. Here is an example of this:
The idea is that you have a WFS server that is running somewhere. Once you have a WFS server that you can access, you can then write some JavaScript to make that request for GeoJSON:
const geoJsonPromise = fetch('http://example.com/geoserver/wfs?service=wfs&version=2.0.0&request=GetFeature&typeNames=namespace:featuretype').then(res => res.json());
The above code would return a WFS response wrapped within a JavaScript Promise. From here, you could then do something like...
const viewer = new Cesium.viewer('cesiumContainer');
geoJsonPromise.then(geoJson =>
viewer.dataSources.add(
Cesium.GeoJsonDataSource.load(
geoJson,
{ fill: Cesium.Color.PINK }
)
)
);
You could also create your own "WFSProvider" or, more accurately, "WFSDataSource" class that wraps the above functionality in a more generic fashion (could support more data formats) and abstracts it away.

What objects are supported in threejs JSON format?

I'm trying to export a scene from some modeling software to three.js using the latest JSON format (4).
It's not clear what objects are supported in this format.
Are mesh files (.stl, .obj), AxisHelper, ArrowHelper and TextGeometry supported?
I can export mesh files using Geometry but I don't want to reinvent the wheel.
What objects are supported?
Looking into the code it looks like that supported "objects" in the JSON format are:
Geometry
Material
Skinning/Bones
Animation/Frames
Morphing
Lights
Cameras
So AxisHelper, ArrowHelper and TextGeometry is not.

KineticJS load json layer

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/

Can JSON Format support Scene graph?

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

Get and parse JSON in Actionscript

What I want to do is make a get request to this URL: http://api.beatport.com/catalog/3/most-popular, which should return some JSON and then parse out certain information from it.
How would I go about doing this in Actionscript 3? I'm more concerned with figuring out how to get the data to feed to a JSON parser rather than parsing the JSON, since there seem to be plenty of questions about parsing JSON. The reason I want to do this in AS3 is that I have a 3D flash visualization set up and I want to get this data, parse out the relevant bits, and then display the parsed bits in the visualization.
I'm open to any other ways of doing this that can easily be integrated with Flash besides AS3 if there's an easier way to do it in another language.
Add the corelib.swc to your library path.
Import the JSON library: import com.adobe.serialization.json.JSON;
Call your service with code something like this:
var request:URLRequest=new URLRequest();
request.url=YOUR_ENDPOINT
request.requestHeaders=[new URLRequestHeader("Content-Type", "application/json")];
request.method=URLRequestMethod.GET;
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE, receive);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, notAllowed);
loader.addEventListener(IOErrorEvent.IO_ERROR, notFound);
loader.load(request);
protected function receive(event:Event):void
{
var myResults:Array=JSON.decode(event.target.data);
}
Parse the results with JSON.decode(results).
as3corelib is maintained here: https://github.com/mikechambers/as3corelib#readme.
Alternatively if you're using Flash Player 11 or AIR 3.0 or higher you can use the built in JSON object to decode your JSON. It's a top level object so you dont even need to import anything, just do:
var decoded : Object = JSON.parse(loadedText);
See: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/JSON.html
I believe the as3corelib has a JSON serializer and deserializer
You can use those instead of re-inventing the wheel and writing parsing logic afresh.