Beispiel #1
0
 def __init__(self,
              axis=osg.Vec3(0.0, 0.0, 1.0),
              startangle=0.0,
              speed=0.001):
     self._angle = startangle
     self._axis = axis
     self._quat = osg.Quat()
     self._speed = speed
     osg.NodeCallback.__init__(self)
Beispiel #2
0
def createObjectFromImageList(pNode, pImageList, pBaseUrl=""):
    """
    uses the image list to create a set of objects
    """

    box_geometry = osg.Box()
    box_drawable = osg.ShapeDrawable(box_geometry)
    # create a random function for floating points
    frandom = lambda x, y: random.randrange(x, y, int=types.FloatType)

    print "Opening %d from %d images" % (maxphotos, len(pImageList))

    for imgfile in [str(x) for x in pImageList[:maxphotos]]:
        print "osgDB.readImageFile loading:", imgfile
        image = osgDB.readImageFile(imgfile)

        #check if the image is there, and not too small (icons and such)
        if image and image.s() > 100.0 and image.t() > 100.0:
            t = osg.TextureRectangle()
            texmat = osg.TexMat()
            texmat.setScaleByTextureRectangleSize(True)
            t.setImage(image)
            stateset = osg.StateSet()
            stateset.setTextureAttributeAndModes(0, t, 1)
            stateset.setTextureAttributeAndModes(0, texmat,
                                                 osg.StateAttribute.ON)

            lbox_geode = osg.Geode()
            lbox_geode.addDrawable(box_drawable)
            lbox_geode.setStateSet(stateset)
            lbox_node = osg.PositionAttitudeTransform()
            lbox_node.addChild(lbox_geode)

            rscale = frandom(5, 10)
            lbox_node.setScale(
                osg.Vec3d(image.s() / rscale, 0.5,
                          image.t() / rscale))
            #set vertical
            q = osg.Quat()
            q.makeRotate(frandom(0, 2 * math.pi), 0, 0, 1)
            lbox_node.setAttitude(q)
            lbox_node.setPosition(
                osg.Vec3d(frandom(-50, 50), frandom(-50, 50),
                          frandom(-100, 100)))
            pNode.addChild(lbox_node)
Beispiel #3
0
def main():

    #arguments = osg.ArgumentParses(len(sys.argv),sys.argv)
    viewer = osgViewer.Viewer()  #arguments)

    viewer.setCameraManipulator(osgGA.TrackballManipulator())

    skelroot = osgAnimation.Skeleton()
    skelroot.setDefaultUpdateCallback()
    root = osgAnimation.Bone()
    root.setBindMatrixInBoneSpace(osg.Matrixd_identity())
    root.setBindMatrixInBoneSpace(osg.Matrixd_translate(-1, 0, 0))
    root.setName("root")
    root.setDefaultUpdateCallback()

    right0 = osgAnimation.Bone()
    right0.setBindMatrixInBoneSpace(osg.Matrixd_translate(1, 0, 0))
    right0.setName("right0")
    right0.setDefaultUpdateCallback("right0")

    right1 = osgAnimation.Bone()
    right1.setBindMatrixInBoneSpace(osg.Matrixd_translate(1, 0, 0))
    right1.setName("right1")
    right1.setDefaultUpdateCallback("right1")

    root.addChild(right0)
    right0.addChild(right1)
    skelroot.addChild(root)

    scene = osg.Group()
    manager = osgAnimation.BasicAnimationManager()
    scene.setUpdateCallback(manager)

    anim = osgAnimation.Animation()
    keys0 = osgAnimation.QuatKeyframeContainer()
    keys1 = osgAnimation.QuatKeyframeContainer()
    pKeys0 = int(keys0.this)
    pKeys1 = int(keys1.this)
    rotate = osg.Quat()
    rotate.makeRotate(PI_2, osg.Vec3(0, 0, 1))
    keys0.push_back(osgAnimation.QuatKeyframe(0, osg.Quat(0, 0, 0, 1)))
    keys0.push_back(osgAnimation.QuatKeyframe(3, rotate))
    keys0.push_back(osgAnimation.QuatKeyframe(6, rotate))
    keys1.push_back(osgAnimation.QuatKeyframe(0, osg.Quat(0, 0, 0, 1)))
    keys1.push_back(osgAnimation.QuatKeyframe(3, osg.Quat(0, 0, 0, 1)))
    keys1.push_back(osgAnimation.QuatKeyframe(6, rotate))

    sampler0 = osgAnimation.QuatSphericalLinearSampler()
    sampler0.setKeyframeContainer(keys0)
    channel0 = osgAnimation.QuatSphericalLinearChannel(sampler0)
    channel0.setName("quaternion")
    channel0.setTargetName("right0")
    anim.addChannel(channel0)
    sampler1 = osgAnimation.QuatSphericalLinearSampler()
    sampler1.setKeyframeContainer(keys1)
    channel1 = osgAnimation.QuatSphericalLinearChannel(sampler1)
    channel1.setName("quaternion")
    channel1.setTargetName("right1")
    anim.addChannel(channel1)
    manager.registerAnimation(anim)
    manager.buildTargetReference()

    # let's start !
    manager.playAnimation(anim)

    # we will use local data from the skeleton
    rootTransform = osg.MatrixTransform()
    rootTransform.setMatrix(osg.Matrixd_rotate(PI_2, osg.Vec3(1, 0, 0)))
    right0.addChild(createAxis())
    right0.setDataVariance(osg.Object.DYNAMIC)
    right1.addChild(createAxis())
    right1.setDataVariance(osg.Object.DYNAMIC)
    trueroot = osg.MatrixTransform()
    trueroot.setMatrix(osg.Matrixd(root.getMatrixInBoneSpace()))
    trueroot.addChild(createAxis())
    trueroot.addChild(skelroot)
    trueroot.setDataVariance(osg.Object.DYNAMIC)
    rootTransform.addChild(trueroot)
    scene.addChild(rootTransform)

    geom = createTesselatedBox(4, 4.0)
    geode = osg.Geode()
    geode.addDrawable(geom)
    skelroot.addChild(geode)
    src = geom.getVertexArray().asVec3Array()
    geom.getOrCreateStateSet().setMode(osg.GL_LIGHTING, False)
    geom.setDataVariance(osg.Object.DYNAMIC)

    initVertexMap(root, right0, right1, geom, src)

    #let's run !
    viewer.setSceneData(scene)
    viewer.realize()

    while not viewer.done():
        viewer.frame()