MackeyK24 Posted August 24, 2017 Share Posted August 24, 2017 Hi guys... I am trying to create a binary format serialization for Babylon scene files... But the main question is how do I manually create a scene from the: var parsedScene = JSON.parse(binData) now I already have the javascript object representing my scene... I don't wanna to save out to string and try a re-load via the XmlHttpRequest or anything like that... I want to create a FileLoader like the obj... But have a .bin file... I will DECODE the binary into JSON Objects (not strings)... is there a BABYLON.SceneLoader.CreateFromObject(jsonObject):BABYLON.Scene or ANYTHING like that ??? Yo @Deltakosh Is There anything to help me create a scene from a parsed json object (not string) ??? Thanks In Advanced Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 25, 2017 Share Posted August 25, 2017 The think as I mentioned earlier is that we already have a binary format. You should rely on it and perhaps expand it if needed because all the loading infrastructure is already in and we won't support multiple binary format Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted August 25, 2017 Author Share Posted August 25, 2017 49 minutes ago, Deltakosh said: The think as I mentioned earlier is that we already have a binary format. You should rely on it and perhaps expand it if needed because all the loading infrastructure is already in and we won't support multiple binary format Yo @Deltakosh I get you... But as a little side project I am working on... I was able to serialize an entire scene... skeletons, animations, particle systems and everything.. the entire scene file as one binary myscene.babylon.bin... Is working perfect... I just need to create a scene from that parsed json just like you do when you read from xmlhttpresponse or whatever to parse the .babylon text... I just already have the parsed up json object... I know you got your existing binary format... and I am not and will not try to replace... but would LUV to get this tiny little going... Just please take a look at this code and see if you can tell me how create scene from the JSObject... I mead could always try some kind a way to hack in the loading process with some kinda the BLOB url workaround... But creating the scene in the DESIRED spot below, would be freakin awesome: var sceneUrl:string = rootUrl + sceneFilename; BABYLON.Tools.LoadFile(sceneUrl, (arrayBuffer:any)=>{ var byteArray:Uint8Array = new Uint8Array(arrayBuffer); var jsonScene:any = BABYLON.SceneManager.DecodeBinary(byteArray); console.log("===> Decoded Binary Scene File: " + sceneFilename); // TODO: BABYLON.SceneLoader.CreateFromParsedJson(jsonScene) }, null, null, true, () => { console.warn("Error - Unable to load " + sceneUrl); }); Or guide me into the SceneLoader process and I can hack around in there (For my own purposes... and and OPTION in the toolkit to pack your whole scene file as 1 binary file instead of a bunch of external mesh data and a son catalog file... NOT THAT ANYTHING WRONG WITH THAT... Im just playing around in my toolkit and I got native binary work perfect... IF I SAVE THE jsonScene:any to a string and cut and copy to a text file and load that... my decoded son works perfect)... BTW I what do you consider a good reduction ratio from doing all the binary stuff... either your way or my way... I loaded up a character with several minutes worth of long playing animations on a skin with 65 bones... the total JSON file size was 18 MB and the BINARY encoded version of same file was 13MB ... I think thats about 20 - 25 percent file size reduction and all one single file binary encoded for even easier/smoother network communications to the web browser... I would think... Anyways.. enough me tootin my horn... but if you can help.. thanks... as always IF NO CAN... NO CAN Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted August 25, 2017 Author Share Posted August 25, 2017 UPDATE: Yo @Deltakosh ... Nevermind bro... I get em I just use a Loader: export class ToolkitSceneLoader implements ISceneLoaderPlugin { public name = "babylon.bin"; public extensions: BABYLON.ISceneLoaderPluginExtensions = { ".bin": {isBinary: true}, }; public load(scene: BABYLON.Scene, data: any, rootUrl: string): boolean { var byteArray:Uint8Array = new Uint8Array(data); var parsedScene:any = BABYLON.SceneManager.DecodeBinary(byteArray); return this.loadHandler(scene, parsedScene, rootUrl); } public importMesh(meshesNames: any, scene: BABYLON.Scene, data: any, rootUrl: string, meshes: BABYLON.AbstractMesh[], particleSystems: BABYLON.ParticleSystem[], skeletons: BABYLON.Skeleton[]): boolean { var byteArray:Uint8Array = new Uint8Array(data); var parsedScene:any = BABYLON.SceneManager.DecodeBinary(byteArray); return this.importMeshHandler(meshesNames, scene, parsedScene, rootUrl, meshes, particleSystems, skeletons); } } Works like a charm GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 25, 2017 Share Posted August 25, 2017 Well done! Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted August 26, 2017 Author Share Posted August 26, 2017 18 hours ago, Deltakosh said: Well done! Yo @Deltakosh ... You know I looked at loaders before but decided to go with my own BABYLON.SceneManager.Load and ImportMesh functions that are in the current scenemanager.ts... But needing to get to the raw son creating is the PERFECT spot for all scene loader... and its all automatic HOWEVER you load a scene or import meshes... my managers will attach and pears the metadata automatically give LIFE-CYCLE... IF METADATA EXISTS.. IF NOT.. DOES NOTHING. Again works like a charm... Take a look at my Scene Manager Loader... Nice, tight and clean Json and Binary scene loading.. no fuse no muse module BABYLON { export class JsonSceneLoader implements ISceneLoaderPlugin { public name = "toolkit.json"; public extensions: BABYLON.ISceneLoaderPluginExtensions = { ".babylon": {isBinary: false}, }; public load(scene: BABYLON.Scene, data: any, rootUrl: string): boolean { var plugin:BABYLON.ToolkitPlugin = new BABYLON.ToolkitPlugin(); var result:boolean = false; result = plugin.load(scene, data, rootUrl); if (result === true) { (<any>BABYLON.SceneManager).parseSceneMetadata(rootUrl, scene); } else { BABYLON.Tools.Warn("Failed to load json scene data."); } return result; } public importMesh(meshesNames: any, scene: BABYLON.Scene, data: any, rootUrl: string, meshes: BABYLON.AbstractMesh[], particleSystems: BABYLON.ParticleSystem[], skeletons: BABYLON.Skeleton[]): boolean { var plugin:BABYLON.ToolkitPlugin = new BABYLON.ToolkitPlugin(); var result:boolean = false; result = plugin.importMesh(meshesNames, scene, data, rootUrl, meshes, particleSystems, skeletons); if (result === true) { (<any>BABYLON.SceneManager).parseMeshMetadata(meshes, scene); } else { BABYLON.Tools.Warn("Failed to load json scene data."); } return result; } } export class BinarySceneLoader implements ISceneLoaderPlugin { public name = "toolkit.binary"; public extensions: BABYLON.ISceneLoaderPluginExtensions = { ".bin": {isBinary: true}, }; public load(scene: BABYLON.Scene, data: any, rootUrl: string): boolean { var plugin:BABYLON.ToolkitPlugin = new BABYLON.ToolkitPlugin(); var bytes:Uint8Array = new Uint8Array(data); var json:string = BABYLON.SceneManager.DecompressToString(bytes); var result:boolean = plugin.load(scene, json, rootUrl); if (result === true) { (<any>BABYLON.SceneManager).parseSceneMetadata(rootUrl, scene); } else { BABYLON.Tools.Warn("Failed to load binary scene data"); } json = null; bytes = null; return result; } public importMesh(meshesNames: any, scene: BABYLON.Scene, data: any, rootUrl: string, meshes: BABYLON.AbstractMesh[], particleSystems: BABYLON.ParticleSystem[], skeletons: BABYLON.Skeleton[]): boolean { var plugin:BABYLON.ToolkitPlugin = new BABYLON.ToolkitPlugin(); var bytes:Uint8Array = new Uint8Array(data); var json:string = BABYLON.SceneManager.DecompressToString(bytes); var result:boolean = plugin.importMesh(meshesNames, scene, json, rootUrl, meshes, particleSystems, skeletons); if (result === true) { (<any>BABYLON.SceneManager).parseMeshMetadata(meshes, scene); } else { BABYLON.Tools.Warn("Failed to load json scene data"); } json = null; bytes = null; return result; } } if (BABYLON.SceneLoader) { BABYLON.SceneLoader.RegisterPlugin(new BABYLON.JsonSceneLoader()); BABYLON.SceneLoader.RegisterPlugin(new BABYLON.BinarySceneLoader()); } } Thanks again ... As always for all your help GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.