Copy objects with bias/counting up a value
1132 5 0- EllyFish
- Member
- 11 posts
- Joined: July 2014
- Offline
I'm making a .hda for Maya and I'd like to procedurally copy a user-specified number of pieces of geometry from a set of an unknown number of objects at random, biased to the inverse of the objects' volume. For example, say the user asks for 100 copies and plugs in two objects, A and B. A has 0.3 times the volume of B. I'd like the system to return 100 objects which can each randomly be A or B, but with A being 3.3333 times as likely as B. Since the geometry is coming in from Maya, I know I can separate individual objects by name. I've gotten as far as measuring the volume of all objects together, then going through a loop of each named piece and giving its points an attribute equal to (The total volume of all objects)/(The object's individual weight), which gives all of the objects a total bias amount. Any advice on where to go from there?
Edited by EllyFish - April 24, 2018 18:17:31
- Enivob
- Member
- 2519 posts
- Joined: June 2008
- Offline
- EllyFish
- Member
- 11 posts
- Joined: July 2014
- Offline
- BabaJ
- Member
- 2024 posts
- Joined: Sept. 2015
- Offline
As I said, I won't know how many items there will be beforehand.
Then on your hda establish a user input parameter that establishes however many copies they want, and parameters for which objects the user wants to use.
And in the wrangle use those valuse to create the number of items of the desired objects.
Edited by BabaJ - April 24, 2018 21:55:14
- Enivob
- Member
- 2519 posts
- Joined: June 2008
- Offline
- EllyFish
- Member
- 11 posts
- Joined: July 2014
- Offline
Nevermind, I figured it out. I go through a list of the objects by name, and just give them an ID number, a piece_weight attribute of 0, and measure their volume. The I attribute promote the sum of their volumes to get the total volume. After that I go through a loop with feedback. I find the maximum piece_weight attribute of all objects, as well as the bias for the current object (total volume/object volume), add them together, and assign that as the piece_weight for the current object. At the end I divide all of their piece_weights by the maximum piece_weight to normalize them to a 0-1 scale, and my copy stamp node picks a random 0-1 float, and I take the object with the lowest piece_weight that is higher than that number.
-
- Quick Links