Forum: Poser Python Scripting


Subject: remove a slice from bottom of a prop..??

dennisharoldsen opened this issue on Apr 08, 2008 · 32 posts


dennisharoldsen posted Tue, 08 April 2008 at 8:11 AM

i have some plant props that i wish to remove a slice from the bottom so that they will be flat along the bottom.

is this possible in poser? i have looked at code that examines the polygons and vertices and peeked inside an obj file but it seems pretty mysterious to me.

if the polygons or vertices can't be removed, maybe they can be relocated or something.

i would like to do it as a batch process but i would also like to understand what is possible using the tools within poser.
 


markschum posted Tue, 08 April 2008 at 10:21 AM

You can make a transparency map , and try to hide them . Or you can use magnets , and attempt to deform them flat. Deforming them is going to leave an ugly surface .    You can use the group editor , and make a new group for those bits , and then make that group transparent . Group editor may actually be the easiest way , work in front or side view wireframe and one select with the selection box should get it .

The best solution is to bring them into  a modelling program and clean up the model.

? why do you need them flat ?   you can just poke the bottom edge through the ground as long as its not going to be seen.


dennisharoldsen posted Tue, 08 April 2008 at 4:14 PM

hi markschum. thanks for your interest.

why do i want to do this? i am working on a graphics program for kids called collage. i am using poser to create a clip art library. i use the ground as a shadow catcher only and i don't really build any scenes as such in poser.

i have no documentation except for some basic preliminary pages that show a small portion of what collage can do. the link to it is: http://www.bestlogic.com/collage/default.asp. the pages only work on ie. there are tool tips for the commands for the image toolbar but that and the dialogue are the only documentation.

collage creates a composite of individual images that are moveable. various characteristics such as rotation and size can be changed. what i have shown is just a small peek at the full system. i achieve the illusion of rotation by rendering each base image in 14 rotations.

as you can see from the sample, each collage can be used on web pages or processed into a single jpeg image. the image library is online or can run from a local computer. each collage is described by a small text file and constructed dynamically so that those who share the same library could transmit a small file instead of a full image. i am providing a library but local images can be used and a link to an image on a webpage will display it in collage without even having a local copy.

i am processing a large amount of content and making lots or renders, so i can't afford the effort it takes to do each piece manually. there are other things i want to do that would use the same process but in the example i mentioned, i have about 50 props that need to be processed this way in order to be really usable. currently, i have more than more than 2000 base images and most get rendered in 54 variations.

i was looking at the syntax for moving vertices and perhaps i can move the ones i don't want up to the level where i want to have a visible object. i have hexagon and it appears to be able to do what i want but not in an automated way. i would like to do something like i have described but it is not essential. there is a vast amount of available content.

another possible use would require splitting a prop in two. since i am working in 2d, i have no way to create for example, fish in a fish bowl. all images in collage have a z-order. if i split the fish bowl, i can place half of it first, then the fish and then the front. i am not sure if i am making sense. i have been proceeding to the final product and thinking that seeing it in action will be obvious. when kids see me do it, they catch on right away so i am planning to use screen capture videos for documentation.
 


PhilC posted Tue, 08 April 2008 at 4:29 PM

It is possible that the process could be scripted.

Work flow:-

For each polygon in the model.
Does polygon intersect the ground? If so move lower verts to y = zero.
Is polygon below the ground? If so assign to a discard group/material.
Perform some Poser Python sleight of hand to effectively delete the unwanted portion.

The Scissors script will do it. I guess with some manipulation that could be adapted to batch process.


dennisharoldsen posted Tue, 08 April 2008 at 4:52 PM

philc: hi, thanks for your input. that it is possible is a good start.

you have provided some ideas as where one might begin. even better.

i downloaded your poserpython reference. i was up all night, so i didn't get a chance to view it in depth but it looks really great. the idea for moving the vertices came from what i saw.

i am thinking that another possibility is operating directly on the .obj file. maybe someone who understands the file structure will show up and enlighten us.
 


PhilC posted Tue, 08 April 2008 at 5:18 PM

