[Bf-committers] Questions regarding adding new mesh primitive
Rodrigo Hernandez
kwizatz at aeongames.com
Wed Aug 22 18:22:30 CEST 2007
Hi Campbell,
Well, I guess I am more familiar with C than Python, so even though its
biased thats one of the reasons :),
The other is that the primitive is in fact a variation of the icosphere,
and since the icoshpere is in the C portion
of the code, I find it fitting to add it there as well.
The amount of code required is quite small due to the similarity with
the icosphere,
its not like I am bending over backwards in order to add the primitive,
and finally,
it is sort of a parametric primitive (uses the exact same parameters for
icosphere),
so its not just instancing a hard coded model.
The reason why I want to add this primitive is because its used by Paul
Steed in his
book "*Modelling* a Character in 3DS Max" for the character's head, if
Blender had the
primitive, I am sure the book can be followed using it instead of Max.
Let me know what you think, I'll add the last piece of code post the
patch soon.
I still don't know what the function on toolbox.c does, so here it is:
static TBitem *create_mesh_sublevel(ListBase *storage)
{
Link *link;
TBitem *meshmenu, *mm;
int totmenu= 10, totpymenu=0, a=0;
/* Python Menu */
BPyMenu *pym;
/* count the python menu items*/
for (pym = BPyMenuTable[PYMENU_ADDMESH]; pym; pym = pym->next,
totpymenu++) {}
if (totpymenu) totmenu += totpymenu+1; /* add 1 for the seperator */
link= MEM_callocN(sizeof(Link) + sizeof(TBitem)*(totmenu+1), "mesh
menu");
BLI_addtail(storage, link);
mm= meshmenu= (TBitem *)(link+1);
mm->icon = 0; mm->retval= a; mm->name = "Plane"; mm++; a++;
mm->icon = 0; mm->retval= a; mm->name = "Cube"; mm++; a++;
mm->icon = 0; mm->retval= a; mm->name = "Circle"; mm++; a++;
mm->icon = 0; mm->retval= a; mm->name = "UVsphere"; mm++; a++;
mm->icon = 0; mm->retval= a; mm->name = "Icosphere"; mm++; a++;
mm->icon = 0; mm->retval= a; mm->name = "Cylinder"; mm++; a++; a++;
mm->icon = 0; mm->retval= a; mm->name = "Cone"; mm++; a++;
mm->icon = 0; mm->retval= 0; mm->name = "SEPR"; mm++;
mm->icon = 0; mm->retval= a; mm->name = "Grid"; mm++; a++;
mm->icon = 0; mm->retval= a; mm->name = "Monkey"; mm++; a++;
/* a == 10 */
if (totpymenu) {
int i=0;
mm->icon = 0; mm->retval= 0; mm->name = "SEPR"; mm++;
/* note that we account for the 10 previous entries with i+4: */
for (pym = BPyMenuTable[PYMENU_ADDMESH]; pym; pym = pym->next,
i++) {
mm->icon = ICON_PYTHON;
mm->retval= i+20;
mm->name = pym->name;
mm++; a++;
}
}
/* terminate the menu */
mm->icon= -1; mm->retval= a; mm->name= ""; mm->poin=
do_info_add_meshmenu;
return meshmenu;
}
again, should I add something at all there?
Thanks!
Campbell Barton wrote:
> Hi Rodrigo,
> Is there any reason to do this in C?
> a procedural python mesh example is add_mesh_torus.py
>
> Adding static objects is a lot easier, an example.
> http://members.optusnet.com.au/cjbarton/add_mesh_teapot.py
>
> The script to write a blender mesh to a script like the teapot is
> commented in BPyAddMesh.py, it wasn't exposed because we didnt want
> people to use the add menu as their personal model library.
>
> Rodrigo Hernandez wrote:
>
>> Hello,
>>
>> My name is Rodrigo Hernandez and I am writing some code to add an
>> Octahedron primitive
>> (dubbed "octaspehere" following the icosphere convention).
>> I have already managed to add the code, however I have a couple of
>> questions before submitting a patch:
>>
>> 1- My changes are on header_info.c and editmesh_add.c, I reckon I also
>> need to add some code to
>> python\api2_2x\meshPrimitive.c in order to expose the function to Python
>> (am I right?), but I also noticed
>> that the file toolbox.c in the create_mesh_sublevel function has
>> something that looks vaguely as a primitive menu,
>> How should I modify it in order to add the new primitive? would just
>> adding the line for octasphere do?
>> My code works without any changes to this file, so I am wondering what
>> exactly does it do.
>>
>> 2 - In order not to reinvent the wheel I just made a search for the
>> string icosphere and duplicated the code, then
>> made the appropriate modifications, I noticed the static arrays icoverts
>> and icofaces.
>> I noticed that icoverts are normal vectors multiplied by 200, I use the
>> length 1 normal vectors on my octaverts,
>> it works fine, but I am wondering if I should be using the times 200
>> version instead, is this some sort of floating
>> point safeguard? the octaverts are actually coaxial, so I doubt there
>> would be any problems,
>> but I rather use the Blender standard and keep everything consistent...
>> I might have just answered my own question there.
>>
>> So, thats it for now.
>> Thanks.
>>
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>>
>>
>
>
>
More information about the Bf-committers
mailing list