[Bf-python] How to get inside faces from inside verts?
joe
joeedh at gmail.com
Fri May 22 00:09:06 CEST 2009
I'd suggest asking for help on blenderartists or
irc://irc.freenode.net/blendercoders , I'm a little too tired to give
good answers at the moment. :-/
Anyway, there should be a way of extracting the scale and rotation
part of a matrix (I believe the API has stuff for that) so I'd suggest
doing that, then creating a function that puts vertices through a
round-trip, first applying rot/scale based on the object matrix (don't
forget to zero the rot/scale fields after applying), then deapplying
it. This will ensure that you have the order of transformations
correct.
Joe
On Thu, May 21, 2009 at 3:59 PM, <lynx.abraxas at freenet.de> wrote:
> On 21/05/09 15:23:38, joe wrote:
>> What do you want? The global positions of each vertex? Or in
>> relation to the object center?
>
> I would like the ellipsoid-obj to be translated where as their rot. and scale
> should be applied to the mesh. I think I got that with:
>
> mat= B.Mathutils.Matrix([dl[6],dl[7],dl[8], 0], [dl[9],dl[10],dl[11], 0],
> [dl[12],dl[13],dl[14], 0], [0,0,0,1])#octave: v' #why is this correct???
> #mat= B.Mathutils.Matrix([dl[6],dl[9],dl[12], 0], [dl[7],dl[10],dl[13],
> 0], [dl[8],dl[11],dl[14], 0], [0,0,0,1])#octave: v
>
> local_rot(ob, mat)
> ob.setSize(dl[0], dl[1], dl[2])
> ###ob.setLocation(dl[3], dl[4], dl[5])#transl obj and the mesh
> me= ob.getData(mesh=1) #blender shows the obj. according to its matrix
> me.transform(ob.matrix)#but does not apply it on the obj verts
> ob.setMatrix(ob.matrix.identity())#set identity to avoid double effect
> ob.setLocation(dl[3], dl[4], dl[5])#transl obj only not the mesh
>
>
> In the next step I want a copy of an ellipsoid mesh which I apply the
> trnslation of the ellipsoid object on (just for pointInside). But the copy
> should not be linked to the ellipsoid object so that the mesh of the object
> stays untouched by the translation of the (copied) mesh.
>
> All types of coping I tried some how kept a link to the original object:
>
> ellmesh= ell.getData(mesh=1)
> ellmesh= bpy.data.meshes.get(ell.getData(name_only=1,mesh=1))
> ellmesh.get(ell.getData(name_only=1,mesh=1))
> ellmesh= copy.copy(ell.getData(mesh=1))
>
> Is it possible?
> Do You know how?
>
> Thanks for Your help
> Lynx
>
> To only apply the rot/scale, I believe
>> you can simply multiply (do this temporarily though, don't store the
>> result back in the mesh) with the rotation/scale matrix, which I
>> believe is something like:
>>
>> (matrix.rotationPart() * matrix.scalePart()) * vert_co
>>
>> . . .but I could be wrong, look it up in the docs. It'd help if you
>> could give a more complete description of what your trying to do.
>>
>> Joe
>>
>> On Thu, May 21, 2009 at 11:17 AM, <lynx.abraxas at freenet.de> wrote:
>> > On 20/05/09 17:33:20, joe wrote:
>> >> If applying rot/scale works, then it means your script isn't properly
>> >> taking the object matrix into account. To calculate the final
>> >> transformed position of a vertex, you have to multiply it with the
>> >> object's matrix, like so:
>> >
>> > Is this OK too?
>> >
>> > ellmesh= ell.getData(mesh=1)
>> > ellmesh.transform(ell.matrix) #apply any transform, just in case it wasn't done already
>> > ell.setMatrix(ell.matrix.identity())
>> >
>> >
>> > This sadly has the unwanted side effect that the ellipsoids have their blender
>> > centres at the global origin.
>> > Without the matrix application they have their blender centers at the centers
>> > of each ellipsoid.
>> > I created the ellipsoids by adding a UVsphere at the origin, rotating, scaling
>> > and displacing it:
>> >
>> >
>> > me= B.Mesh.Primitives.UVsphere(segments, rings, diameter)
>> >
>> > sc= B.Scene.GetCurrent() # get current scene
>> > #http://www.blender.org/documentation/246PythonDoc/Object-module.html
>> > obn= "Ellipsoid_%0.4d" % dl[15]
>> > ob= sc.objects.new(me, obn) # add a new mesh-type object to the scene
>> >
>> > #http://www.blender.org/documentation/246PythonDoc/Object.Object-class.html
>> > mat= B.Mathutils.Matrix([dl[6],dl[7],dl[8], 0], [dl[9],dl[10],dl[11], 0], [dl[12],dl[13],dl[14], 0], [0,0,0,1])
>> >
>> > local_rot(ob, mat)
>> > ob.setSize(dl[0], dl[1], dl[2])
>> > ob.setLocation(dl[3], dl[4], dl[5])
>> > me= ob.getData(mesh=1) #blender shows the obj. according to its matrix
>> > me.transform(ob.matrix)#but does not apply it on the obj verts
>> > ob.setMatrix(ob.matrix.identity())#set identity to avoid double effect
>> >
>> >
>> > Why is blender showing the ellipsoids correctly where as their verts are still
>> > the unit sphere until I apply the matrix to the mesh?
>> > Can You point me to some docs explaining this behavior?
>> > Is there a way to apply only rot and scale to the mesh but not the translation
>> > at creation time?
>> > How can I later some how translate the mesh (for pointInside to work) but
>> > leave the object as it is?
>> >
>> > Well, at least I'm slowly getting what I want;)
>> >
>> > Thanks for any help
>> > Lynx
>> > _______________________________________________
>> > Bf-python mailing list
>> > Bf-python at blender.org
>> > http://lists.blender.org/mailman/listinfo/bf-python
>> >
>> _______________________________________________
>> Bf-python mailing list
>> Bf-python at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-python
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
More information about the Bf-python
mailing list