The OBJ file format is reasonably well documented. The best info I've found on it is at http://www.royriggs.com/obj.html 

It is possible to use Poser Python to write OBJ files from scratch. A number of my scripts do this when the standard OBJ export options do not give sufficient control.


PhilC posted Tue, 08 April 2008 at 5:29 PM

The sample scripts that come with Poser will help. See:-

Poser 7RuntimePythonposerScriptsCreatePropsgeom_genmesh.py

Or at least that was my starting point.


EnglishBob posted Wed, 09 April 2008 at 3:11 AM

It may be worth asking in the Blender forum. Blender has Python scripting; I know nothing about its capabilities, but since Blender is a modeller one might expect it to be able to do more.


Cage posted Wed, 09 April 2008 at 1:48 PM

This will flatten the bottom of a prop.  It will actually change the vertex positions in the prop geometry, and won't compensate for any world transforms in the prop, so the prop's transforms should all be zeroed when you run.

To define where the "bottom" should be, load one of the square props into the scene and rotate it so it's parallel with the GROUND plane.  Then move it on Y until it lies where you want the flattening to occur.  Rename this prop "SQUARE" (without the quotes), so the script will recognize it as your flattening square.  The script will error out if there is no actor named SQUARE in your scene.

Then select the actor to flatten, and run the script.

You could use the GROUND as the SQUARE actor, if you simply rename it before running.  You could really also use any appropriately named actor as SQUARE.  The script will look for the highest Y coordinate in the SQUARE geometry, to define the flattening plane (it assumes you have an axially-aligned actor with a plane flattened along the appropriate axis, but this is not at all necessary).  You could use a box or a sphere or a figure's foot as the SQUARE, if you name it appropriately.

Remember that this will actually alter the geometry of your selected actor!  Back up your scene if necessary before running.

A script to actually clip the geometry at the plane would be more complex.  This process can still give slightly jagged edges, along the edge of the flattened area.  Removing the verts might or might not give nicer results....

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Thu, 10 April 2008 at 7:54 AM

EnglishBob: thanks for the suggestion.


dennisharoldsen posted Thu, 10 April 2008 at 7:55 AM

Cage: your script accomplished what i needed to do. thanks.

i would be interested in what would be involved in deleting the vertices. i am not asking for a script but would like to get a better understanding.


Cage posted Thu, 10 April 2008 at 12:49 PM

To delete the vertices, you'd have to spawn a new geometry in PoserPython, which can be a bit complex, if you want to retain the UV and materials data.  You'd have to identify the parts you don't want and leave those out of the new geometry.  Then you'd have to build the new prop using the PPy geometry handling API, using specially formatted Numeric arrays.  It might or might not be easier to work directly with the OBJ file, presumably outside of Poser.

The next easiest approach after flattening the base would be to assign a new transparent material to the unwanted portions, I think.  That would involve identifying the polygons you don't want and assigning them to a new material which is set up as transparent.

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Thu, 10 April 2008 at 1:29 PM

Cage:
sounds pretty difficult to me.
you've solved my immediate problem. thanks.


Cage posted Thu, 10 April 2008 at 2:34 PM

I tacked this together from functions I had lying around from the TDMT project.  It basically shows what needs to be done to create a new Geometry which isn't linked to the original in any way.  This script will create a triangulated copy of the currently selected actor.  There are probably cleaner ways to approach this, and I can't claim that it represents good coding practice....

If you have Poser 7, Spanki's _tdmt.pyd could perhaps be used to simplify some of the code, although the basic process would have to be similar....

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Thu, 10 April 2008 at 5:47 PM

Cage:

ok. i tried it and it works and i can apply the materials to it. cool. the code looks pretty clear to me although the subject matter is new.

i understand little of this or where it's going. if i transfer only the vertices i want to retain, does that then create a new geometry that works and if so are the groups retained? am i getting the gist of this at all?

my purpose would be what i mentioned above, for example to create a fishbowl in 2 parts so that they could be positioned around the fish (in the 2d rendered versions).
 


Cage posted Thu, 10 April 2008 at 8:09 PM

