示例#1
0
 def primitiveSetFromList(cls, primitiveType, vertexIndexList):
     primitiveSet = osg.DrawElementsUInt(primitiveType, len(vertexIndexList))
     arrayPointer = pointer(c_uint.from_address(int(primitiveSet.getDataPointer()))) # pylint: disable=E1101
     offset = 0
     for vertex in vertexIndexList:
         arrayPointer[offset] = vertex
         offset += 1
     return primitiveSet
示例#2
0
def createTesselatedBox(nsplit, size):
    geometry = osgAnimation.RigGeometry()
    vertices = osg.Vec3Array()
    colors = osg.Vec3Array()
    geometry.setVertexArray(vertices)
    geometry.setColorArray(colors)
    geometry.setColorBinding(osg.Geometry.BIND_PER_VERTEX)

    step = size / nsplit
    s = 0.5 / 4.0
    for i in range(nsplit):
        x = -1 + i * step
        vertices.push_back(osg.Vec3(x, s, s))
        vertices.push_back(osg.Vec3(x, -s, s))
        vertices.push_back(osg.Vec3(x, -s, -s))
        vertices.push_back(osg.Vec3(x, s, -s))
        c = osg.Vec3(0, 0, 0)
        c[i % 3] = 1
        colors.push_back(c)
        colors.push_back(c)
        colors.push_back(c)
        colors.push_back(c)

    faces = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
    for i in range(nsplit - 1):
        base = i * 4
        faces.push_back(base)
        faces.push_back(base + 1)
        faces.push_back(base + 4)
        faces.push_back(base + 1)
        faces.push_back(base + 5)
        faces.push_back(base + 4)

        faces.push_back(base + 3)
        faces.push_back(base)
        faces.push_back(base + 4)
        faces.push_back(base + 7)
        faces.push_back(base + 3)
        faces.push_back(base + 4)

        faces.push_back(base + 5)
        faces.push_back(base + 1)
        faces.push_back(base + 2)
        faces.push_back(base + 2)
        faces.push_back(base + 6)
        faces.push_back(base + 5)

        faces.push_back(base + 2)
        faces.push_back(base + 3)
        faces.push_back(base + 7)
        faces.push_back(base + 6)
        faces.push_back(base + 2)
        faces.push_back(base + 7)

    geometry.addPrimitiveSet(faces)
    geometry.setUseDisplayList(False)
    return geometry
示例#3
0
# create a root node
node = osg.Group()

# Line Geometry
lineGeode = osg.Geode()
lineGeometry = osg.Geometry()
lineGeode.addDrawable(lineGeometry)
lineStateSet = lineGeode.getOrCreateStateSet()

lineVertices = osg.Vec3Array()
lineVertices.push_back(osg.Vec3(-10, 10, 0))
lineVertices.push_back(osg.Vec3(-10, -10, 0))
lineGeometry.setVertexArray(lineVertices)

lineBase = osg.DrawElementsUInt(osg.PrimitiveSet.LINES, 0)
lineBase.push_back(0)
lineBase.push_back(1)
lineGeometry.addPrimitiveSet(lineBase)

node.addChild(lineGeode)

# Pyramid geometry, following tutorial
pyramidGeode = osg.Geode()
pyramidGeometry = osg.Geometry()
pyramidGeode.addDrawable(pyramidGeometry)
pyramidStateSet = pyramidGeode.getOrCreateStateSet()

pyramidVertices = osg.Vec3Array()
pyramidVertices.push_back(osg.Vec3(0, 0, 0))
pyramidVertices.push_back(osg.Vec3(10, 0, 0))
示例#4
0
# create a root node
node = osg.Group()

# Line Geometry
lineGeode = osg.Geode()
lineGeometry = osg.Geometry()
lineGeode.addDrawable(lineGeometry)
lineStateSet = lineGeode.getOrCreateStateSet()

lineVertices = osg.Vec3Array()
lineVertices.push_back(osg.Vec3(-10, 10, 0))
lineVertices.push_back(osg.Vec3(-10, -10, 0))
lineGeometry.setVertexArray(lineVertices)

lineBaseA = osg.DrawElementsUInt(osg.PrimitiveSet.LINES, 0)
lineBase = lineBaseA.asVector()
lineBase.push_back(0)
lineBase.push_back(1)
lineGeometry.addPrimitiveSet(lineBaseA)

node.addChild(lineGeode)

# Pyramid geometry, following tutorial
pyramidGeode = osg.Geode()
pyramidGeometry = osg.Geometry()
pyramidGeode.addDrawable(pyramidGeometry)
pyramidStateSet = pyramidGeode.getOrCreateStateSet()

pyramidVertices = osg.Vec3Array()
pyramidVertices.push_back(osg.Vec3(0, 0, 0))