Esempio n. 1
0
def createPyramid():
    pyramidGeode = osg.Geode()
    pyramidGeometry = osg.Geometry()
    pyramidGeode.addDrawable(pyramidGeometry)

    # Specify the vertices:
    pyramidVertices = osg.Vec3Array()
    pyramidVertices.append(osg.Vec3(0, 0, 0))  # front left
    pyramidVertices.append(osg.Vec3(2, 0, 0))  # front right
    pyramidVertices.append(osg.Vec3(2, 2, 0))  # back right
    pyramidVertices.append(osg.Vec3(0, 2, 0))  # back left
    pyramidVertices.append(osg.Vec3(1, 1, 2))  # peak

    # Associate this set of vertices with the geometry associated with the
    # geode we added to the scene.
    pyramidGeometry.setVertexArray(pyramidVertices)

    # Create a QUAD primitive for the base by specifying the
    # vertices from our vertex list that make up this QUAD:
    pyramidBase = osg.DrawElementsUInt(osg.PrimitiveSet.QUADS, 0)
    pyramidBase.append(3)
    pyramidBase.append(2)
    pyramidBase.append(1)
    pyramidBase.append(0)

    # Add this primitive to the geometry:
    # pyramidGeometry.addPrimitiveSet(pyramidBase)
    # code to create other faces goes here!
    pyramidGeometry.addPrimitiveSet(pyramidBase)
    # Repeat the same for each of the four sides. Again, vertices are specified in counter-clockwise order.
    pyramidFaceOne = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
    pyramidFaceOne.append(0)
    pyramidFaceOne.append(1)
    pyramidFaceOne.append(4)
    pyramidGeometry.addPrimitiveSet(pyramidFaceOne)

    pyramidFaceTwo = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
    pyramidFaceTwo.append(1)
    pyramidFaceTwo.append(2)
    pyramidFaceTwo.append(4)
    pyramidGeometry.addPrimitiveSet(pyramidFaceTwo)

    pyramidFaceThree = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
    pyramidFaceThree.append(2)
    pyramidFaceThree.append(3)
    pyramidFaceThree.append(4)
    pyramidGeometry.addPrimitiveSet(pyramidFaceThree)

    pyramidFaceFour = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
    pyramidFaceFour.append(3)
    pyramidFaceFour.append(0)
    pyramidFaceFour.append(4)
    pyramidGeometry.addPrimitiveSet(pyramidFaceFour)

    colors = osg.Vec4Array()
    colors.append(osg.Vec4(1.0, 0.0, 0.0, 1.0))  #index 0 red
    colors.append(osg.Vec4(0.0, 1.0, 0.0, 1.0))  #index 1 green
    colors.append(osg.Vec4(0.0, 0.0, 1.0, 1.0))  #index 2 blue
    colors.append(osg.Vec4(1.0, 1.0, 1.0, 1.0))  #index 3 white
    colors.append(osg.Vec4(1.0, 0.0, 0.0, 1.0))  #index 4 red

    pyramidGeometry.setColorArray(colors)
    pyramidGeometry.setColorBinding(osg.Geometry.BIND_PER_VERTEX)

    # Since the mapping from vertices to texture coordinates is 1:1,
    # we don't need to use an index array to map vertices to texture
    # coordinates. We can do it directly with the 'setTexCoordArray'
    # method of the Geometry class.
    # This method takes a variable that is an array of two dimensional
    # vectors (osg.Vec2). This variable needs to have the same
    # number of elements as our Geometry has vertices. Each array element
    # defines the texture coordinate for the cooresponding vertex in the
    # vertex array.
    texcoords = osg.Vec2Array(5)
    texcoords[0].set(0.00, 0.0)  # tex coord for vertex 0
    texcoords[1].set(0.25, 0.0)  # tex coord for vertex 1
    texcoords[2].set(0.50, 0.0)  # ""
    texcoords[3].set(0.75, 0.0)  # ""
    texcoords[4].set(0.50, 1.0)  # ""
    pyramidGeometry.setTexCoordArray(0, texcoords)

    return pyramidGeode
