Save properties to JSON, download - Import from JSON and apply settings Playground (using BJS GUI)

Dears,

You know the quality of my dev skills :grin: (I actually should start all my posts with this :sweat_smile: :joy:)…

For a small project I’m about to finalize, I needed this feature where I can (simply) save a number of properties by writing them to a json file, download the file and next allow the user to upload this file as ‘presets’ and apply it to the scene.

I had a few bits here or there and was trying to fill-in the missing parts from this forum… and next from other forums… and ended-up with ChatGPT… which I have proven wrong on some parts after identifying other bits.

So, I decided I would make a PG that I can later share here with an explicit name so that others who’d likely face the same situation would be able to have at least this source.

I believe the logic and method to be correct (and it works)… but I do have a small issue with it.
I’m uploading and applying properties for the active camera. They all do load correctly, but - for the active camera only (camera1 in this PG), they ALL apply only if I load the file twice… for some unknown reason. On the first pass, it looks like some are ‘ignored’. So, I tried detaching, re-attaching the camera, re-instruct scene.activeCameras, make another scene.render… nothing seems to do the trick? :cry:

Anyone of yours experts have a quick look at this PG and tell me where I messed it up?
Also feel free to improve the script for write to json, export/download, import, parse, apply (if not the best). I’d like to keep it ‘explicit’ and ‘simple’ but I don’t want to share something that’s not 100% ‘recommendable’.

The file upload ‘twist’ to also work in the Playground and using only the BJS GUI I tweaked (for JSON) from this source from @Evgeni_Popov (while ChatGPT was first saying it is not possible, lol :rofl:) BTW ChatGPT v4 is thanking @Evgeni_Popov for his outstanding contribution :grin: :smiley:

Thanks and meanwhile, have a great sunday :sunglasses:

1 Like

I can’t repro this for me,
I’ve logged the applied data in this PG

and all the properties seem to be applied correctly for every camera, the active cam also seems to be returned to the same state as saved : O

Did you try change all properties. Including target (panning) and the camera fov? That’s how I eventually encounter the issue. Could be because of the target. May be should use setTarget first :thinking:… 'need to investigate… Anyways, thx for having a look at it and have a great day :sunglasses:

We should ask a forum moderator to revoke your Jedi master badge then… :rofl:

It works for me at once.

1 Like

Don’t know how I got it in the first place :laughing: I can assure you I didn’t bribe for it :joy: I’m just hoping I will never have to face a dark lord - or he’ll slice me with a single line of saber code :crossed_swords: :rofl:

That’s probably just ‘incidental’. Like most of the things I do :sweat_smile: :joy: … As said above, I will have to check back on this… Thanks for taking the time to have a look at it :pray: and have a great day :sunglasses:

1 Like

go it, repro’d, it’s prolly cuz of position

see if this works : )

steps to repro:

1 Like

What about this bad boy?

Both PGs are working for me. I tried both several times. No issues here. MacOS/Chrome

I can only hope I manage to flee
:fearful: :scream: :ghost:

if nearly works

the final image is like so,

very close to the og position but not quite : )
can you try the steps listed, if it still doesn’t happen for you it might be a platform thing : O
I’m on firefox linux

Yes, of course ‘position’. Stupid me completely forgot about it. Huh? Did I? I’m not sure; The position of the arc cam should be from the target (orbital) using alpha, beta and radius. :thinking:… and I thought I had a perfect understanding of cameras :sweat_smile: As I said, need to check on this…

Pixel perfect :rofl:

{
  "cameras": {
    "cam1": {
      "pos": [
        -125.56967008124252,
        29.178128936089838,
        -3.943280117020711
      ],
      "alpha": 3.0572155675663497,
      "beta": 1.3686958455711484,
      "radius": 131.9706,
      "camlock": false,
      "fov": 0.8,
      "targetX": 3.255,
      "targetY": 2.688,
      "targetZ": -14.839
    },
    "cam2": {
      "pos": [
        8.660254037844386,
        5.000000000000001,
        0
      ],
      "alpha": 0,
      "beta": 1.0471975511965976,
      "radius": 10,
      "camlock": true,
      "fov": 0.8,
      "targetX": 0,
      "targetY": 0,
      "targetZ": 0
    },
    "cam3": {
      "pos": [
        8.660254037844386,
        5.000000000000001,
        0
      ],
      "alpha": 0,
      "beta": 1.0471975511965976,
      "radius": 10,
      "camlock": false,
      "fov": 0.8,
      "targetX": 0,
      "targetY": 0,
      "targetZ": 0
    }
  }
}
2 Likes

The position of the arc cam should be from the target (orbital) using alpha, beta and radius

It also works if you set the target the first thing and then the other stuff

2 Likes

Pixel perfect :rofl:

yeah I have no clue lmao

wait you’re using the latest PG, ofc that has the correct code, use the original!

Well, the answer may be in my last question. If it is ‘from the target’ may be just need to set the target first :grin: That could explain why it works when you upload a second time… :thinking:

Edit: typed and didn’t see your post

That might be it. I’ll just quickly check on that. There’s a fair chance that would be it… don’t waste more time on this. I’ll sure let you know if it isn’t :grin: :sweat_smile:

1 Like

OK Guys,
Thanks again and sorry for wasting your precious time :face_with_hand_over_mouth:.
The above looks like the solution:
Set the target first.

Here’s an updated playground that should work (does it? :sweat_smile: :joy:)

Edit: Updated PG link. Uses ‘pointerUp’ observable to load the file which prevents from having to click twice (since the hidden DOM element is created dynamically).

1 Like

Here’s an updated playground that should work (does it? :sweat_smile: :joy:)

yea, can’t repro on this : )

1 Like