Options
Go to last post Go to first unread
topspin  
#1 Posted : Thursday, March 30, 2023 10:30:38 PM(UTC)
topspin

Rank: Advanced Member

Joined: 12/7/2015(UTC)
Posts: 83

Thanks: 63 times
Was thanked: 47 time(s) in 36 post(s)

A very elementary example, but I'm sure folks will think of all sorts of things . . .


Q. Can you write a script for Daz Studio that will animate the intensity of all lights in the scene, starting with them, but coming on. As the lights come on, i'd like the color temperature and luminosity to be lower, scaling up in intensity and color temperature over 200 frames


A.Sure, here's a script for Daz Studio that will animate the intensity, color temperature, and luminosity of all lights in the scene over 200 frames. The script assumes that the lights have a color temperature property, which is true for some lights, such as the "Distant Light" and the "Photometric Spot Light" in Daz Studio.


// Function to set keyframes for a property
function setKeyframes(property, startFrame, endFrame, startValue, endValue) {
    property.addKey(startFrame, startValue);
    property.addKey(endFrame, endValue);
}


// Set the duration (in frames) for the animation
var duration = 200;


// Set the initial and final intensity, color temperature, and luminosity values
var initialIntensity = 0;
var finalIntensity = 100;
var initialColorTemp = 2000;
var finalColorTemp = 6500;
var initialLuminosity = 0;
var finalLuminosity = 1;


// Get the current scene
var scene = App.getScene();


// Iterate through all nodes in the scene
for (var i = 0; i < scene.getNumNodes(); i++) {
    var node = scene.getNode(i);
    var light = node.getObject();


    // Check if the object is a light
    if (light && light.inherits("DzLight")) {
        // Set keyframes for intensity
        var intensityProperty = light.findProperty("Intensity");
        if (intensityProperty) {
            setKeyframes(intensityProperty, 0, duration, initialIntensity, finalIntensity);
        }


        // Set keyframes for color temperature (if the light supports it)
        var colorTempProperty = light.findProperty("ColorTemperature");
        if (colorTempProperty) {
            setKeyframes(colorTempProperty, 0, duration, initialColorTemp, finalColorTemp);
        }


        // Set keyframes for luminosity
        var luminosityProperty = light.findProperty("Luminosity");
        if (luminosityProperty) {
            setKeyframes(luminosityProperty, 0, duration, initialLuminosity, finalLuminosity);
        }
    }
}


To run the script in Daz Studio:


  1. Open Daz Studio and go to Window > Panes (Tabs) > Script IDE to open the Script IDE.
  2. Copy and paste the script above into the Script IDE.
  3. Press the "Execute" button (or press F5) to execute the script.

After executing the script, the intensity, color temperature, and luminosity of all lights in the scene will be animated over 200 frames, starting with the lights off and gradually increasing in intensity and color temperature.


Note that the script assumes that your lights have properties named "Intensity", "ColorTemperature", and "Luminosity". If your specific light type uses different property names, you'll need to update the script accordingly.


 

Edited by user Sunday, April 2, 2023 8:47:55 PM(UTC)  | Reason: Not specified

thanks 3 users thanked topspin for this useful post.
Pushee-Ri on 3/31/2023(UTC), 5200north on 4/1/2023(UTC), Zaavaleta on 4/1/2023(UTC)
Pushee-Ri  
#2 Posted : Friday, March 31, 2023 1:38:59 AM(UTC)
Pushee-Ri

Rank: Advanced Member

Joined: 9/23/2020(UTC)
Posts: 343

Thanks: 77 times
Was thanked: 187 time(s) in 171 post(s)
Hi topspin - then I am soon unemployed.

Nope, just kidding ;-)

That sounds very interesting. Especially if you don't want to get stuck with the cranky DAZ API, but just need an idea generator in the right direction. And if you share the generated script as CC - even with GPT4 as author - there is nothing wrong with it IMHO.