Esempio n. 2
0
            xypositions.push_back(osg.Vec2(1.0-0.5/(O*K),((float)y+0.5)/(O*N)))
    xypositions.setBinding(osg.Array.BIND_PER_VERTEX)
    xypositions.setNormalize(False)

    meshGeom.setVertexAttribArray(6, xypositions)
    meshGeom.setVertexArray(vertices)

    # generate several tri strips to form a mesh
    indices = GLuint[4*O*K]()
    for (unsigned int y=0 y < O*N-1 y++) 
        if y % 2 == 0 :
            base = (y/2) * (O*K+O*K+1)
            base2 = (y/2) * (O*K+O*K+1) + O*K
            i = 0 for (unsigned int x=0 x < O*K x++)  indices[i++] = base2+x indices[i++] = base+x
            indices[i++] = base2+O*K
            meshGeom.addPrimitiveSet(osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLE_STRIP, i, indices))
        else:
            base = (y/2) * (O*K+O*K+1) + O*K
            base2 = (y/2) * (O*K+O*K+1) + O*K + O*K+1
            i = 0 for (unsigned int x=0 x < O*K x++)  indices[i++] = base+x indices[i++] = base2+x
            indices[i++] = base+O*K
            meshGeom.addPrimitiveSet(osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLE_STRIP, i, indices))
    delete[] indices

    # create vertex and fragment shader
    program = osg.Program()
    program.setName( "mesh" )
    program.addBindAttribLocation("xypos", 6)
    program.addShader( osg.Shader( osg.Shader.VERTEX, VertexShader ) )
    program.addShader( osg.Shader( osg.Shader.FRAGMENT, DepthPeeling.PeelingShader ) )
    program.addShader( osg.Shader( osg.Shader.FRAGMENT, FragmentShader ) )
def createPyramid():
   pyramidGeode = osg.Geode()
   pyramidGeometry = osg.Geometry()
   pyramidGeode.addDrawable(pyramidGeometry) 
   pyramidVertices = osg.Vec3Array()
   pyramidVertices.append( osg.Vec3(0, 0, 0) ) # front left 
   pyramidVertices.append( osg.Vec3(2, 0, 0) ) # front right 
   pyramidVertices.append( osg.Vec3(2, 2, 0) ) # back right 
   pyramidVertices.append( osg.Vec3( 0,2, 0) ) # back left 
   pyramidVertices.append( osg.Vec3( 1, 1,2) ) # peak
   # Associate this set of vertices with the geometry associated with the 
   # geode we added to the scene.
   pyramidGeometry.setVertexArray( pyramidVertices )
   pyramidBase = osg.DrawElementsUInt(osg.PrimitiveSet.QUADS, 3)
   pyramidBase.append(3)
   pyramidBase.append(2)
   pyramidBase.append(1)
   pyramidBase.append(0)
   pyramidGeometry.addPrimitiveSet(pyramidBase)

   pyramidFaceOne = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
   pyramidFaceOne.append(0)
   pyramidFaceOne.append(1)
   pyramidFaceOne.append(4)
   pyramidGeometry.addPrimitiveSet(pyramidFaceOne)

   pyramidFaceTwo = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
   pyramidFaceTwo.append(1)
   pyramidFaceTwo.append(2)
   pyramidFaceTwo.append(4)
   pyramidGeometry.addPrimitiveSet(pyramidFaceTwo)

   pyramidFaceThree = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
   pyramidFaceThree.append(2)
   pyramidFaceThree.append(3)
   pyramidFaceThree.append(4)
   pyramidGeometry.addPrimitiveSet(pyramidFaceThree)

   pyramidFaceFour = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
   pyramidFaceFour.append(3)
   pyramidFaceFour.append(0)
   pyramidFaceFour.append(4)
   pyramidGeometry.addPrimitiveSet(pyramidFaceFour)

   colors = osg.Vec4Array()
   colors.append(osg.Vec4(1.0, 0.0, 0.0, 1.0) ) #index 0 red
   colors.append(osg.Vec4(0.0, 1.0, 0.0, 1.0) ) #index 1 green
   colors.append(osg.Vec4(0.0, 0.0, 1.0, 1.0) ) #index 2 blue
   colors.append(osg.Vec4(1.0, 1.0, 1.0, 1.0) ) #index 3 white

   colorIndexArray = osg.UIntArray()
   colorIndexArray.append(0) # vertex 0 assigned color array element 0
   colorIndexArray.append(1) # vertex 1 assigned color array element 1
   colorIndexArray.append(2) # vertex 2 assigned color array element 2
   colorIndexArray.append(3) # vertex 3 assigned color array element 3
   colorIndexArray.append(0) # vertex 4 assigned color array element 0

   pyramidGeometry.setColorArray(colors)
   pyramidGeometry.setColorIndices(colorIndexArray)
   pyramidGeometry.setColorBinding(osg.Geometry.BIND_PER_VERTEX)

   texcoords = osg.Vec2Array(5)
   texcoords[0].set(0.00,0.0)
   texcoords[1].set(0.25,0.0)
   texcoords[2].set(0.50,0.0)
   texcoords[3].set(0.75,0.0)
   texcoords[4].set(0.50,1.0)

   pyramidGeometry.setTexCoordArray(0,texcoords)
   return pyramidGeode
        array.push_back(base+5)
        array.push_back(base+1)
        array.push_back(base+2)
        array.push_back(base+2)
        array.push_back(base+6)
        array.push_back(base+5)

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

    geometry.addPrimitiveSet(osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, array.size(), array.front()))
    geometry.setUseDisplayList( False )
    riggeometry.setSourceGeometry(geometry)
    return riggeometry


