Page 1 of 1

BookScatter

Posted: 14 Sep 2012, 15:18
by caledonian_tartan
Moderator edit - I've forcefully and experimentally moved this topic to our Community ICE Project subforum,
just to focus your attention at that part of the community once again - HB


Hello Community
i stumbled on this a few days ago:
http://mourelask.weebly.com/bookscatter.html

it's a max script to scatter books into a shelf.

what a nice training to do this in ice.

Already (more or less) working is this:
- create Rows and Colums of an arbitrary number of books.
- flip probability
- random scale
- align in Z
- tilt some books

i'm stuck with a few things.

1. if a book is tilted, the other ones should move to the side accordingly. (collision)

2. it should be possible to make some books stapled rather than standing

SceneFile


Image
Image

don't get scared by the messy ice tree. looks worse than it really is. the lower half of it is only WIP...
just download it and fiddle around.

i'd be happy about every input/comment.
cheers

Re: BookScatter

Posted: 14 Sep 2012, 20:21
by origin
you probably need to check previous particle orientation & scale (bounding box of mesh?) to see how much you can rotate.

just for fun, bookshelf with bullet particles ;)
bulletparticlesbookshelf.jpg

Re: BookScatter

Posted: 14 Sep 2012, 21:45
by Mathaeus
Hi there,

here's old one I already have. It performs, let's call it, one dimension packing. The trick is to create an array, take position of two neighboring members, place an appropriate particle in the middle of two. Array is created from bounding boxes sizes. This one works by carefully aligning all members "on the corner", placing centers to bounding box centers (by appropriate SI command). So, group member's global position, represent a half of bounding box. In this way, there is no need for ICE tree on each member of instance group, for calculating bounding box. Rotated ones are just "faked".

As it is noticeable, it's able to align instances of different sizes.

I've added a few comments in ICE tree.
BTW, Origin's solution looks a bit... smarter :) Anyway, take it here.

Image

Re: BookScatter

Posted: 17 Sep 2012, 11:36
by caledonian_tartan
thanks guys!
looking forward to check your scenes!
...you probably need to check previous particle orientation & scale (bounding box of mesh?) to see how much you can rotate...
that's what i do. i check the previous or the next particle depending on it's tilt angle (pos or neg). it also only checks the books group in the same part of the shelf.

simulating works, and looks quite cool, but i try to avoid to simulate.

i hope i find some time to work on this afternoon.

Re: BookScatter

Posted: 17 Sep 2012, 14:40
by origin
I was thinking about something different,
vect1 = particle[id+1].position - particle[id].position
vect2 = vect1 - book_height
angle = angle_between(vect1,vect2)

maybe also position +- book width, and book height vector rotated with particle orientation

Re: BookScatter

Posted: 17 Sep 2012, 18:57
by dwigfor
I was looking at a similar approach to that, Origin, but I think opposite. Knowing the angle of the books (some are tilted), how far would you have to push the book to the side to make room.

That could be accomplished by taking the sin of angle * book height = how far book would move to side (x). You'd also have to account for thickness of books.

The next problem would be if the book next to it was also tilted. I think you could calculate their intersection point via emTools intersecting line compound. But I didn't get that far...

Re: BookScatter

Posted: 17 Sep 2012, 20:45
by origin
semi-working ;) solution...
dunno if you can get bounding box of instanced shape in ice. If think for such things some kind of script node would be faster to setup


Re: BookScatter

Posted: 17 Sep 2012, 21:24
by Mathaeus
about getting bounding box, well there is a stupid trick I've mentioned before, just to put center on bounding box, then to place object "on the corner" to some null or so - distance is then a half of bbox. Actually this works with rotated objects too. Definitively it should be faster to calculate the bbox once for forever. Last time I've tried to get bbox, using ICE tree on each object, it worked, but SI liked to crash.

Re: BookScatter

Posted: 17 Sep 2012, 21:41
by iamVFX
origin wrote:dunno if you can get bounding box of instanced shape in ice
sure, by multiplying the bounding box size of the original object by the size and scale vector of each of the particle

Re: BookScatter

Posted: 17 Sep 2012, 22:08
by origin
yes, but it's not possible (?) to get data from .shape attribute (maybe with custom node?)
(when you try to make user-friendly compound, with only shape attribute exposed)
or when you put a group in instance shape node, you can't retrieve group id of object.
I hope I make sense with my pseudo english

Re: BookScatter

Posted: 17 Sep 2012, 22:29
by Mathaeus
origin wrote:yes, but it's not possible (?) to get data from .shape attribute (maybe with custom node?)
(when you try to make user-friendly compound, with only shape attribute exposed)
or when you put a group in instance shape node, you can't retrieve group id of object.
I hope I make sense with my pseudo english
I know you know :) that group contains array of whatever attribute exists on all members. So, if all members of group have ICE tree which calculates bbox and sets it as custom attribute, it's possible to assign this to particles in point cloud, created by same pattern. self.ID> select in array and so. But doesn't seem to be so stable, at least in my experience.

Re: BookScatter

Posted: 17 Sep 2012, 22:32
by iamVFX
origin wrote:yes, but it's not possible (?) to get data from .shape attribute (maybe with custom node?)
(when you try to make user-friendly compound, with only shape attribute exposed)
or when you put a group in instance shape node, you can't retrieve group id of object.
When you selecting a group in instance shape node you still need to provide id of the object for each of the particle. Sure, you should also provide the name of the group for a compound, it is an ice limitation, user should deal with it, because it is nesssecary for selecting the object from the group array to get bounding box information.
origin wrote:I hope I make sense with my pseudo english
Look at my messages, I make mistakes all over the place and sadly nobody even corrects me :Р
Mathaeus wrote:that group contains array of whatever attribute exists on all members. So, if all members of group have ICE tree which calculates bbox and sets it as custom attribute, it's possible to assign this to particles in point cloud, created by same pattern. self.ID> select in array and so.
Exactly. Basically when you referencing a group name in Get Data node you get an array of attributes of its objects which matches the id of particles, if the same group was selected as an instance group