Did you use the free basic version to create the script? I haven't tried it - but as a "directional guide" it looks usefull.
topspin  
#3 Posted : Friday, March 31, 2023 10:32:12 AM(UTC)
topspin

Rank: Advanced Member

Joined: 12/7/2015(UTC)
Posts: 83

Thanks: 63 times
Was thanked: 47 time(s) in 36 post(s)

Originally Posted by: rollemops Go to Quoted Post
Hi topspin - then I am soon unemployed.

Nope, just kidding ;-)

That sounds very interesting. Especially if you don't want to get stuck with the cranky DAZ API, but just need an idea generator in the right direction. And if you share the generated script as CC - even with GPT4 as author - there is nothing wrong with it IMHO.


So, I don't really think that Chat GPT is "the author", any more than suggesting than ECMA Script is "the author".  Now, when it randomly starts sending me scripts, unsolicited, with "my ideas of some scripts for you" . . . that would be different. But here, I'm asking it for something, its making me a script, I stick it into Daz and  . .  . well, I call that a convenience.


But if you think, say, of compiler design--  I don't see how its all that different, just that its now got a natural language interface. The "AI" thing -- well, there are some things there that are smart, like knowing that the idea I had about lights actually only applies to _some_ Daz lights, not all. 



Originally Posted by: rollemops Go to Quoted Post

Did you use the free basic version to create the script? I haven't tried it - but as a "directional guide" it looks usefull.


I've got the paid version of ChatGPT4,


Not sure if it does 3.5.


I doubt it would put anyone out of a job -- but might increase the popularity and utility of scripting in Daz. With Daz, pretty much any useful script is going to be very context dependant, you have to know just what you want, and how your scene is set up, to make use of scripts. So I think this can help people along, like a template, but I'll push it farther -- haven't asked it to analyse a scene yet, but I'll try.


It also can help with Poser Python (though I don't have Poser installed anymore and can't test whether this works, but now am curious)


Q. I'd like to have a Poser Python script in which the luminance property of a named material "C" varies inversely with the distance between two polygons. That is, I'd like C to get brighter when the polygons it is applied to get closer to a null, and darker when farther away. Can you do this?


A.


Yes, I can help you write a Poser Python script for that purpose. In this example, I'm assuming you have a Poser scene with two objects, each with a single polygon, and a null object representing the point of reference. Here's a basic script that demonstrates how to achieve this effect:


import poser
import math


# Constants
MATERIAL_NAME = "C"
MAX_DISTANCE = 5.0  # Define the maximum distance between polygons, in scene units
MIN_LUMINANCE = 0.0
MAX_LUMINANCE = 1.0


def distance_between_points(p1, p2):
    return math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 + (p1[2] - p2[2])**2)


def update_luminance(scene):
    # Get the objects from the scene by name
    poly1 = scene.Actor("Polygon1")
    poly2 = scene.Actor("Polygon2")
    null_object = scene.Actor("Null")


    # Calculate the distance between each polygon and the null object
    poly1_pos = poly1.WorldCenter()
    poly2_pos = poly2.WorldCenter()
    null_pos = null_object.WorldCenter()


    distance1 = distance_between_points(poly1_pos, null_pos)
    distance2 = distance_between_points(poly2_pos, null_pos)


    # Calculate the average distance
    avg_distance = (distance1 + distance2) / 2


    # Map the average distance to the luminance range [MIN_LUMINANCE, MAX_LUMINANCE]
    normalized_distance = min(avg_distance / MAX_DISTANCE, 1)
    luminance = MAX_LUMINANCE - normalized_distance * (MAX_LUMINANCE - MIN_LUMINANCE)


    # Update the luminance property of the material "C"
    material = poly1.Material(MATERIAL_NAME)
    material.SetDiffuseColor((luminance, luminance, luminance))


    # Apply the updated material to both polygons
    poly1.SetMaterial(MATERIAL_NAME, material)
    poly2.SetMaterial(MATERIAL_NAME, material)


    # Update the scene to reflect the changes
    scene.Update()


# Get the current scene
scene = poser.Scene()