To create a trimmed prop using the approach in my example... might not be as easy as it could be.  I've tinkered a bit with the idea since posting the above, and I haven't yet come up with a relatively simple way to work in the screening.  All of the Numeric arrays used to create the new prop will have to be screened, not just the vertices.  The polygons and sets and texvertices and texpolygons and texsets and materials lists all need to be screened, too.  My approach doesn't really offer a straightforward way to do that.  It can be done, it will just have to be a more complex process than it necessarily needs to be, because of the framework I used.

Right now I'm wondering about using the CreateGeomFromGroup option.  A pose can be used to insert a group into a prop, then the script can fill the group with the appropriate polygons.  Spawning a trimmed group that way might be a simpler approach.

On the other hand, the reason I create the geometry from scratch in the example I posted is that PoserPython creates some problems when geometries are copied using a script.  If you build a prop using the geometry of an existing prop, then delete the original prop, Poser (7, at least) may crash, in my experience.  So possibly a combination of the group approach and the fresh copy approach might work.  Create an internal geometry from the group, then make a fresh copy of it using the method in my posted script, then build the prop from that.

Anyway, I'm curious about the idea, so I'm going to fiddle about.

Can you explain the fishbowl in two parts?  I assume that's split vertically somehow?  Hmm.  I'm having trouble visualizing what you want, there....

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


Cage posted Thu, 10 April 2008 at 9:24 PM

I didn't answer all of your questions.  Sorry.  PoserPython can't create a group, so no, the groups wouldn't be retained, using the earlier approach.  They could be inserted back in afterwards, using a geometry insertion pose (which would basically have to contain the whole formatted OBJ).

The approach in the attached script might be altogether more promising.  This will trim a prop, once again using the SQUARE as the bottom definition.  The prop to be trimmed must, in this case, have an empty group named "NewGroup" (without quotes) added using the grouping tool, before the run.  The script fills that group and spawns a new trimmed prop from it.

As noted above, a pose can be used to insert new geometry, and hence new groups.  I'm going to see if I can work out a simple extension of the attached script which creates such a pose for the NewGroup, so the grouping tool doesn't need to be included.

But it looks like that will have to happen tomorrow.  I can hear a thunderstorm approaching, which means I'll be off the computer until it's over....

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Thu, 10 April 2008 at 11:01 PM

Cage:

i appreciate all your efforts. my real problem that started the thread was that i had some content with oak trees sitting in a mound of earth with roots hanging down. since i am making clipart, i couldn't use the trees. flattening the bottom took care of that. that is my real practical use. you have saved 28 oak trees. there are other instances where this will come in handy, i'm sure.

the idea of splitting the prop is a fantasy that occurred along the way. it may or may not be useful. considering the difficulty, i don't think it's worth your time unless it's a problem you just have to solve. if you do, i will certainly put it to good use if i can.  

i appreciate the conversation and looking at your code because it gives me a little more insight into the innerworkings. however, my mission is creating clipart and not making poser masterpieces or content.