def initVertexMap(b0, b1, b2, geom, array):


    
    vertexesInfluences = osgAnimation.VertexInfluenceSet()
    vim = osgAnimation.VertexInfluenceMap()

    (*vim)[b0.getName()].setName(b0.getName())
    (*vim)[b1.getName()].setName(b1.getName())
    (*vim)[b2.getName()].setName(b2.getName())
pyramidGeometry = osg.Geometry()
# Next we need to associate the pyramid geometry with the pyramid geode and add the pyramid geode to the root node of the scene graph.
pyramidGeode.addDrawable(pyramidGeometry)
root.addChild(pyramidGeode)
# Declare an array of vertices. Each vertex will be represented by a triple -- an instances of the vec3 class. An instance of osg.Vec3Array can be used to store these triples. Since osg.Vec3Array is derived from the STL vector class, we can use the append method to add array elements. Push back adds elements to the end of the vector, thus the index of first element entered is zero, the second entries index is 1, etc.
# Using a right-handed coordinate system with 'z' up, array elements zero..four below represent the 5 points required to create a simple pyramid.
pyramidVertices = osg.Vec3Array()
pyramidVertices.append(osg.Vec3(0, 0, 0))  # front left
pyramidVertices.append(osg.Vec3(10, 0, 0))  # front right
pyramidVertices.append(osg.Vec3(10, 10, 0))  # back right
pyramidVertices.append(osg.Vec3(0, 10, 0))  # back left
pyramidVertices.append(osg.Vec3(5, 5, 10))  # peak
# Associate this set of vertices with the geometry associated with the geode we added to the scene.
pyramidGeometry.setVertexArray(pyramidVertices)
# Next, create a primitive set and add it to the pyramid geometry. Use the first four points of the pyramid to define the base using an instance of the DrawElementsUint class. Again this class is derived from the STL vector, so the append method will add elements in sequential order. To ensure proper backface cullling, vertices should be specified in counterclockwise order. The arguments for the constructor are the enumerated type for the primitive (same as the OpenGL primitive enumerated types), and the index in the vertex array to start from.
pyramidBase = osg.DrawElementsUInt(osg.PrimitiveSet.QUADS, 0)
pyramidBase.append(3)
pyramidBase.append(2)
pyramidBase.append(1)
pyramidBase.append(0)
pyramidGeometry.addPrimitiveSet(pyramidBase)
# Repeat the same for each of the four sides. Again, vertices are specified in counter-clockwise order.
pyramidFaceOne = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
pyramidFaceOne.append(0)
pyramidFaceOne.append(1)
pyramidFaceOne.append(4)
pyramidGeometry.addPrimitiveSet(pyramidFaceOne)

pyramidFaceTwo = osg.DrawElementsUInt(osg.PrimitiveSet.TRIANGLES, 0)
pyramidFaceTwo.append(1)
pyramidFaceTwo.append(2)
Esempio n. 6
0
        column = row
        for(unsigned int ix=0ix<num_x++ix)
            (*vertices)[vert_no++] = column
            column.x() += dx
        row.y() += dy

    geom.setVertexArray(vertices)

    vbo =  osg.VertexBufferObject if (useVBO) else  0()
    if vbo : vertices.setVertexBufferObject(vbo)
    
    ebo =  osg.ElementBufferObject if (useVBO) else  0()

    for(iy=0 iy<num_y-1 ++iy)
        element_no = 0
        elements = osg.DrawElementsUInt(GL_TRIANGLE_STRIP, num_x*2)
        index = iy * num_x
        for(unsigned int ix = 0 ix<num_x ++ix)
            (*elements)[element_no++] = index + num_x
            (*elements)[element_no++] = index++
        geom.addPrimitiveSet(elements) 
        
        if ebo : elements.setElementBufferObject(ebo)
    
    geom.setUseVertexBufferObjects(useVBO)

    return geode

int main(int argc, char *argv[])
    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)