On Aug 4, 2009, at 7:55 AM, Luigi Calori wrote:

I'm unwilling to update as each time I update osg... there are some problems with swig wrapping. One of the worst issues has been the MixinVector that has broken all the vecArrays wrapping thus preventing python construction of geometry. I do not know weather Robert is aware of the hassle this mod has caused to osgswig users.


I'm still running against OSG 2.6 but was finally able to construct custom geometry via Python with code similar to the following:

def vectorArrayFromList(vectorList):
    from ctypes import *
    vectorArray = osg.Vec3Array(len(vectorList))
arrayPointer = pointer(c_float.from_address(int(vectorArray.getDataPointer())))
    vectorSize = vectorArray.getDataSize()
    offset = 0
    for vector in vectorList:
        for dim in range(3):
            arrayPointer[offset + dim] = vector[dim]
        offset += vectorSize
    return vectorArray

The vectorList argument should be a list of tuples to stick into the array, e.g. [(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)]. The trick is to take advantage of the Vec3Array constructor that takes just a length argument. You get a vector full of (0.0, 0.0, 0.0) values which you can then replace with real data via ctypes. I adapted this from Randolph Fritz's post to osg-users (<http://www.mail-archive.com/[email protected]/msg23368.html >).

You can do the same thing for primitive sets:

def primitiveSetFromList(primitiveType, vertexIndexList):
    from ctypes import *
primitiveSet = osg.DrawElementsUInt(primitiveType, len(vertexIndexList)) arrayPointer = pointer(c_uint.from_address(int(primitiveSet.getDataPointer())))
    offset = 0
    for vertex in vertexIndexList:
        arrayPointer[offset] = vertex
        offset += 1
    return primitiveSet

I haven't done massive testing but it's working fine so far on both Mac OS X and Win XP…

-Frank

------------------------------------
Frank Midgley
HHMI JFRC - Scientific Computing
[email protected]
(571) 209-4629
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to