i put some details about my 2d system in my second post above and a link to a partial sample (http://www.bestlogic.com/collage/default.asp). i have explained most everything on the pages but those who have seen them don't seem to get it. all the images can be moved, rotated, resized, cloned and other things.

i have not done any documentation because i am still working on the content library and when that is done, i will make a better UI. i am not an artist. i am trying to use some of the quality of poser in the clipart and it doesn't have to be perfect because the target audience is kids. however, when i get my render factors and lighting down, the quality will be pretty good. some of the collage pictures look as good as some of the uploads i've seen on rendo and since everything is done post-poser, i can have as many objects as i want in a scene.

since i am using 2d objects, everything has a unique z-order. with the fish example, i can put fish in front of a bowl or behind it but not in it. if i have a fish bowl in 2 parts, i can put the fish between them and it will appear inside. i could make fish bowls with fish inside, but it would seem better to me for the kids to make their own combinations if possible.

i have seen lots of your posts and am happy to be having a conversation. i just got your message that you were going into a thunderstorm. i live on bainbridge island, across from seattle. we don't have real lightning here. i lived in cincinnati for a while and after losing data and some equipment, i ended up putting everything on ups. instead, we have rain and clouds and no sun.
 


Cage posted Fri, 11 April 2008 at 12:33 AM

Ah, well... if I'm taking the thread off-topic, um, my apologies.  I become a bit enthused about a new problem, and I do have a bad habit of sort of taking over a thread.  I think I may have misunderstood your overall goal, in my perhaps narrow focus on certain scripting problems.  Hmm.  At any rate, you've given me a few things to think about.  :D

In terms of the splitting of props, I've just glanced at the link PhilC provided, and his tool looks like it probably delivers already on that idea.

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Fri, 11 April 2008 at 1:48 AM

Cage:

i didn't feel that you were taking the thread off topic at all. i was starting to feel a little guilty about taking up your time when i am not certain how i would implement my idea in my software. i would like to know about what you have in mind and would like to get to know you better. it is unclear whether philc has any better idea than you do. he doesn't have a batch solution.

once i get my system to beta, i will have more time to get into the technical aspects of poser. i want to get it to market and generate some income and get some artist types to deal with creating content that works so it doesn't have to be fixed. i find the technical to be the most interesting but now there is only me and my computers to create the first library.

if you feel like you are arriving at something interesting, then please go on and include me in. i am always up for exploring new things. i really appreciate the interest you have shown and help you have extended to me and to others.
 

 


dennisharoldsen posted Fri, 11 April 2008 at 5:00 AM

Cage: what can i say? if you can figure a way to add a group, it will complete the miracle. i don't understand much of this but it's pretty fun. Why is it all black inside of v4? Doesn't she have any internal organs?

EnglishBob posted Fri, 11 April 2008 at 5:16 AM

Quote - Why is it all black inside of v4? Doesn't she have any internal organs?

She doesn't have a brain either. :) "Outside V4, a book is man's best friend. Inside V4, it's too dark to read." - with apologies to Groucho Marx


Cage posted Fri, 11 April 2008 at 2:55 PM

I couldn't stop tinkering.  It looks like the group insertion pose works, in the attached.

Boy, I love geom insertion poses.

V4 is darker on the inside... but is she bigger on the inside?  (Sorry, obscure Doctor Who reference - not an intended vulgarity).

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


Cage posted Fri, 11 April 2008 at 3:24 PM

Typically with my work, that version had a few bugs.  This should fix them....

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


Cage posted Fri, 11 April 2008 at 5:39 PM

Sigh.  I'm spamming the thread.  Sorry.  Incorrect use of Name() in the pose creation, rather than InternalName()....

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Fri, 11 April 2008 at 6:22 PM

Cage: well you did it, adding a new group with poserpython. congratulations! it is supposed to be impossible.

i have been playing with your new script and thought you might like some feedback.

the image i sent shows james lores. it seems that the new prop is slightly rotated.

the new version that adds a group is very slow compared to the last version. i tried it first with the v42 object and i aborted poser because it seemed like it wouldn't finish. i then chose a more simple prop and it did complete but was much slower.

i really don't know enough to ask an intelligent question but i was wondering... i see your posts about moving morphs between characters... perhaps it might be possible to have an extra prop with the extra group already added and transfer the information to it. i am not sure where the extra time is being spent but the processing time takes much much longer.

this has been interesting and fun and i am beginning to get some insights into how this all works. from the documentation, i just get a blank.
 


Cage posted Fri, 11 April 2008 at 9:47 PM

Well... that last one had some bugs, too.  They're fixed, in this new attachment.

There shouldn't be any rotation in the spawned prop, relative to the base geometry for the original from which it was spawned.  CreateGeomFromGroup seems to only spawn a geometry without transforms or deformations.  So if the object from which you spawn the trimmed prop doesn't have zeroed transforms, you should see some difference in position between it and the new trimmed prop.

I've done some testing.  this doesn't work so well with body parts.  Best to use props.  I also can't seem to use the geom insertion trick to restore the original geometry to the prop on which we've acted - which means the process does embed a new geomCustom reference in your actor, so you should back up before running this, or be prepared to edit the .pp2 or .cr2 to correct things later, if you want to backtrack.

Deformations could be transferred over, but because this uses an internal PoerPython trick with the CreateGeomFromProp, it's difficult to calculate any vertex correlations before the run of the script.  I suppose it could be done, possibly, by trying to correlate the groups, but I assume indexing may get muddled.  I need to look at how that works out.  So the meshes would have to be correlated in some way after the trim.  TDMT could handily correlate the meshes and transfer any morph deformations, but I haven't tried that at all yet....

I'm glad this is helping you, then.  Don't pick up my poor coding habits from my scripts, however.  LOL  I'm sloppy and I don't adhere to good coding practice, as I understand it.  I like to throw around Very Big Arrays, which isn't supposed to be the best approach.

I'm a bit confused about your question concerning the extra processing time.  At what point in the process?

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


Cage posted Fri, 11 April 2008 at 11:12 PM

Okay, I skimmed your post before - I'm on dialup and often racing to post before I'm kicked offline unexpectedly - and now I see what you meant by a slowdown.

I did some timing tests, and the slow part of the process is this line:

scene.LoadLibraryPose(path)

Unfortunately, there's no way to optimize that part of the script.  So this exposes a limitation of using geometry insertion poses this way, at least with large geometries.  When I developed the poses, I was using them to swap out single body parts, as an alternative to geom-swapping dials, which I've never found agreeable.  The process of inserting a geometry via a pose is really a hack, not supported formally by Poser, and it's trying to chew on a lot when applying one which uses a large geometry, so it's really not surprising that it slows down a great deal.

The process can be sped up for runs in which the necessary group already exists by adding a condition in the run() function.

if not "SpecialAddGroup" in prop.Geometry().Groups(): # All of this inserts a group - and is potentially slow.
        tempfig = 0
        if len(scene.Figures()) == 0: # No figures in scene, so load our blank proxy .cr2
            proxy = make_proxy()
            tempfig = 1   
        filename = export_obj(prop,1)
        savePose(prop,filename)
        if tempfig:
            scene.DeleteCurrentFigure() # Remove the proxy

There are certainly better approaches to adding a group.  The script could read back the .obj it saves, importing it directly using the imexporter options.  That wouldn't be hard to do.

I need to move back to handling TDMT now, however.  LOL  I've been avoiding a problem there which I haven't been able to solve....  This latest addition to this script was kind of a proof-of-concept for the possibilities of geom insertion poses.  This approach allows groups to be added to the geometry and it allows original groups to be retained in the spawned prop, but there are definite limitations, the slowdown being perhaps the foremost....

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Sat, 12 April 2008 at 2:02 AM

Cage:

when i got your post, i was inserting timers in your script and had determined that 'savePose()' was taking 120 seconds and the rest only 1 second.

i didn't know you were on dialup. wow. my new library is going to be over 5GB and i have to load it to the website. it takes a long time even on dsl since it is composed of lots of small files.


Cage posted Sat, 12 April 2008 at 1:40 PM

Correct.  The savePose() function also reads the pose back.  This is the script I'm using for timing.

===========================sigline======================================================

Cage can be an opinionated jerk who posts without thinking.  He apologizes for this.  He's honestly not trying to be a turkeyhead.

Cage had some freebies, compatible with Poser 11 and below.  His Python scripts were saved at archive.org, along with the rest of the Morphography site, where they were hosted.


dennisharoldsen posted Sat, 12 April 2008 at 3:12 PM

Cage: i checked out your latest. for my purposes, the speed is fine. i just put it on one of my rendering computers and come back later.

about your coding style. i think it is great. what if you use large arrays. so what? we have lot's of resources and we should use them.

i have worked as a programmer for many years using different os's and languages and seen many different programming standards. what you do seems clear and you document it.

when developing prototypes, i always use my naming conventions, i try to be clear so i will know what i did for later. first thing is that 'it must work' and then i try to make it fast. making it understandable to the world is not necessary.

i am sending a private message on site mail.


dennisharoldsen posted Tue, 15 April 2008 at 1:44 PM

cage: i have been playing with the new tool you made....
http://www.renderosity.com/mod/forumpro/showthread.php?thread_id=2737057