def buildJoint3(previousJoint): height = 7.5 radius = 4.45633 joint = osg.Geode() xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(-osg.PI_2, 1.0, 0.0, 0.0) xTransform.setMatrix(xRot) zCheat = osg.MatrixTransform() zTransCheat = osg.Matrix.translate(0.0,0.0,-height) zCheat.setMatrix(zTransCheat) xTransform.addChild(zCheat) shape = osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints) joint.addDrawable(shape) zCheat.addChild(joint) zTransform = osg.MatrixTransform() zCheat.addChild(zTransform) zRot = osg.Matrix.rotate((float)jointAngle3, 0.0, 0.0, 1.0) zTrans = osg.Matrix.translate(0,0,0) zTransform.setMatrix(zTrans*zRot) if showAxis : createAxis(zTransform) return zTransform
def createMovingModel(center, radius): animationLength = 10.0 animationPath = createAnimationPath(center,radius,animationLength) model = osg.Group() cessna = osgDB.readNodeFile("cessna.osgt") if cessna : bs = cessna.getBound() size = radius/bs.radius()*0.3 positioned = osg.MatrixTransform() positioned.setDataVariance(osg.Object.STATIC) positioned.setMatrix(osg.Matrix.translate(-bs.center())* osg.Matrix.scale(size,size,size)* osg.Matrix.rotate(osg.inDegrees(180.0),0.0,0.0,2.0)) positioned.addChild(cessna) xform = osg.MatrixTransform() xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,2.0)) xform.addChild(positioned) xform.addChild(createSpotLightNode(osg.Vec3(0.0,0.0,0.0), osg.Vec3(0.0,1.0,-1.0), 60.0, 0, 1)) model.addChild(xform) return model
def createMovingModel(center, radius): animationLength = 10.0 animationPath = createAnimationPath(center,radius,animationLength) model = osg.Group() glider = osgDB.readNodeFile("glider.osgt") if glider : bs = glider.getBound() size = radius/bs.radius()*0.15 positioned = osg.MatrixTransform() positioned.setDataVariance(osg.Object.STATIC) positioned.setMatrix(osg.Matrix.translate(-bs.center())* osg.Matrix.scale(size,size,size)* osg.Matrix.rotate(osg.inDegrees(-90.0),0.0,0.0,1.0)) positioned.addChild(glider) xform = osg.PositionAttitudeTransform() xform.setDataVariance(osg.Object.DYNAMIC) xform.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON) xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,0.5)) xform.addChild(positioned) model.addChild(xform) cessna = osgDB.readNodeFile("cessna.osgt") if cessna : bs = cessna.getBound() size = radius/bs.radius()*0.15 positioned = osg.MatrixTransform() positioned.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON) positioned.setDataVariance(osg.Object.STATIC) positioned.setMatrix(osg.Matrix.translate(-bs.center())* osg.Matrix.scale(size,size,size)* osg.Matrix.rotate(osg.inDegrees(180.0),0.0,0.0,1.0)) #positioned.addChild(cessna) positioned.addChild(cessna) xform = osg.MatrixTransform() xform.setDataVariance(osg.Object.DYNAMIC) xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,1.0)) xform.addChild(positioned) model.addChild(xform) return model
def createAxis(previousJoint): height = 12.0 radius = .5 zmt = osg.MatrixTransform() previousJoint.addChild(zmt) zShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) zCone = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0,0.0,1.0),radius+1.0,2.0),hints) zmtCone = osg.MatrixTransform() zgCone = osg.Geode() zmtCone.setMatrix( osg.Matrix.translate(0.0,0.0,height)) previousJoint.addChild(zmtCone) zShape.setColor(osg.Vec4(0.0, 0.0, 1.0, 1.0)) zCone.setColor(osg.Vec4(0.0, 0.0, 1.0, 1.0)) z = osg.Geode() z.addDrawable(zShape) zgCone.addDrawable(zCone) zmtCone.addChild(zgCone) zmt.addChild(z) mt = osg.MatrixTransform() previousJoint.addChild(mt) xMatrix = osg.Matrix.rotate(-osg.PI_2, 0.0, 1.0, 0.0) mt.setMatrix(xMatrix) xShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) xShape.setColor(osg.Vec4(1.0, 0.0, 0.0, 1.0)) x = osg.Geode() x.addDrawable(xShape) mt.addChild(x) yMt = osg.MatrixTransform() previousJoint.addChild(yMt) yMatrix = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0) yMt.setMatrix(yMatrix) yShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) yShape.setColor(osg.Vec4(0.0, 1.0, 0.0, 1.0)) y = osg.Geode() y.addDrawable(yShape) yMt.addChild(y)
def createTouchRepresentations(parent_group, num_objects): # create some geometry which is shown for every touch-point for(unsigned int i = 0 i not = num_objects ++i) ss = std.ostringstream() geode = osg.Geode() drawable = osg.ShapeDrawable(osg.Box(osg.Vec3(0,0,0), 100)) drawable.setColor(osg.Vec4(0.5, 0.5, 0.5,1)) geode.addDrawable(drawable) ss, "Touch ", i text = osgText.Text() geode.addDrawable( text ) drawable.setDataVariance(osg.Object.DYNAMIC) _drawables.push_back(drawable) text.setFont("fonts/arial.ttf") text.setPosition(osg.Vec3(110,0,0)) text.setText(ss.str()) _texts.push_back(text) text.setDataVariance(osg.Object.DYNAMIC) mat = osg.MatrixTransform() mat.addChild(geode) mat.setNodeMask(0x0) _mats.push_back(mat) parent_group.addChild(mat)
def main(argv): overlay = False arguments = osg.ArgumentParser(argv) while arguments.read("--overlay") : overlay = True technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY while arguments.read("--object") : technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY overlay=True while arguments.read("--ortho") or arguments.read("--orthographic") : technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY overlay=True while arguments.read("--persp") or arguments.read("--perspective") : technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY overlay=True # initialize the viewer. viewer = osgViewer.Viewer() # load the nodes from the commandline arguments. model = createModel(overlay, technique) if not model: return 1 # tilt the scene so the default eye position is looking down on the model. rootnode = osg.MatrixTransform() rootnode.setMatrix(osg.Matrix.rotate(osg.inDegrees(30.0),1.0,0.0,0.0)) rootnode.addChild(model) # run optimization over the scene graph optimzer = osgUtil.Optimizer() optimzer.optimize(rootnode) # set the scene to render viewer.setSceneData(rootnode) viewer.setCameraManipulator(osgGA.TrackballManipulator()) # viewer.setUpViewOnSingleScreen(1) # normal viewer usage. return viewer.run()
def addDraggerToScene(scene, name, fixedSizeInScreen): scene.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON) transform = osg.MatrixTransform() transform.addChild(scene) dragger = createDragger(name) root = osg.Group() root.addChild(transform) if fixedSizeInScreen : draggerContainer = DraggerContainer() draggerContainer.setDragger( dragger ) root.addChild(draggerContainer) else: root.addChild(dragger) scale = scene.getBound().radius() * 1.6 dragger.setMatrix(osg.Matrix.scale(scale, scale, scale) * osg.Matrix.translate(scene.getBound().center())) if dynamic_cast<osgManipulator.TabPlaneDragger*>(dragger) : dragger.addTransformUpdating(transform, osgManipulator.DraggerTransformCallback.HANDLE_TRANSLATE_IN_LINE)
def buildJoint1(previousJoint): xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) radius = 6.7640 height = 45.0 joint = osg.Geode() xTransform.addChild(joint) joint.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) zTransform = osg.MatrixTransform() xTransform.addChild(zTransform) zTrans = osg.Matrix.translate(0.0, 0.0, height) zRot = osg.Matrix.rotate(jointAngle1, 0.0, 0.0, 1.0) zTransform.setMatrix(zTrans*zRot) return zTransform
def createLights(bb, rootStateSet): lightGroup = osg.Group() modelSize = bb.radius() # create a spot light. myLight1 = osg.Light() myLight1.setLightNum(0) myLight1.setPosition(osg.Vec4(bb.corner(4),1.0)) myLight1.setAmbient(osg.Vec4(1.0,0.0,0.0,1.0)) myLight1.setDiffuse(osg.Vec4(1.0,0.0,0.0,1.0)) myLight1.setSpotCutoff(20.0) myLight1.setSpotExponent(50.0) myLight1.setDirection(osg.Vec3(1.0,1.0,-1.0)) lightS1 = osg.LightSource() lightS1.setLight(myLight1) lightS1.setLocalStateSetModes(osg.StateAttribute.ON) lightS1.setStateSetModes(*rootStateSet,osg.StateAttribute.ON) lightGroup.addChild(lightS1) # create a local light. myLight2 = osg.Light() myLight2.setLightNum(1) myLight2.setPosition(osg.Vec4(0.0,0.0,0.0,1.0)) myLight2.setAmbient(osg.Vec4(0.0,1.0,1.0,1.0)) myLight2.setDiffuse(osg.Vec4(0.0,1.0,1.0,1.0)) myLight2.setConstantAttenuation(1.0) myLight2.setLinearAttenuation(2.0/modelSize) myLight2.setQuadraticAttenuation(2.0/osg.square(modelSize)) lightS2 = osg.LightSource() lightS2.setLight(myLight2) lightS2.setLocalStateSetModes(osg.StateAttribute.ON) lightS2.setStateSetModes(*rootStateSet,osg.StateAttribute.ON) mt = osg.MatrixTransform() # set up the animation path animationPath = osg.AnimationPath() animationPath.insert(0.0,osg.AnimationPath.ControlPoint(bb.corner(0))) animationPath.insert(1.0,osg.AnimationPath.ControlPoint(bb.corner(1))) animationPath.insert(2.0,osg.AnimationPath.ControlPoint(bb.corner(2))) animationPath.insert(3.0,osg.AnimationPath.ControlPoint(bb.corner(3))) animationPath.insert(4.0,osg.AnimationPath.ControlPoint(bb.corner(4))) animationPath.insert(5.0,osg.AnimationPath.ControlPoint(bb.corner(5))) animationPath.insert(6.0,osg.AnimationPath.ControlPoint(bb.corner(6))) animationPath.insert(7.0,osg.AnimationPath.ControlPoint(bb.corner(7))) animationPath.insert(8.0,osg.AnimationPath.ControlPoint(bb.corner(0))) animationPath.setLoopMode(osg.AnimationPath.SWING) mt.setUpdateCallback(osg.AnimationPathCallback(animationPath))
def setupAnimtkNode(staticGeode): osg.Vec3 v[5] v[0] = osg.Vec3( 0, 0, 0) v[1] = osg.Vec3(20, 40, 60) v[2] = osg.Vec3(40, 60, 20) v[3] = osg.Vec3(60, 20, 40) v[4] = osg.Vec3( 0, 0, 0) node = osg.MatrixTransform() callback = MakePathDistanceCallback(staticGeode) keys = callback._sampler.getOrCreateKeyframeContainer() keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(0, osgAnimation.Vec3CubicBezier( v[0], v[0] + (v[0] - v[3]), v[1] - (v[1] - v[0]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(2, osgAnimation.Vec3CubicBezier( v[1], v[1] + (v[1] - v[0]), v[2] - (v[2] - v[1]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(4, osgAnimation.Vec3CubicBezier( v[2], v[2] + (v[2] - v[1]), v[3] - (v[3] - v[2]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(6, osgAnimation.Vec3CubicBezier( v[3], v[3] + (v[3] - v[2]), v[4] - (v[4] - v[3]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(8, osgAnimation.Vec3CubicBezier( v[4], v[4] + (v[4] - v[3]), v[0] - (v[0] - v[4]) ))) callback.start() node.setUpdateCallback(callback) geode = osg.Geode() geode.setStateSet(setupStateSet()) geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0, 0.0, 0.0), 2))) node.addChild(geode) return node
def buildTube2(previousJoint): if showAxis : createAxis(previousJoint) height = 17.6 radius = 4.45633 xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(osg.PI_2, 1.0,0.0,0.0) xTransform.setMatrix(xRot) tube3 = osg.Geode() xTransform.addChild(tube3) tube3.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) zTransform = osg.MatrixTransform() xTransform.addChild(zTransform) zTrans = osg.Matrix.translate(0,0,height) zTransform.setMatrix(zTrans) return zTransform
def buildJoint2(previousJoint): if showAxis : createAxis(previousJoint) height = 17.6 radius = 4.45633 xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0) xTransform.setMatrix(xRot) joint = osg.Geode() joint.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) xTransform.addChild(joint) zTransform = osg.MatrixTransform() zTrans = osg.Matrix.translate( 0.0, 0.0, height) zRot = osg.Matrix.rotate(osg.PI_2+jointAngle2, 0.0,0.0,1.0) zTransform.setMatrix(zTrans*zRot) xTransform.addChild(zTransform) return zTransform
def buildTube5(previousJoint): if showAxis : createAxis(previousJoint) height = 7.5 radius = 2.86479 height = 15.0 joint = osg.Geode() shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) joint.addDrawable(shape) xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xTransform.addChild(joint) zTransform = osg.MatrixTransform() zTrans = osg.Matrix.translate(0,0,height) zTransform.setMatrix(zTrans) xTransform.addChild(zTransform) return zTransform
def buildJoint5(previousJoint): radius = 2.86479 height = 2.86479*2 joint = osg.Geode() shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,0.0),radius,height),hints) joint.addDrawable(shape) xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(-osg.PI_2, 1.0,0,0) xTransform.setMatrix(xRot) xTransform.addChild(joint) if showAxis : createAxis(xTransform) zTransform = osg.MatrixTransform() zRot = osg.Matrix.rotate(jointAngle5, 0,0,1) zTrans = osg.Matrix.translate(0,0,0) zTransform.setMatrix(zTrans*zRot) xTransform.addChild(zTransform) return zTransform
def buildJoint4(previousJoint): height = 17.5 radius = 2.86479 tube4 = osg.Geode() tube4.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) xTransform = osg.MatrixTransform() #if showAxis : # #createAxis(xTransform) # previousJoint.addChild(xTransform) xTransform.addChild(tube4) xRot = osg.Matrix.rotate(osg.PI_2, 1,0,0) xTransform.setMatrix(xRot) height = 7.5 zTrans = osg.Matrix.translate(0,0,17.5) zRot = osg.Matrix.rotate(jointAngle4-osg.PI_2, 0,0,1) zTransform = osg.MatrixTransform() zTransform.setMatrix(zTrans*zRot) xTransform.addChild(zTransform) return zTransform
def buildJoint6(previousJoint): height = 3.0 radius = 1.0 joint = osg.Geode() joint.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) xTransform = osg.MatrixTransform() xRot = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0) xTransform.setMatrix(xRot) xTransform.addChild(joint) previousJoint.addChild(xTransform) if showAxis : createAxis(xTransform) return xTransform
def createMirroredScene(model): #// calculate where to place the mirror according to the #// loaded models bounding sphere. bs = model.getBound(); width_factor = 1.5; height_factor = 0.3; xMin = bs._center.x-bs._radius*width_factor; xMax = bs._center.x+bs._radius*width_factor; yMin = bs._center.y-bs._radius*width_factor; yMax = bs._center.y+bs._radius*width_factor; z = bs._center.z-bs._radius*height_factor; #// create a textured, transparent node at the appropriate place. mirror = createMirrorSurface(xMin,xMax,yMin,yMax,z); rootNode = osg.MatrixTransform(); rootNode.setMatrix(osg.Matrix.rotate(toRad(45.0),1.0,0.0,0.0)); #// make sure that the global color mask exists. rootColorMask = osg.ColorMask(); rootColorMask.setMask(True,True,True,True); #// set up depth to be inherited by the rest of the scene unless #// overrideen. this is overridden in bin 3. rootDepth = osg.Depth() rootDepth.setFunction(osg.Depth.LESS); rootDepth.setRange(0.0,1.0); rootStateSet = osg.StateSet(); rootStateSet.setAttribute(rootColorMask); rootStateSet.setAttribute(rootDepth); rootNode.setStateSet(rootStateSet) #// bin1 - set up the stencil values and depth for mirror. setupBin1(rootNode,mirror,z) setupBin2(rootNode,model,z) setupBin3(rootNode,mirror,z) setupBin4(rootNode,model,z) setupBin5(rootNode,mirror,z) return rootNode;
def createScaledNode(node, targetScale): # create scale matrix transform = osg.MatrixTransform() bsphere = node.getBound() scale = targetScale / bsphere._radius transform.setMatrix(osg.Matrix.scale(scale,scale,scale)) transform.setDataVariance(osg.Object.STATIC) transform.addChild(node) # rescale normals state = transform.getOrCreateStateSet() state.setMode(GL_NORMALIZE, osg.StateAttribute.ON) return transform
def buildEndEffector(): mt = osg.MatrixTransform() m = osg.Matrix() length = 17.0 m.makeTranslate(0,0,length/2) mt.setMatrix(m) geode_3 = osg.Geode() shape1 = osg.ShapeDrawable(osg.Box(osg.Vec3(-EndEffector, 0.0, 0.0), .5, 1.5, length), hints) shape2 = osg.ShapeDrawable(osg.Box(osg.Vec3( EndEffector, 0.0, 0.0), .5, 1.5, length), hints) shape1.setColor(osg.Vec4(0.8, 0.8, 0.4, 1.0)) shape2.setColor(osg.Vec4(0.8, 0.8, 0.4, 1.0)) geode_3.addDrawable(shape1) geode_3.addDrawable(shape2) mt.addChild(geode_3) return mt
def main(argv): viewer = osgViewer.Viewer() wm = osgWidget.WindowManager( viewer, WINDOW_WIDTH, WINDOW_HEIGHT, MASK_2D ) menu = osgWidget.Box("menu", osgWidget.Box.HORIZONTAL) menu.addWidget(ColorLabelMenu("Choose EaseMotion")) menu.getBackground().setColor(1.0, 1.0, 1.0, 1.0) menu.setPosition(15.0, 15.0, 0.0) wm.addChild(menu) group = osg.Group() geode = osg.Geode() mt = osg.MatrixTransform() geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(), 4.0))) EASE_MOTION_SAMPLER = EaseMotionSampler(osg.Vec3(50.0, 0.0, 0.0)) EASE_MOTION_GEODE = osg.Geode() mt.addChild(geode) mt.setUpdateCallback(EASE_MOTION_SAMPLER) mt.setNodeMask(MASK_3D) viewer.setCameraManipulator(osgGA.TrackballManipulator()) viewer.getCameraManipulator().setHomePosition( osg.Vec3d(0.0, 0.0, 200.0), osg.Vec3d(20.0, 0.0, 0.0), osg.Vec3d(0.0, 1.0, 0.0) ) viewer.home() group.addChild(mt) group.addChild(EASE_MOTION_GEODE) return osgWidget.createExample(viewer, wm, group)
def createShapes(): group = osg.Group() transform = osg.MatrixTransform() group.addChild(transform) joint1 = buildJoint1(transform) joint2 = buildJoint2(joint1) tube2 = buildTube2(joint2) joint3 = buildJoint3(tube2) joint4 = buildJoint4(joint3) tube5 = buildTube5(joint4) joint5 = buildJoint5(tube5) joint6= buildJoint6(joint5) joint6.addChild( buildEndEffector()) return group
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # construct the viewer. viewer = osgViewer.Viewer() # read the scene from the list of file specified commandline args. loadedModel = osgDB.readNodeFiles(arguments) # if not loaded assume no arguments passed in, try use default mode instead. if not loadedModel : loadedModel = osgDB.readNodeFile("cessna.osgt") # if no model has been successfully loaded report failure. if not loadedModel : print arguments.getApplicationName(), ": No data loaded" return 1 # optimize the scene graph, remove redundant nodes and state etc. optimizer = osgUtil.Optimizer() optimizer.optimize(loadedModel) # add a transform with a callback to animate the loaded model. loadedModelTransform = osg.MatrixTransform() loadedModelTransform.addChild(loadedModel) nc = osg.AnimationPathCallback(loadedModelTransform.getBound().center(),osg.Vec3(0.0,0.0,1.0),osg.inDegrees(45.0)) loadedModelTransform.setUpdateCallback(nc) # finally decorate the loaded model so that it has the required multipass/bin scene graph to do the reflection effect. rootNode = createMirroredScene(loadedModelTransform) # set the scene to render viewer.setSceneData(rootNode) # hint to tell viewer to request stencil buffer when setting up windows osg.DisplaySettings.instance().setMinimumNumStencilBits(8) #osgDB.writeNodeFile(*rootNode, "test.osgt") return viewer.run()
def setupAnimtkNode(): osg.Vec3 v[5] v[0] = osg.Vec3(0,0,0) v[1] = osg.Vec3(10,-50,0) v[2] = osg.Vec3(30,-10,20) v[3] = osg.Vec3(-10,20,-20) v[4] = osg.Vec3(0,0,0) node = osg.MatrixTransform() callback = AnimtkUpdateCallback() keys = callback._sampler.getOrCreateKeyframeContainer() keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(0, osgAnimation.Vec3CubicBezier( v[0], # pos v[0] + (v[0] - v[3]), # p1 v[1] - (v[1] - v[0]) # p2 ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(2, osgAnimation.Vec3CubicBezier( v[1], # pos v[1] + (v[1] - v[0]), v[2] - (v[2] - v[1]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(4, osgAnimation.Vec3CubicBezier( v[2], # pos v[2] + (v[2] - v[1]), v[3] - (v[3] - v[2]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(6, osgAnimation.Vec3CubicBezier( v[3], # pos v[3] + (v[3] - v[2]), v[4] - (v[4] - v[3]) ))) keys.push_back(osgAnimation.Vec3CubicBezierKeyframe(8, osgAnimation.Vec3CubicBezier( v[4], # pos v[4] + (v[4] - v[3]), v[0] - (v[0] - v[4]) ))) callback.start() node.setUpdateCallback(callback) node.addChild(setupCube()) return node
def createHUD(node): # absolute transform modelview_abs = osg.MatrixTransform() modelview_abs.setReferenceFrame(osg.Transform.ABSOLUTE_RF) modelview_abs.setMatrix(osg.Matrix.identity()) modelview_abs.addChild(node) # 2D projection node projection = osg.Projection() projection.setMatrix(osg.Matrix.ortho2D(0,1280,0,1024)) projection.addChild(modelview_abs) # turn off lighting and depth test state = modelview_abs.getOrCreateStateSet() state.setMode(GL_LIGHTING, osg.StateAttribute.OFF) state.setMode(GL_DEPTH_TEST, osg.StateAttribute.OFF) return projection
def setupBin4(rootNode,model,z): #// now create the 'reflection' of the loaded model by applying #// create a Transform which flips the loaded model about the z axis #// relative to the mirror node, the loadedModel is added to the #// Transform so now appears twice in the scene, but is shared so there #// is negligable memory overhead. Also use an osg.StateSet #// attached to the Transform to override the face culling on the subgraph #// to prevert an 'inside' out view of the reflected model. #// set up the stencil ops so that only operator on this mirrors stencil value. #// this clip plane removes any of the scene which when mirror would #// poke through the mirror. However, this clip plane should really #// flip sides once the eye point goes to the back of the mirror... clipplane = osg.ClipPlane(); clipplane.setClipPlane(0.0,0.0,-1.0,z); clipplane.setClipPlaneNum(0); clipNode = osg.ClipNode(); clipNode.addClipPlane(clipplane); dstate = clipNode.getOrCreateStateSet(); dstate.setRenderBinDetails(4,"RenderBin"); dstate.setMode(osg.GL_CULL_FACE,osg.StateAttribute.OVERRIDE|osg.StateAttribute.OFF); stencil = osg.Stencil(); stencil.setFunction(osg.Stencil.EQUAL,1,4294967295); stencil.setOperation(osg.Stencil.KEEP, osg.Stencil.KEEP, osg.Stencil.KEEP); dstate.setAttributeAndModes(stencil,osg.StateAttribute.ON); reverseMatrix = osg.MatrixTransform(); reverseMatrix.stateSet = dstate reverseMatrix.preMult(osg.Matrix.translate(0.0,0.0,-z)* osg.Matrix.scale(1.0,1.0,-1.0)* osg.Matrix.translate(0.0,0.0,z)); reverseMatrix.addChild(model); clipNode.addChild(reverseMatrix); rootNode.addChild(clipNode);
def createHUD(updateText): # create the hud. derived from osgHud.cpp # adds a set of quads, each in a separate Geode - which can be picked individually # eg to be used as a menuing/help system not # Can pick texts too not modelview_abs = osg.MatrixTransform() modelview_abs.setReferenceFrame(osg.Transform.ABSOLUTE_RF) modelview_abs.setMatrix(osg.Matrix.identity()) projection = osg.Projection() projection.setMatrix(osg.Matrix.ortho2D(0,1280,0,1024)) projection.addChild(modelview_abs) timesFont = str("fonts/times.ttf") # turn lighting off for the text and disable depth test to ensure its always ontop. position = osg.Vec3(50.0,510.0,0.0) delta = osg.Vec3(0.0,-60.0,0.0) # this displays what has been selected geode = osg.Geode() stateset = geode.getOrCreateStateSet() stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF) stateset.setMode(GL_DEPTH_TEST,osg.StateAttribute.OFF) geode.setName("The text label") geode.addDrawable( updateText ) modelview_abs.addChild(geode) updateText.setCharacterSize(20.0) updateText.setFont(timesFont) updateText.setColor(osg.Vec4(1.0,1.0,0.0,1.0)) updateText.setText("") updateText.setPosition(position) position += delta
def main(argv): # use an ArgumentParser object to manage the program arguments. viewer = osgViewer.Viewer() # viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded) # read the scene from the list of file specified commandline args. loadedModel = osgDB.readNodeFile("cessna.osg") if loadedModel == None: raise Exception('Could not load model file (is OSG_FILE_PATH set and correct?)') # create a transform to spin the model. loadedModelTransform = osg.MatrixTransform() loadedModelTransform.addChild(loadedModel) print loadedModelTransform.getBound()._center #todo: nc = osg.AnimationPathCallback(loadedModelTransform.getBound()._center,osg.Vec3(0.0,0.0,1.0),osg.inDegrees(45.0)); # loadedModelTransform.setUpdateCallback(nc) rootNode = osg.Group() rootNode.stateSet.dataVariance = osg.Object.DYNAMIC rootNode.addChild(createMirroredScene(loadedModelTransform)) viewer.addEventHandler(osgViewer.HelpHandler()) viewer.addEventHandler(osgViewer.StatsHandler()) viewer.addEventHandler(osgGA.StateSetManipulator(rootNode.stateSet)) viewer.setSceneData(rootNode) print "set scene data" #hint to tell viewer to request stencil buffer when setting up windows # osg.DisplaySettings().setMinimumNumStencilBits(8) osg.DisplaySettings.instance().setMinimumNumStencilBits(8); osgDB.writeNodeFile(rootNode, "test_reflect.osg"); viewer.run() #we need run, because that sets up a trackballmanipulator and so we have the correct "look" into the scene. return 0
def createScalarBar_HUD(): geode = osgSim.ScalarBar() tp = osgSim.ScalarBar.TextProperties() tp._fontFile = "fonts/times.ttf" geode.setTextProperties(tp) stateset = geode.getOrCreateStateSet() stateset.setMode(GL_LIGHTING, osg.StateAttribute.OFF) stateset.setMode(GL_DEPTH_TEST,osg.StateAttribute.OFF) stateset.setRenderBinDetails(11, "RenderBin") modelview = osg.MatrixTransform() modelview.setReferenceFrame(osg.Transform.ABSOLUTE_RF) matrix = osg.Matrixd(osg.Matrixd.scale(1000,1000,1000) * osg.Matrixd.translate(120,10,0)) # I've played with these values a lot and it seems to work, but I have no idea why modelview.setMatrix(matrix) modelview.addChild(geode) projection = osg.Projection() projection.setMatrix(osg.Matrix.ortho2D(0,1280,0,1024)) # or whatever the OSG window res is projection.addChild(modelview) return projection #make sure you delete the return sb line
stateset.setTextureAttributeAndModes(0, texture,osg.StateAttribute.ON) polyGeom.setStateSet(stateset) # create the Geode (Geometry Node) to contain all our osg.Geometry objects. geode = osg.Geode() # add the points geometry to the geode. geode.addDrawable(polyGeom) #return geode # create a transform to move the background back and forward with. transform = osg.MatrixTransform() transform.setUpdateCallback(MyTransformCallback(1.0)) transform.addChild(geode) return transform int main(int, char **) # create the model root = osg.Group() root.addChild( createScene() ) root.addChild( createBackground() ) #osgDB.writeNodeFile(*root,"geoemtry.osgt") viewer = osgViewer.Viewer()
def createDemoScene(fixedSizeInScreen): root = osg.Group() geode_1 = osg.Geode() transform_1 = osg.MatrixTransform() geode_2 = osg.Geode() transform_2 = osg.MatrixTransform() geode_3 = osg.Geode() transform_3 = osg.MatrixTransform() geode_4 = osg.Geode() transform_4 = osg.MatrixTransform() geode_5 = osg.Geode() transform_5 = osg.MatrixTransform() geode_6 = osg.Geode() transform_6 = osg.MatrixTransform() geode_7 = osg.Geode() transform_7 = osg.MatrixTransform() radius = 0.8 height = 1.0 hints = osg.TessellationHints() hints.setDetailRatio(2.0) shape = osg.ShapeDrawable() shape = osg.ShapeDrawable(osg.Box(osg.Vec3(0.0, 0.0, -2.0), 10, 10.0, 0.1), hints) shape.setColor(osg.Vec4(0.5, 0.5, 0.7, 1.0)) geode_1.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0, 0.0, 0.0), radius * 2,radius), hints) shape.setColor(osg.Vec4(0.8, 0.8, 0.8, 1.0)) geode_2.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(-3.0, 0.0, 0.0), radius,radius), hints) shape.setColor(osg.Vec4(0.6, 0.8, 0.8, 1.0)) geode_3.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(3.0, 0.0, 0.0), 2 * radius,radius), hints) shape.setColor(osg.Vec4(0.4, 0.9, 0.3, 1.0)) geode_4.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0, -3.0, 0.0), radius, height), hints) shape.setColor(osg.Vec4(0.2, 0.5, 0.7, 1.0)) geode_5.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0, 3.0, 0.0), radius, height), hints) shape.setColor(osg.Vec4(1.0, 0.3, 0.3, 1.0)) geode_6.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0, 0.0, 3.0), 2.0, 2.0), hints) shape.setColor(osg.Vec4(0.8, 0.8, 0.4, 1.0)) geode_7.addDrawable(shape) # material matirial = osg.Material() matirial.setColorMode(osg.Material.DIFFUSE) matirial.setAmbient(osg.Material.FRONT_AND_BACK, osg.Vec4(0, 0, 0, 1)) matirial.setSpecular(osg.Material.FRONT_AND_BACK, osg.Vec4(1, 1, 1, 1)) matirial.setShininess(osg.Material.FRONT_AND_BACK, 64.0) root.getOrCreateStateSet().setAttributeAndModes(matirial, osg.StateAttribute.ON) transform_1.addChild(addDraggerToScene(geode_1,"TabBoxDragger",fixedSizeInScreen)) transform_2.addChild(addDraggerToScene(geode_2,"TabPlaneDragger",fixedSizeInScreen)) transform_3.addChild(addDraggerToScene(geode_3,"TabBoxTrackballDragger",fixedSizeInScreen)) transform_4.addChild(addDraggerToScene(geode_4,"TrackballDragger",fixedSizeInScreen)) transform_5.addChild(addDraggerToScene(geode_5,"Translate1DDragger",fixedSizeInScreen)) transform_6.addChild(addDraggerToScene(geode_6,"Translate2DDragger",fixedSizeInScreen)) transform_7.addChild(addDraggerToScene(geode_7,"TranslateAxisDragger",fixedSizeInScreen)) root.addChild(transform_1) root.addChild(transform_2) root.addChild(transform_3) root.addChild(transform_4) root.addChild(transform_5) root.addChild(transform_6) root.addChild(transform_7) return root