theatre-js / theatre

Motion design editor for the web
https://www.theatrejs.com
Apache License 2.0
10.82k stars 337 forks source link

how to set props value in sequence by code? #447

Closed wahono77 closed 8 months ago

wahono77 commented 8 months ago

How to set props value in sequence by code? My purpose is to load sequence from saved file and I can continue editing animation from previous animation that is stored in a file.

Thanks

wahono77 commented 8 months ago

I save animation data using studio.createContentOfSaveFile("myproject") to variabel animationData ans save it to file. And after load animationData from file, I want to rebuild sequence animation. But I got nothing. What's wrong in my code?

        studio.setSelection([ObjStudio]);
        const objProp =
          _this.animationData.sheetsById.Objects.sequence.tracksByObject[
            objName
          ];
        if (objProp) {
          const propKeys = Object.keys(objProp.trackIdByPropPath);
          for (var i = 0; i < propKeys.length; i++) {
            let propValue =
              objProp.trackData[objProp.trackIdByPropPath[propKeys[i]]];
            if (propValue.keyframes.length > 0) {
              let propname = JSON.parse(propKeys[i]);
              for (var j = 0; j < propValue.keyframes.length; j++) {
                sheet.sequence.position = propValue.keyframes[j].position;
                studio.transaction(({ set, unset }) => {
                  if (propname.length == 1) {
                    set(
                      ObjStudio.props[propname[0]],
                      propValue.keyframes[j].value
                    );
                  } else {
                    set(
                      ObjStudio.props[propname[0]][propname[1]],
                      propValue.keyframes[j].value
                    );
                  }
                });
              }
            }
          }
        }
vimlesh1975 commented 8 months ago

The code may work but before using set function, prop must have been manually right click and choose sequence. I normally save content and animationContent both in a file. When i open the file I Create a new project with saved animationContent. See a ref https://github.com/vimlesh1975/ReactCasparClient/blob/b98222f8a19eeac8cb8b09ae867d9bf1ea56dd52/client/src/theatrejs/WebAnimator.jsx#L1927

wahono77 commented 8 months ago

The code may work but before using set function, prop must have been manually right click and choose sequence. I normally save content and animationContent both in a file. When i open the file I Create a new project with saved animationContent. See a ref https://github.com/vimlesh1975/ReactCasparClient/blob/b98222f8a19eeac8cb8b09ae867d9bf1ea56dd52/client/src/theatrejs/WebAnimator.jsx#L1927

Thanks vimlesh1975, but right click and choose sequence is impossible if we have many keyframes :) I think we need new API to create sequence from code.

wahono77 commented 8 months ago

I got the solution. After load project, sequence should be play to show sequence UI editor I create the test project here

https://codepen.io/wahono77/pen/RwLNJXK