Jump to content

Saving and Loading a Scene


iiceman
 Share

Recommended Posts

  • 2 weeks later...

The loader is trying to get the view matrix at the constructor, which tries to load the target (which is only set later). So at certain cases it will fail. The scene is loaded correctly, the problem is that one single getViewMatrix call didn't work. 

I sent a PR (https://github.com/BabylonJS/Babylon.js/pull/443) setting a default target for an ArcRotate camera, which should solve this issue. At first a default value will be set, and later the correct target, if sent by the use in the scene. So target is not obligatory. default is Vector3.Zero().

Link to comment
Share on other sites

hi;
should i want to download the new babylon.js from github,if yes which version i want to download... and one more thing after loading movewithcollision is not working. what i mean is...movement of meshes is not working after loading

Link to comment
Share on other sites

The Serializer is only serializing the scene. Any functionality you added (for example in the scene before or after rendering functions) will not be serialized. You will have to "recreate" your scene - attach the controls again, set the correct animations and start them (if done using code), move your light's position programmatically etc'.

 

It will give you a scene file to load and play with. Not more than that .

In your case - all of the ponter event functions will be voided if loaded in a different browser window. They won't exist.

 

What exactly are you trying to achieve? Maybe the serializer is not exactly what you need. Maybe simply copying the code from the playground to you locally would work better!

Link to comment
Share on other sites

hi raanan; actually what i want to achieve is.. i am using BJS in html page,there i am having one button to save the scene and one button to load the scene, when i am click the save the button, i want to take the back up of scene and when i click the load it will load the save scene and there again i want to continue with that saved scene...

Link to comment
Share on other sites

So you will have to add the functionality yourself and attach it to the scene.

Actions (for example) cannot be added to a scene file. Scene events (before/after render etc') too. External functions too.

 

Look at the source of the serializer to see what it does (or doesn't) - https://github.com/BabylonJS/Babylon.js/blob/c37f4834838b88fe5dc88c0c4f66e06602c7887e/Babylon/Tools/babylon.sceneSerializer.ts 

 

I also implemented a (very simple) scene loader in the material editor - https://github.com/BabylonJS/Extensions/blob/master/MaterialEditor/MaterialEditor/canvas/CanvasController.ts#L148 , but in general you need nothing more than the scene loader

Link to comment
Share on other sites

  • 4 weeks later...

hi all i am having some problem in loading scene..when i am loading the data it give some error like
TypeError: a is undefined
...FromArray=function(a,c){return c||(c=0),new b(a[c],a[c+1],a[c+2])},b.FromArrayTo...

could you suggest me what i am doing wrong..

 

Link to comment
Share on other sites

hi i checked in debug version error showing in this line..

 Vector3.FromArray = function (array, offset) {
            if (!offset) {
                offset = 0;
            }
            return new Vector3(array[offset], array[offset + 1], array[offset + 2]);
        };

i am not getting which parameter i am missing

Link to comment
Share on other sites

hi raananw. now i able to get the saved data..but previously i given camera  target id as canvas now i change target position to [0,0,0]. Now its working fine.. but my question here if i give camera target id to canvas it wont work..?

Link to comment
Share on other sites

hi, folks.

 

Perhaps you knows what's kind this problem:

in loaded file:

"excludedMeshesIds": ["Cube.110","Cube.111"],
"includedOnlyMeshesIds": ["Cube.090","Cube.091"],

after loading, light have set only
_excludedMeshesIds  and _includedOnlyMeshesIds  arrays, but not set excludedMeshes and includedOnlyMeshes arrays.

i must init this manually?

And next, but not important: Adding in excludedMeshes not change _excludedMeshesIds, and when i save the scene i must use excludedMeshes.

Link to comment
Share on other sites

Hi Vahith,

camera.target should be a Vector3. to set a mesh id you can use the camera.lockedTargetId parameter (where you can give a mesh ID to set as a locked target).

 

@Blax,

This is the correct behaviour, if you are checing the arrays right after a scene was loaded. The excludedMeshes and includedOnlyMeshes arrays are populated only during an update. which will be right after before the first frame is rendered. If you had elements in the scene file's "excludedMeshesIds" or "includedOnlyMeshesIds", they will be stored temporarily in the _excludedMeshesIds  and _includedOnlyMeshesIds  arrays and will be processed later.

Link to comment
Share on other sites

Hi Vahith,

camera.target should be a Vector3. to set a mesh id you can use the camera.lockedTargetId parameter (where you can give a mesh ID to set as a locked target).

 

@Blax,

This is the correct behaviour, if you are checing the arrays right after a scene was loaded. The excludedMeshes and includedOnlyMeshes arrays are populated only during an update. which will be right after before the first frame is rendered. If you had elements in the scene file's "excludedMeshesIds" or "includedOnlyMeshesIds", they will be stored temporarily in the _excludedMeshesIds  and _includedOnlyMeshesIds  arrays and will be processed later.

 

Thank you, RaananW!

 

Sounds logical, but it not work :(

1. load the scene.

2. set engine.runRenderLoop function, and render. Render is work (my Cube is rotating in canvas).

3. check _excludedMeshesIds - all correct

4. check excludedMeshes - is empty and in scene can not see any exclusion.

5. if i set excludedMeshes manually - all is work, exclusion can see.

Where to dig? :)

Link to comment
Share on other sites

Can you show the scene you are trying to load?

 

Assumptions: 

  • We are talking about a light that reflects on specific meshes.
  • The meshes all have a material

If those two are correct and everything is activated, there shouldn't be a reason why it doesn't work. But would be great to find the cause and fix it.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...