1#!/usr/bin/env python 2 3### 4# Copyright (c) 2002-2007 Systems in Motion 5# 6# Permission to use, copy, modify, and distribute this software for any 7# purpose with or without fee is hereby granted, provided that the above 8# copyright notice and this permission notice appear in all copies. 9# 10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17# 18 19### 20# This is an example from the Inventor Mentor, 21# chapter 2, example 1. 22# 23# Hello Cone example program; draws a red cone in a window. 24# 25 26import sys 27 28from pivy.sogui import * 29from pivy.coin import * 30 31def main(): 32 # Initialize Inventor. This returns a main window to use. 33 # If unsuccessful, exit. 34 35 myWindow = SoGui.init(sys.argv[0]) 36 if myWindow == None: sys.exit(1) 37 38 # Make a scene containing a red cone 39 root = SoSeparator() 40 myCamera = SoPerspectiveCamera() 41 myMaterial = SoMaterial() 42 root.addChild(myCamera) 43 root.addChild(SoDirectionalLight()) 44 myMaterial.diffuseColor = (1.0, 0.0, 0.0) # Red 45 root.addChild(myMaterial) 46 root.addChild(SoCone()) 47 48 # Create a renderArea in which to see our scene graph. 49 # The render area will appear within the main window. 50 myRenderArea = SoGuiRenderArea(myWindow) 51 52 # Make myCamera see everything. 53 myCamera.viewAll(root, myRenderArea.getViewportRegion()) 54 55 # Put our scene in myRenderArea, change the title 56 myRenderArea.setSceneGraph(root) 57 myRenderArea.setTitle("Hello Cone") 58 myRenderArea.show() 59 60 SoGui.show(myWindow) # Display main window 61 SoGui.mainLoop() # Main Inventor event loop 62 63if __name__ == "__main__": 64 main() 65