고려대학교 그래픽스 연구실 An Inventor Sampler - The Inventor mentor 고려대학교 그래픽스 연구실 민 성환
23 December 2015Sunghwan Min 2 Install Guide Inv252.exe 를 실행 XF-OIKEY.COM 을 커멘트라인으로 실행시켜 버전을 2.5 용 key,expire 날짜,host id 얻어낸다. 시작메뉴의 TGS open inventor 항목에서 license Admin 실행 Version 을 2.5 로 하고 key,expire 날짜,host id 를 넣고 apply 한다 이전버젼과의 호환을 위해 dll 들을 system 폴더에 복사한 다. 리부팅한다.
23 December 2015Sunghwan Min 3 Build IVF Viewer Visual studio 를 실행 New 를 클릭하면 project 탭 하위에 IVF appWizard 를 선택 Step 5 에서 생성될 Viewer 옵션을 선택한다. 컴파일후 실행
23 December 2015Sunghwan Min 4 “Hello, Cone” This chapter begins with a set of sample programs that illustrate the key aspects of Inventor Example 2-1 Creates a red cone and then renders it in a window Use Inventor Xt window Construct a simple scene graph composed of camera node, a light node, a material node, and a cone node The purpose of this chapter Simply to convey a feel for the tools Inventor
23 December 2015Sunghwan Min 5 A Red Cone Basic steps 1. Create a window where the scene will be rendered 2. Build the scene graph by creating property and shape node and combining them into groups
23 December 2015Sunghwan Min 6 A Red Cone (cont.) #include #ifdef WIN32 #define main ivMain #endif Void main(int, char **argv) { // Initialize Inventor. This returns a main window to use. // If unsuccessful, exit. Widget myWindow = SoXt::init(argv[0]); // pass the app name if (myWindow == NULL) exit(1); // Make a scene containing a red cone SoSeparator *root = new SoSeparator; SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; SoMaterial *myMaterial = new SoMaterial; root->ref(); root->addChild(myCamera); root->addChild(new SoDirectionalLight);
23 December 2015Sunghwan Min 7 A Red Cone (cont.) myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); // Red root->addChild(myMaterial); root->addChild(new SoCone); // Create a renderArea in which to see our scene graph. // The render area will appear within the main window. SoXtRenderArea *myRenderArea = new SoXtRenderArea(myWindow); // Make myCamera see everything. myCamera->viewAll(root, myRenderArea->getViewportRegion()); // Put our scene in myRenderArea, change the title myRenderArea->setSceneGraph(root); myRenderArea->setTitle("Hello Cone"); myRenderArea->show(); SoXt::show(myWindow); // Display main window SoXt::mainLoop(); // Main Inventor event loop }
23 December 2015Sunghwan Min 8 To Make the Cone Spin How to use engines to make the cone spin The engine changes the angle value in the rotationXYZ node in response to changes in the real-time clock Example 2-2
23 December 2015Sunghwan Min 9 “Hello,Cone” Using Engines 추가된 코드 // This transformation is modified to rotate the cone SoRotationXYZ *myRotXYZ = new SoRotationXYZ; root->addChild(myRotXYZ); // An engine rotates the object. The output of myCounter // is the time in seconds since the program started. // Connect this output to the angle field of myRotXYZ myRotXYZ->axis = SoRotationXYZ::X; // rotate about X axis SoElapsedTime *myCounter = new SoElapsedTime; myRotXYZ->angle.connectFrom(&myCounter->timeOut);
23 December 2015Sunghwan Min 10 Adding a Trackball Manipulator The next two examples show additional methods for editing a node in the scene graph Add manipulator to the first example When left mouse button is pressed on the trackball,it highlights itself in a different color to show it is active While it is active, the mouse can be used to rotate the trackball and the object In this example, a trackball is constructed instead of the SoRotationXYZ node Render area has a sensor attached to the scene graph, the scene is automatically rendered again after each edit
23 December 2015Sunghwan Min 11 Adding a Trackball Manipulator (cont.) Void main(int, char **argv) { // Initialize Inventor and Xt Widget myWindow = SoXt::init(argv[0]); if (myWindow == NULL) exit(1); SoSeparator *root = new SoSeparator; root->ref(); SoPerspectiveCamera *myCamera = new SoPerspectiveCamera; root->addChild(myCamera); // child 0 root->addChild(new SoDirectionalLight); // child 1 root->addChild(new SoTrackballManip); // child 2 SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); root->addChild(myMaterial); root->addChild(new SoCone); SoXtRenderArea *myRenderArea = new SoXtRenderArea(myWindow); myCamera->viewAll(root, myRenderArea->getViewportRegion()); myRenderArea->setSceneGraph(root); myRenderArea->setTitle("Trackball"); myRenderArea->show(); SoXt::show(myWindow); SoXt::mainLoop(); }
23 December 2015Sunghwan Min 12 Examiner Viewer It provides a user interface that allow use of the mouse to modify camera placement in the scene Does not need to set up a camera and call viewAll() because the viewer does this automatically
23 December 2015Sunghwan Min 13 A Red Cone (cont.) Void main(int, char **argv) { Widget myWindow = SoXt::init(argv[0]); if (myWindow == NULL) exit(1); SoSeparator *root = new SoSeparator; root->ref(); SoMaterial *myMaterial = new SoMaterial; myMaterial->diffuseColor.setValue(1.0, 0.0, 0.0); root->addChild(myMaterial); root->addChild(new SoCone); // Set up viewer: SoXtExaminerViewer *myViewer = new SoXtExaminerViewer(myWindow); myViewer->setSceneGraph(root); myViewer->setTitle("Examiner Viewer"); myViewer->show(); SoXt::show(myWindow); SoXt::mainLoop(); }
23 December 2015Sunghwan Min 14 Naming Conventions Sb Basic types (for scene basic) SbColor, SbViewVolume So All other classes in Inventor ( for scene object) SoCone,SoPerspectiveCamera,SoMaterial,SoTransform Methods and variables begin with a owercase letter getNormal(),setSceneGraph() Enumerated type values FILLED,PER_PART
23 December 2015Sunghwan Min 15 Scene Basic Types SbBool Boolean value SbBoxnx 2D or 3D box SbColor RGB color value SbCylinder cylinder SbLine directed 3D line SbMatrix 4x4 matrix SbName character string SbPList list of generic pointer SbPlane oriented 3D plane SbRotation representation of a 3D rotation about an arbitrary axis SbSphere sphere SbString “smart” character strings that have many convenience method SbTime representation of time Sb Vecnx 2D or 3D vector SbViewportRegion active viewport region within a display window SbViewVolume view volume
23 December 2015Sunghwan Min 16 Method Each Sb class has useful operators associated with it SbVec3f v(1.0,2.0,3.0); V.normalize() Fields Store parameters for nodes A field contains a value of a certain type Coordinate Systems Right-hand Angles are specified in radians