# Update the luminance based on the distance between polygons and the null object
update_luminance(scene)


This script calculates the distance between the center of each polygon and a null object, then averages those distances. The average distance is mapped to a luminance value in the range [MIN_LUMINANCE, MAX_LUMINANCE] and applied to the material named "C". Finally, the script updates the scene to reflect the changes.


You might need to adjust the constants at the beginning of the script, such as the maximum distance and the material name, to match your specific scene setup.


 


 


 

Edited by user Friday, March 31, 2023 10:38:56 AM(UTC)  | Reason: Not specified

5200north  
#4 Posted : Saturday, April 1, 2023 12:05:41 AM(UTC)
5200north

Rank: Advanced Member

Joined: 3/20/2015(UTC)
Posts: 78

Thanks: 25 times
Was thanked: 14 time(s) in 11 post(s)
1. that's amazing.
2. guess what i'm going to be doing tomorrow afternoon now.
3. what other scripts have you made?
4. i agree, the creator is the human who inputs the data.
thanks 1 user thanked 5200north for this useful post.
topspin on 4/1/2023(UTC)
topspin  
#5 Posted : Saturday, April 1, 2023 3:31:45 AM(UTC)
topspin

Rank: Advanced Member

Joined: 12/7/2015(UTC)
Posts: 83

Thanks: 63 times
Was thanked: 47 time(s) in 36 post(s)

Originally Posted by: 5200north Go to Quoted Post
1. that's amazing.
2. guess what i'm going to be doing tomorrow afternoon now.
3. what other scripts have you made?
4. i agree, the creator is the human who inputs the data.


Those were the only ones so far. I've got some more Daz stuff cooking, but I need to get that on my computer and test that these scripts actually work. And I don;t have a Pose install any more, so I haven't verified that that works.


Yeah -- people really misunderstand the "AI art" thing. You _can_ be uncreative and just stick a prompt "pretty girl" into Pornpen . . . and you'll get a "pretty girl" . . . but that's kinda nothing at this point.


So I've always struggled with complex interactions between characters in 3D, I've got ideas for scenes that I'd like to see -- but it takes guys like Davo to figure out how to make those things work, and its a lot of work.


I haven't seen anyone doing Daz scripting from Chat GPT4, but there's a lot of discussion about what folks have done with Blender scripts, which have a somewhat similar architecture. In the last week, ChatGPT4 has been integrated into Blender as a plugin; I assume that that will happen with Daz real soon now.


I saw that, remembered that Daz had its own scripting language, and wondered if ChatGPT4 could do for it what it can do for Blender.


. . . appears that the answer is "yes", but its challenging.


The Daz Scripting thing has a lot of challenges -- I asked it to write a script to make a rigged chain with 100 links, but at this point Daz throws errors at me. Here's the code right now . . . but it isn't running. So i'm in debug mode and trying to remember how Daz scripting is supposed to work, because right now I'm missing something.




// create a new chain object

var chain = new Scene();



// set the number of links

var numLinks = 100;



// create the chain links

for (var i = 0; i < numLinks; i++) {

    // create a new link

    var link = new Cube();



    // set the link's size and position

    link.scale = new Vector3(1, 0.1, 0.1);

    link.translation = new Vector3(i, 0, 0);



    // add the link to the chain

    chain.addChild(link);

}



// create the chain bones

for (var i = 0; i < numLinks - 1; i++) {

    // create a new bone

    var bone = new Bone();



    // set the bone's start and end points

    bone.startPoint = new Vector3(i, 0, 0);

    bone.endPoint = new Vector3(i+1, 0, 0);



    // add the bone to the chain

    chain.addBone(bone);

}



// select the chain

chain.select();



// make the chain ready for animation

chain.makeReadyForAnimation();



. . . as I say, I think its a start, but it's a lot more than just wishing on a star to get it to work


 


 

Edited by user Saturday, April 1, 2023 3:34:13 AM(UTC)  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.593 seconds.

Notification

Icon
Error