|
|||||||
![]() |
|
|
Thread Tools |
|
||||
|
This is a rather long post. Because I connot access my own webserver yet want to share to code I will include the full code in the next post in this thread (otherwise I'll exceed 10k characters)
What was needed to port it from 2.49 -> 2.50 alpha 0? The basic functions that calculate the geometry (verts and faces) are unchanged ( add_tooth(), add_spoke2(), add_gear() ) These functions were designed to return lists of tuples (x,y,z) (for the vertices) and lists of lists [i,k,l,m] (for the faces). Because the Blender 2.50 API does not provide facilties to alter individual elements of the the verts and faces attributes of a mesh directly we have to add the calculated vertices and faces in bulk by using the mesh.add_geometry(nverts,nedges,nfaces) methodfolowed by mesh.verts.foreach_set("co", verts_loc) and mesh.faces.foreach_set("verts_raw", faces). Both the foreach_set() methods take flattened lists as arguments, not lists of tuples, so we added a simple function to flatten a list of lists or tuples. Also, the vertex group API is changed a little bit but the concepts are the same: Code:
Code:
Just definining the appropriate properties in the AddGear() operator will display the properties in the Blender GUI with the added benefit of making it interactive: changing a property will redo the AddGear() operator providing the user with instant feedback. FInally we had to convert/throw away some print statements to print functions as Blender nows uses Python 3.x The most puzzling issue was that the built in Python zip() function changed its behavior. In 3.x it returns a zip object (that can be iterated over) instead of a list of tuples. This meant we could no longer use deepcopy(zip(...)) but had to convert the zip object to a list of tuples first. The code to actually implement the AddGear() function is mostly copied from add_mesh_torus() (distributed with Blender). Unresolved issues: - removing doubles: the code that produces the teeth of the gears produces some duplicate vertices. The original script just called remove_doubles() but if we do that in 2.50 we have a problem. To apply the bpy.ops.mesh.remove_doubles() operator we have to change to edit mode. The moment we do that we loose to possibilty to interactively change the properties. Also changing back to object mode raises a strange exception (to investigate). So for now, removing doubles is left to the user once satisfied with the chosen setting for a gear, - no suitable icon: a rather minor point but I reused the torus icon for the add->mesh->gear menu entry as there doesn't seem to be a generic mesh icon or a way to add custom icons. Too bad, but as this is just eye candy it's no big deal.
............................................
My Blender Scrpting book https://www.packtpub.com/blender-2-4...ign=mdb_003338 current work on Pynodes http://www.swineworld.org/blender/pynodes.shtml current work on Network Rendering http://www.swineworld.org/blender/networkrender Other Blender stuff (gears/cogwheels, tips and tricks) http://www.swineworld.org/blender |
||||
|
#1
|
||||
|
|
|
||||
|
the code:
Code:
Code:
Code:
Code:
Code:
............................................
My Blender Scrpting book https://www.packtpub.com/blender-2-4...ign=mdb_003338 current work on Pynodes http://www.swineworld.org/blender/pynodes.shtml current work on Network Rendering http://www.swineworld.org/blender/networkrender Other Blender stuff (gears/cogwheels, tips and tricks) http://www.swineworld.org/blender |
||||
|
#2
|
|
||||
|
there seems to be 4 scripts here
how do we organise this is it all put into the same script file and run it and where will this new panel appears in tool sidebar may be ? do you think with the addition of Bmesh it will change the script again ? Thanks |
||||
|
#3
|
|
|||
|
ok, working with replaced upper case I to i at "for I in range" in second block. and it's nice gear.
ps. it's pity that tweaking parameters is possible just at adding(as i wrote it already in another post)
............................................
http://eggnot.com/ |
|||
|
#4
|
|
|||
|
Sweet! Beautiful script, easy to use, fast, I love it! Very handy for making quick gears. I'll have to study the code more closely to see what's going on under the hood.
You may want to fix the loops in "def add_tooth...", the mix of lowercase and capitilized "i" doesn't make blender happy on my end. Once that was changed it worked fine. Oh, and there are some issues with the normals of the final object. The lower surface is facing out, but all the other faces are pointed inward. Other than that it looks perfect! |
|||
|
#5
|
|
|||
|
When porting a few of my scripts to 2.50 I noticed this as well. Just add the vertices of the face (i.e. when you call faces.extend) in counter-clockwise order and the normals will point outward.
|
|||
|
#6
|
|
||||
|
Why don't you use pasteall.org? This forum is notorious for mangling code that you get out of a code box. Post it on shareCG, anywhere...
I don't understand why this forum does not allow attachments...? Dang, no scriptlinks? What a loss....
............................................
Windows XP 64, 3Gb RAM, nVidia 9500M GS Blender 2.49.2, Python 2.64 2.49b Scripts: Blendgraph Meshfoot Cubic Transition APE 2.49b Scenes: After Effects Stroke Sea Tubes Page Rip or Tear Opening A Book Single Page Turn 3DSMax Super Spray Last edited by Atom; 30-Nov-09 at 14:02. |
||||
|
#7
|
|
||||
|
@dudecon & @atom:
I put the script on my website:http://www.swineworld.org/blender/gears/ (navigation to your right for download or direct link: http://www.swineworld.org/blender/ge...d_mesh_gear.py , just plonk it into the .blender/scripts/op/ directory) Concerning those normals: I will try the clockwise trick. In the 2.49 version I just did a recalc_normals() but just like removing doubles that can only be done in edit mode and edit mode destroys the redo options of the tools window so that clearly not the way to go. I'll have to check the source code of those operators to see if there is some way around this.
............................................
My Blender Scrpting book https://www.packtpub.com/blender-2-4...ign=mdb_003338 current work on Pynodes http://www.swineworld.org/blender/pynodes.shtml current work on Network Rendering http://www.swineworld.org/blender/networkrender Other Blender stuff (gears/cogwheels, tips and tricks) http://www.swineworld.org/blender Last edited by varkenvarken; 30-Nov-09 at 19:28. Reason: install instructions |
||||
|
#8
|
|
||||
|
well done !
do you think it could be possible to call the dedicated gui panel again, when one clic again on a parametric-made object like your gears ? an object tag defined by the user/script, linked to parametric values somewhere in the registry and to the add_xx script.. mmm well. it would need a dedicated object class property for that I suppose.. and also to check if the object is still eligible for parametric config.
|
||||
|
#9
|
|
||||
|
The script works great, taking 2.5 limitations into account. The only strange thing I encountered was when you set the Number of Teeth to 4 (all other parameters at default).
About a suitable icon: how about using ICON_SCRIPTWIN? It looks like a gear to me. |
||||
|
#10
|
|
||||
|
So how do I activate the script? I have placed it here .blender/scripts/op/
I just realized that the scripts window no longer exists in Blender 2.5. How do I activate it?
............................................
Windows XP 64, 3Gb RAM, nVidia 9500M GS Blender 2.49.2, Python 2.64 2.49b Scripts: Blendgraph Meshfoot Cubic Transition APE 2.49b Scenes: After Effects Stroke Sea Tubes Page Rip or Tear Opening A Book Single Page Turn 3DSMax Super Spray |
||||
|
#11
|
|
|||
|
Quick note, as of at least revision 25295 This script no longer works. In fact it also breaks the add->Torus feature. I think someone changed a command in the API making this script out of date. However I love it when it works.
EDIT: Ok slight correction. The script works but it just prevents both it and add Torus from showing up in the Add->Mesh menu. EDIT2: Fix found. O line 359 replace icon='ICON_MESH_DONUT' with icon='MESH_DONUT'. Credit goes to Theeth. Last edited by DProber; 10-Dec-09 at 21:32. |
|||
|
#12
|
|
||||
|
Wow, again nice for me. Good work! And an example how to do it ...
In Blender 2.5 alpha 0 trying to set the number teeth to 1 (one) it needs some time, but works. (first I thought it doesn't) Last edited by PKHG; 11-Dec-09 at 10:13. Reason: problem with teeth 1 no, needs time! |
||||
|
#13
|
|
||||
|
hey varkenvarken, would you be interested in including this script for 2.5 alpha-1 ?
Ill try have remove doubles working by having a way to run an operator without registering or undo'ing.
............................................
BPython Cookbook * How to get features into Blender * Code Metrics Hire Me ideasman42<at>gmail.com |
||||
|
#14
|
|
||||
|
Quote:
Sorry for my late reply but sure, I'd love to. Just tell me what you need.
............................................
My Blender Scrpting book https://www.packtpub.com/blender-2-4...ign=mdb_003338 current work on Pynodes http://www.swineworld.org/blender/pynodes.shtml current work on Network Rendering http://www.swineworld.org/blender/networkrender Other Blender stuff (gears/cogwheels, tips and tricks) http://www.swineworld.org/blender |
||||
|
#15
|
|
||||
|
this script seems not to be working in current svn.
is any chance of updating it?
............................................
Meta's Material Library's . My Site get python scripts> http://wiki.blender.org/index.php/Extensions:Py/Scripts External Script Bundle Blender 2.49a Packed Collections . Scripts_Bundles blender-2.49b |
||||
|
#16
|
|
||||
|
Quote:
Only I forgot to replace the script on my website. The one mentioned now for 2.50 is tested against svn 26208. (it fixed the return values and the way a menu os registered). Let me know if you find any difficulties still and I'll try to fix it.
............................................
My Blender Scrpting book https://www.packtpub.com/blender-2-4...ign=mdb_003338 current work on Pynodes http://www.swineworld.org/blender/pynodes.shtml current work on Network Rendering http://www.swineworld.org/blender/networkrender Other Blender stuff (gears/cogwheels, tips and tricks) http://www.swineworld.org/blender |
||||
|
#17
|
|
||||
|
thanks, it works now.
............................................
Meta's Material Library's . My Site get python scripts> http://wiki.blender.org/index.php/Extensions:Py/Scripts External Script Bundle Blender 2.49a Packed Collections . Scripts_Bundles blender-2.49b |
||||
|
#18
|
|
|||
|
How to increase the diameter without change the teeth size?? These is a necessary thing to make that gears ruining together.
|
|||
|
#19
|
|
||||
|
Hi Varkenvarken
I noticed that you needed a Remove Doubles function for your Gears script. I needed the same thing for my “Bolt Factory”. With help from Guillaum I have a function that will do what you need. I hope it helps. Code:
|
||||
|
#20
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|