Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripted object, "still mode"? #242

Open
peteihis opened this issue Nov 10, 2020 · 7 comments
Open

Scripted object, "still mode"? #242

peteihis opened this issue Nov 10, 2020 · 7 comments

Comments

@peteihis
Copy link
Contributor

Hi!

I have been constructing a visualization of a piece that has a repetitive pattern that changes along distance. Now the object that is repeated is a CSGObject that has 7 operations in it's history. I think it will go up to 11 eventually. The object vith small variations is repeated some 50 times, two instances of each. It may actually turn into making every one of them individual, I don't know yet.

Running the script (only one thread) takes currently close to half a minute with relatively coarse surface error setting -- you can see one or two corners on a long arch that really should appear smooth.

So far so good but, when I try to make a camera drive around the object and pull the time marker on the score the script starts to recreate the object every time though nothing is changing. Hiding the scripted object does not help, so obviously building a camera drive does not happen any time soon with this scene.

I could copy the script into the script editor and create a still model, but as I'm still working on it, then I'd have to delete all the parts of the old model, every time I make a change. Keeping it scripted would have some advantages.

So do you see a reasonable way of adding a "still mode" to scripted objects so that they would not have to be constantly recalculated when nothing is changing? -- Even better if this would be extended to loading RaytratcerRenderer.

@peteihis
Copy link
Contributor Author

peteihis commented Nov 10, 2020

And of course I can use the isPreview() option and create just brick model (which helps a bit) for interactive viewing, but then I'd sometimes like to see the final one on the editor too.

What if there were two toggles on the scripted object editor: Still / Animating and Preview / Final? -- Then there should probably be something to detect if isPreview() or Time() are used in the script or the parameters.

@Sailsman63
Copy link
Member

a repetitive pattern that changes along distance.

Do you mean 'changes based on location in scene' or something else?

If this really is a static object, or one that only changes at a few specific points on the timeline, the script should cache the completed CSG model, and perhaps a converted TriangleMesh. Just use the cached object unless the time/location/whatever invalidates the current shape.

@peteihis
Copy link
Contributor Author

peteihis commented Nov 11, 2020

'changes based on location'

Yes, basically so. The changing dimensions happen in local space and the scripted object actually reads some dimensions from a hand sketched curve on the scene.

script should cache the completed CSG model

Now that you say it, I think I may have tried something like that before. -- I think I used a separate script to reset the scripted object (= set the object in memory to null)... I think that could be done by a boolean variable in groovy memory.

The content of the scripted object is actually

50 CSGObjects × 2
 1 Cylinder   × 50
 1 Cylinder   ×  1
 1 Sphere     ×  1
12 parameters to control the build. 

So to cache it I'd have to cache the parameters, the vertex positions of the curve and each object with the list of coordinate systems where to add it. Then the script should check the if any of the parameters or the extra boolean or the control curve have changed to make the decision if it should recreate the objects or use the ones in the memory...

So far I have used @field and/or declared each variable, because undeclared variables that float in the memory tend to ... well ... be remembered even when they have become obsolete and then the next time I open the scene the script may not work.

Something like that?

@Sailsman63
Copy link
Member

While doing a little digging to make sure I understood the question in #241, I found that ObjectCollection (Which ScriptedObject derives from) already caches the object structure under the hood. If it's rebuilding for every frame, your script is either:

  • Calling for the current time, and (not?)changing things based on that time
  • Calling for coordinates, and (not?)changing things

The content of the scripted object is actually

That's a lot going on in a single scripted object. How many of these objects:

  • Actually depend on time, directly or indirectly?
  • Depend on location of the ScriptedObject?
  • Depend on location of/shape of another object?

Of those 12 parameters, how many vary based on time? (IE, have a track)

@peteihis
Copy link
Contributor Author

I see...

None of them depend on time in any way or have tracks or depend on the location of the object. The 50 CSGs depend of a curve on the scene. The curve is not moving and the location of the curve is not a factor, only vertex positions are used.

What is done, is that the scripted object gets a duplicate of the curve, subdivides it a few times, get vertex vectors into an array and then finds (by linear interpolation) the corresponding x-value for each of the 50 y-values that define the CSGs.

So the way to tame it down would be to extract vertexPositions() of the (unsmoothed) curve by other means and save those as an array in the script text? (A script to build a scripted object is not entirely alien to me. -- Type a marker in the scripted object text and tell a tool script to edit that part....) -- And then recreate the curve inside the scripted object and start smoothing...

It's a kind of pity I can't show the thing (not until it's public anyway) but I'm doing it for somebody else.

@Sailsman63
Copy link
Member

This doesn't sound like it should be re-building on every frame.

By default, each object does have a position & rotation track, even if there are no keyframes. Maybe that's enough? Try manually deleting these tracks from the curve object, and see if that makes a difference.

So the way to tame it down would be to extract vertexPositions() of the (unsmoothed) curve by other means and save those as an array in the script text?

I don't know if that would help, and shouldn't be necessary.

Would it be possible to share a "Anonymized" version of the script? I'm thinking:

  • 1 or 2 CSGs made up of a couple of random sphere/cylinder/whatever to stand in for your actual models
  • A simple curve, maybe no more than 3 or 4 points
  • 1 or 2 parameters

What I'm really interested in is:

  • How the parameters are input to the script
  • How all of the parts interact:
    • What math and logic are used to interrelate them?
    • How and when are the various inputs changed?

@peteihis
Copy link
Contributor Author

How the parameters are input to the script

I said parameters but what I mean is just typed in values of variables (that are in essense parameters of the process of creating the objects) -- so no script parameters involved. Like double size = 0.5; Cube cube = new Cube(size, size, size);

I'll come back to with example script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants