const Field<PointType>& PrimitivePatch<Face, FaceList, PointField, PointType>::faceNormals() const { if (!faceNormalsPtr_) { calcFaceNormals(); } return *faceNormalsPtr_; }
MeshModel::MeshModel(GLfloat x,GLfloat y,GLfloat z, vector<V3f> &mv,vector<int> &mvi){ textured=false; for(int i=0; i<mv.size();i++) v.push_back(V3f(mv[i].x+x,mv[i].y+y,mv[i].z+z)); for(int i=0; i<mvi.size(); i+=3) vi.push_back(V3i(mvi[i],mvi[i+1],mvi[i+2])); calcFaceNormals(); calcVertexNormalsAverage(); calcVertexNormalsWeight(); }
artemis::Entity& EntityFactory::makePlaneEntity(){ artemis::Entity& planeEntity = em->create(); vector<vertex> planeVerts; vector<GLuint> planeVertIndex; makePlane(5,5, planeVerts, planeVertIndex); calcFaceNormals(planeVerts, planeVertIndex); planeEntity.addComponent(geoManager.create(planeVerts, planeVertIndex)); return planeEntity; }
MeshPlane::MeshPlane(GLfloat x, GLfloat y, GLfloat z, GLfloat x_len, GLfloat y_len, int x_tiles, int y_tiles){ textured=false; for(int i = 0; i<=x_tiles; i++) for(int j = 0; j<=y_tiles; j++) v.push_back(V3f(i*x_len+x,y, j*y_len+z)); for(int i = 1; i<v.size()-y_tiles-1; i++){ if(i%(y_tiles+1)!=0){ vi.push_back(V3i(i-1,i,i+y_tiles+1)); vi.push_back(V3i( i-1,i+y_tiles+1, i+y_tiles)); } } calcFaceNormals(); calcVertexNormalsAverage(); calcVertexNormalsWeight(); }
MeshPlane::MeshPlane(GLfloat x, GLfloat y, GLfloat z, GLfloat x_len, GLfloat y_len, int x_tiles, int y_tiles, GLuint texid){ MeshPlane::texid=texid; textured=true; t.push_back(V2f(0,0)); t.push_back(V2f(0,1)); t.push_back(V2f(1,1)); t.push_back(V2f(1,0)); for(int i = 0; i<=x_tiles; i++) for(int j = 0; j<=y_tiles; j++) v.push_back(V3f(i*x_len+x,y, j*y_len+z)); for(int i = 1; i<v.size()-y_tiles-1; i++){ if(i%(y_tiles+1)!=0){ vi.push_back(V3i(i-1,i,i+y_tiles+1)); ti.push_back(V3i(0,1,2)); vi.push_back(V3i( i-1,i+y_tiles+1, i+y_tiles)); ti.push_back(V3i(0,2,3)); } } calcFaceNormals(); calcVertexNormalsAverage(); calcVertexNormalsWeight(); }
bool vtkOsgConverter::WriteAnActor() { vtkMapper* actorMapper = _actor->GetMapper(); // see if the actor has a mapper. it could be an assembly if (actorMapper == NULL) return false; // dont export when not visible if (_actor->GetVisibility() == 0) return false; vtkDataObject* inputDO = actorMapper->GetInputDataObject(0, 0); if (inputDO == NULL) return false; // Get PolyData. Convert if necessary becasue we only want polydata vtkSmartPointer<vtkPolyData> pd; if(inputDO->IsA("vtkCompositeDataSet")) { vtkCompositeDataGeometryFilter* gf = vtkCompositeDataGeometryFilter::New(); gf->SetInput(inputDO); gf->Update(); pd = gf->GetOutput(); gf->Delete(); } else if(inputDO->GetDataObjectType() != VTK_POLY_DATA) { vtkGeometryFilter* gf = vtkGeometryFilter::New(); gf->SetInput(inputDO); gf->Update(); pd = gf->GetOutput(); gf->Delete(); } else pd = static_cast<vtkPolyData*>(inputDO); // Get the color range from actors lookup table double range[2]; vtkLookupTable* actorLut = static_cast<vtkLookupTable*>(actorMapper->GetLookupTable()); actorLut->GetTableRange(range); // Copy mapper to a new one vtkPolyDataMapper* pm = vtkPolyDataMapper::New(); // Convert cell data to point data // NOTE: Comment this out to export a mesh if (actorMapper->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA || actorMapper->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA) { vtkCellDataToPointData* cellDataToPointData = vtkCellDataToPointData::New(); cellDataToPointData->PassCellDataOff(); cellDataToPointData->SetInput(pd); cellDataToPointData->Update(); pd = cellDataToPointData->GetPolyDataOutput(); cellDataToPointData->Delete(); pm->SetScalarMode(VTK_SCALAR_MODE_USE_POINT_DATA); } else pm->SetScalarMode(actorMapper->GetScalarMode()); pm->SetInput(pd); pm->SetScalarVisibility(actorMapper->GetScalarVisibility()); vtkLookupTable* lut = NULL; // ParaView OpenSG Exporter if (dynamic_cast<vtkDiscretizableColorTransferFunction*>(actorMapper->GetLookupTable())) lut = actorLut; // Clone the lut in OGS because otherwise the original lut gets destroyed else { lut = vtkLookupTable::New(); lut->DeepCopy(actorLut); lut->Build(); } pm->SetLookupTable(lut); pm->SetScalarRange(range); pm->Update(); if(pm->GetScalarMode() == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA || pm->GetScalarMode() == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA ) { if(actorMapper->GetArrayAccessMode() == VTK_GET_ARRAY_BY_ID ) pm->ColorByArrayComponent(actorMapper->GetArrayId(), actorMapper->GetArrayComponent()); else pm->ColorByArrayComponent(actorMapper->GetArrayName(), actorMapper->GetArrayComponent()); } vtkPointData* pntData = pd->GetPointData(); bool hasTexCoords = false; vtkUnsignedCharArray* vtkColors = pm->MapScalars(1.0); // ARRAY SIZES vtkIdType m_iNumPoints = pd->GetNumberOfPoints(); if (m_iNumPoints == 0) return false; vtkIdType m_iNumGLPoints = pd->GetVerts()->GetNumberOfCells(); vtkIdType m_iNumGLLineStrips = pd->GetLines()->GetNumberOfCells(); vtkIdType m_iNumGLPolygons = pd->GetPolys()->GetNumberOfCells(); vtkIdType m_iNumGLTriStrips = pd->GetStrips()->GetNumberOfCells(); vtkIdType m_iNumGLPrimitives = m_iNumGLPoints + m_iNumGLLineStrips + m_iNumGLPolygons + m_iNumGLTriStrips; bool lit = !(m_iNumGLPolygons == 0 && m_iNumGLTriStrips == 0); if (_verbose) { std::cout << "Array sizes:" << std::endl; std::cout << " number of vertices: " << m_iNumPoints << std::endl; std::cout << " number of GL_POINTS: " << m_iNumGLPoints << std::endl; std::cout << " number of GL_LINE_STRIPS: " << m_iNumGLLineStrips << std::endl; std::cout << " number of GL_POLYGON's: " << m_iNumGLPolygons << std::endl; std::cout << " number of GL_TRIANGLE_STRIPS: " << m_iNumGLTriStrips << std::endl; std::cout << " number of primitives: " << m_iNumGLPrimitives << std::endl; } // NORMALS vtkDataArray* vtkNormals = NULL; int m_iNormalType = NOT_GIVEN; if (_actor->GetProperty()->GetInterpolation() == VTK_FLAT) { vtkNormals = pd->GetCellData()->GetNormals(); if (vtkNormals != NULL) m_iNormalType = PER_CELL; } else { vtkNormals = pntData->GetNormals(); if (vtkNormals != NULL) m_iNormalType = PER_VERTEX; } if (_verbose) { std::cout << "Normals:" << std::endl; if (m_iNormalType != NOT_GIVEN) { std::cout << " number of normals: " << vtkNormals->GetNumberOfTuples() << std::endl; std::cout << " normals are given: "; std::cout << ((m_iNormalType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; } else std::cout << " no normals are given" << std::endl; } // COLORS int m_iColorType = NOT_GIVEN; if(pm->GetScalarVisibility()) { int iScalarMode = pm->GetScalarMode(); if(vtkColors == NULL) { m_iColorType = NOT_GIVEN; std::cout << "WARNING: MapScalars(1.0) did not return array!" << std::endl; } else if(iScalarMode == VTK_SCALAR_MODE_USE_CELL_DATA) m_iColorType = PER_CELL; else if(iScalarMode == VTK_SCALAR_MODE_USE_POINT_DATA) m_iColorType = PER_VERTEX; else if(iScalarMode == VTK_SCALAR_MODE_USE_CELL_FIELD_DATA) { std::cout << "WARNING TO BE REMOVED: Can not process colours with scalar mode using cell field data!" << std::endl; m_iColorType = PER_CELL; } else if(iScalarMode == VTK_SCALAR_MODE_USE_POINT_FIELD_DATA) { std::cout << "WARNING TO BE REMOVED: Can not process colours with scalar mode using point field data!" << std::endl; m_iColorType = PER_VERTEX; } else if(iScalarMode == VTK_SCALAR_MODE_DEFAULT) { //Bummer, we do not know what it is. may be we can make a guess int numColors = vtkColors->GetNumberOfTuples(); if (numColors == 0) { m_iColorType = NOT_GIVEN; std::cout << "WARNING: No colors found!" << std::endl; } else if (numColors == m_iNumPoints) m_iColorType = PER_VERTEX; else if (numColors == m_iNumGLPrimitives) m_iColorType = PER_CELL; else { m_iColorType = NOT_GIVEN; std::cout << "WARNING: Number of colors do not match number of points / cells!" << std::endl; } } } if (_verbose) { std::cout << "Colors:" << std::endl; if (m_iColorType != NOT_GIVEN) { std::cout << " number of colors: " << vtkColors->GetNumberOfTuples() << std::endl; std::cout << " colors are given: " << ((m_iColorType == PER_VERTEX) ? "per vertex" : "per cell") << std::endl; } else std::cout << " no colors are given" << std::endl; } // TEXCOORDS vtkDataArray* vtkTexCoords = pntData->GetTCoords(); if (_verbose) { std::cout << "Tex-coords:" << std::endl; if (vtkTexCoords) { std::cout << " Number of tex-coords: " << vtkTexCoords->GetNumberOfTuples() << std::endl; hasTexCoords = true; } else std::cout << " No tex-coords where given" << std::endl; } // TRANSFORMATION double scaling[3]; double translation[3]; // double rotation[3]; _actor->GetPosition(translation); _actor->GetScale(scaling); //_actor->GetRotation(rotation[0], rotation[1], rotation[2]); if (_verbose) std::cout << "set scaling: " << scaling[0] << " " << scaling[1] << " " << scaling[2] << std::endl; osg::Matrix m; m.setIdentity(); m.setTranslate(translation[0], translation[1], translation[2]); m.setScale(scaling[0], scaling[1], scaling[2]); // TODO QUATERNION m.setRotate(rotation[0], rotation[1], rotation[2]) beginEditCP(_osgTransform); _osgTransform->setMatrix(m); endEditCP(_osgTransform); //pm->Update(); // Get the converted OpenSG node NodePtr osgGeomNode = Node::create(); GeometryPtr osgGeometry = Geometry::create(); beginEditCP(osgGeomNode); osgGeomNode->setCore(osgGeometry); endEditCP(osgGeomNode); bool osgConversionSuccess = false; GeoPTypesPtr osgTypes = GeoPTypesUI8::create(); GeoPLengthsPtr osgLengths = GeoPLengthsUI32::create(); GeoIndicesUI32Ptr osgIndices = GeoIndicesUI32::create(); GeoPositions3fPtr osgPoints = GeoPositions3f::create(); GeoNormals3fPtr osgNormals = GeoNormals3f::create(); GeoColors3fPtr osgColors = GeoColors3f::create(); GeoTexCoords2dPtr osgTexCoords = GeoTexCoords2d::create(); //Rendering with OpenSG simple indexed geometry if (((m_iNormalType == PER_VERTEX) || (m_iNormalType == NOT_GIVEN)) && ((m_iColorType == PER_VERTEX) || (m_iColorType == NOT_GIVEN))) { if (_verbose) std::cout << "Start ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; //getting the vertices: beginEditCP(osgPoints); { for (int i = 0; i < m_iNumPoints; i++) { double* aVertex = pd->GetPoint(i); osgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); } } endEditCP(osgPoints); //possibly getting the normals if (m_iNormalType == PER_VERTEX) { vtkIdType iNumNormals = vtkNormals->GetNumberOfTuples(); beginEditCP(osgNormals); { double* aNormal; for (int i = 0; i < iNumNormals; i++) { aNormal = vtkNormals->GetTuple(i); osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); } } endEditCP(osgNormals); if (iNumNormals != m_iNumPoints) { std::cout << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of normals" << std::endl; std::cout << "should equal the number of vertices (points)!" << std::endl << std::endl; } } //possibly getting the colors if (m_iColorType == PER_VERTEX) { vtkIdType iNumColors = vtkColors->GetNumberOfTuples(); beginEditCP(osgColors); { unsigned char aColor[4]; for (int i = 0; i < iNumColors; i++) { vtkColors->GetTupleValue(i, aColor); float r = ((float) aColor[0]) / 255.0f; float g = ((float) aColor[1]) / 255.0f; float b = ((float) aColor[2]) / 255.0f; osgColors->addValue(Color3f(r, g, b)); } } endEditCP(osgColors); if (iNumColors != m_iNumPoints) { std::cout << "WARNING: CVtkActorToOpenSG::ProcessGeometryNormalsAndColorsPerVertex() number of colors" << std::endl; std::cout << "should equal the number of vertices (points)!" << std::endl << std::endl; } } //possibly getting the texture coordinates. These are alwary per vertex if (vtkTexCoords != NULL) { int numTuples = vtkTexCoords->GetNumberOfTuples(); for (int i = 0; i < numTuples; i++) { double texCoords[3]; vtkTexCoords->GetTuple(i, texCoords); osgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); } } //getting the cells beginEditCP(osgTypes); beginEditCP(osgLengths); beginEditCP(osgIndices); { vtkCellArray* pCells; vtkIdType npts, * pts; int prim; prim = 0; pCells = pd->GetVerts(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_POINTS); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } prim = 0; pCells = pd->GetLines(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_LINE_STRIP); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } prim = 0; pCells = pd->GetPolys(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_POLYGON); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } prim = 0; pCells = pd->GetStrips(); if (pCells->GetNumberOfCells() > 0) for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_TRIANGLE_STRIP); for (int i = 0; i < npts; i++) osgIndices->addValue(pts[i]); } } endEditCP(osgIndices); endEditCP(osgLengths); endEditCP(osgTypes); ChunkMaterialPtr material = CreateMaterial(lit, hasTexCoords); beginEditCP(osgGeometry); { osgGeometry->setPositions(osgPoints); osgGeometry->setTypes(osgTypes); osgGeometry->setLengths(osgLengths); osgGeometry->setIndices(osgIndices); osgGeometry->setMaterial(material); if (m_iNormalType == PER_VERTEX) osgGeometry->setNormals(osgNormals); if (m_iColorType == PER_VERTEX) osgGeometry->setColors(osgColors); if (osgTexCoords->getSize() > 0) osgGeometry->setTexCoords(osgTexCoords); } endEditCP(osgGeometry); osgConversionSuccess = true; if (_verbose) std::cout << " End ProcessGeometryNormalsAndColorsPerVertex()" << std::endl; } else { //Rendering with OpenSG non indexed geometry by copying a lot of attribute data if (_verbose) std::cout << "Start ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; int gl_primitive_type = -1; if(m_iNumGLPolygons > 0) { if(m_iNumGLPolygons != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_POLYGON; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_POLYGON, pd, osgGeometry); } else if(m_iNumGLLineStrips > 0) { if (m_iNumGLLineStrips != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_LINE_STRIP; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_LINE_STRIP, pd osgGeometry); } else if(m_iNumGLTriStrips > 0) { if (m_iNumGLTriStrips != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_TRIANGLE_STRIP; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_TRIANGLE_STRIP, pd osgGeometry); } else if (m_iNumGLPoints > 0) { if (m_iNumGLPoints != m_iNumGLPrimitives) std::cout << "WARNING: vtkActor contains different kind of primitives" << std::endl; gl_primitive_type = GL_POINTS; //osgConversionSuccess = this->ProcessGeometryNonIndexedCopyAttributes(GL_POINTS, pd osgGeometry); } if(gl_primitive_type != -1) { vtkCellArray* pCells; if (gl_primitive_type == GL_POINTS) pCells = pd->GetVerts(); else if (gl_primitive_type == GL_LINE_STRIP) pCells = pd->GetLines(); else if (gl_primitive_type == GL_POLYGON) pCells = pd->GetPolys(); else if (gl_primitive_type == GL_TRIANGLE_STRIP) pCells = pd->GetStrips(); else { std::cout << "CVtkActorToOpenSG::ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl << " was called with non implemented gl_primitive_type!" << std::endl; } beginEditCP(osgTypes); beginEditCP(osgLengths); beginEditCP(osgPoints); beginEditCP(osgColors); beginEditCP(osgNormals); { int prim = 0; if (pCells->GetNumberOfCells() > 0) { vtkIdType npts, * pts; for (pCells->InitTraversal(); pCells->GetNextCell(npts, pts); prim++) { osgLengths->addValue(npts); osgTypes->addValue(GL_POLYGON); for (int i = 0; i < npts; i++) { double* aVertex; double* aNormal; unsigned char aColor[4]; aVertex = pd->GetPoint(pts[i]); osgPoints->addValue(Vec3f(aVertex[0], aVertex[1], aVertex[2])); if (m_iNormalType == PER_VERTEX) { aNormal = vtkNormals->GetTuple(pts[i]); osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); } else if (m_iNormalType == PER_CELL) { aNormal = vtkNormals->GetTuple(prim); osgNormals->addValue(Vec3f(aNormal[0], aNormal[1], aNormal[2])); } if (m_iColorType == PER_VERTEX) { vtkColors->GetTupleValue(pts[i], aColor); float r = ((float) aColor[0]) / 255.0f; float g = ((float) aColor[1]) / 255.0f; float b = ((float) aColor[2]) / 255.0f; osgColors->addValue(Color3f(r, g, b)); } else if (m_iColorType == PER_CELL) { vtkColors->GetTupleValue(prim, aColor); float r = ((float) aColor[0]) / 255.0f; float g = ((float) aColor[1]) / 255.0f; float b = ((float) aColor[2]) / 255.0f; osgColors->addValue(Color3f(r, g, b)); } } } } } endEditCP(osgTypes); endEditCP(osgLengths); endEditCP(osgPoints); endEditCP(osgColors); endEditCP(osgNormals); //possibly getting the texture coordinates. These are always per vertex vtkPoints* points = pd->GetPoints(); if ((vtkTexCoords != NULL) && (points != NULL)) { int numPoints = points->GetNumberOfPoints(); int numTexCoords = vtkTexCoords->GetNumberOfTuples(); if (numPoints == numTexCoords) { beginEditCP(osgTexCoords); { int numTuples = vtkTexCoords->GetNumberOfTuples(); for (int i = 0; i < numTuples; i++) { double texCoords[3]; vtkTexCoords->GetTuple(i, texCoords); osgTexCoords->addValue(Vec2f(texCoords[0], texCoords[1])); } } endEditCP(osgTexCoords); } } ChunkMaterialPtr material = CreateMaterial(lit, hasTexCoords); //GeometryPtr geo = Geometry::create(); beginEditCP(osgGeometry); { osgGeometry->setPositions(osgPoints); osgGeometry->setTypes(osgTypes); osgGeometry->setLengths(osgLengths); osgGeometry->setMaterial(material); if (m_iNormalType != NOT_GIVEN) osgGeometry->setNormals(osgNormals); if (m_iColorType != NOT_GIVEN) osgGeometry->setColors(osgColors); if (osgTexCoords->getSize() > 0) osgGeometry->setTexCoords(osgTexCoords); //geo->setMaterial(getDefaultMaterial()); } endEditCP(osgGeometry); osgConversionSuccess = true; } if (_verbose) std::cout << " End ProcessGeometryNonIndexedCopyAttributes(int gl_primitive_type)" << std::endl; } if(!osgConversionSuccess) { std::cout << "OpenSG converter was not able to convert this actor." << std::endl; return false; } if(m_iNormalType == NOT_GIVEN) { //GeometryPtr newGeometryPtr = GeometryPtr::dcast(newNodePtr->getCore()); if((osgGeometry != NullFC) && (m_iColorType == PER_VERTEX)) { std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; calcVertexNormals(osgGeometry); } else if ((osgGeometry != NullFC) && (m_iColorType == PER_CELL)) { std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per face!" << std::endl; calcFaceNormals(osgGeometry); } else if (osgGeometry != NullFC) { std::cout << "WARNING: Normals are missing in the vtk layer, calculating normals per vertex!" << std::endl; calcVertexNormals(osgGeometry); } } std::cout << "Conversion finished." << std::endl; // Add node to root beginEditCP(_osgRoot); _osgRoot->addChild(osgGeomNode); endEditCP(_osgRoot); pm->Delete(); return true; }
int main (int argc, char **argv) { osgInit( argc, argv ); glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); int winID = glutCreateWindow("OpenSG"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(resize); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glClearColor( .1, .6, .2, 1 ); //glCullFace( GL_BACK ); //glEnable( GL_CULL_FACE ); //BEACON NodePtr beaconNode = Node::create(); GroupPtr beaconCore = Group::create(); beginEditCP( beaconNode ); beaconNode->setCore( beaconCore ); endEditCP( beaconNode ); //TRANSFORM NodePtr transNode = Node::create(); TransformPtr transCore = Transform::create(); beginEditCP( transNode ); transNode->setCore( transCore ); transNode->addChild( beaconNode ); endEditCP( transNode ); cam_trans = transCore; //OBJECT0: Plane objects[0] = makeBox( 3,3,2, 2,2,1 ); calcFaceNormals( GeometryPtr::dcast(objects[0]->getCore()) ); normals[0] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[0]->getCore()), 0.5 ); //OBJECT1: Sphere objects[1] = makeSphere( 2, 2 ); calcFaceNormals( GeometryPtr::dcast(objects[1]->getCore()) ); normals[1] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[1]->getCore()), 0.5 ); //OBJECT2: Cone objects[2] = makeConicalFrustum( 1.5, 0.75, 2, 8, true, true, true ); calcFaceNormals( GeometryPtr::dcast(objects[2]->getCore()) ); normals[2] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[2]->getCore()), 0.5 ); //OBJECT3: Custom Single Indexed Geometry objects[3] = Node::create(); GeometryPtr obj3Core= Geometry::create(); GeoIndicesUI32Ptr obj3Index = GeoIndicesUI32::create(); GeoPositions3f::PtrType obj3Pnts = GeoPositions3f::create(); GeoColors3f::PtrType obj3Colors = GeoColors3f::create(); GeoPTypesPtr obj3Types = GeoPTypesUI8::create(); GeoPLengthsPtr obj3Lengths = GeoPLengthsUI32::create(); beginEditCP( obj3Pnts ); obj3Pnts->addValue( Pnt3f(0, 0,0) ); obj3Pnts->addValue( Pnt3f(1,-1,0) ); obj3Pnts->addValue( Pnt3f(1, 1,0) ); obj3Pnts->addValue( Pnt3f(1, 1,0) ); obj3Pnts->addValue( Pnt3f(1,-1,0) ); obj3Pnts->addValue( Pnt3f(3,-1.3,0) ); obj3Pnts->addValue( Pnt3f(3, 1.3,0) ); obj3Pnts->addValue( Pnt3f(3, 1.3,0) ); obj3Pnts->addValue( Pnt3f(3,-1.3,0) ); obj3Pnts->addValue( Pnt3f(4, 0,0) ); endEditCP( obj3Pnts ); beginEditCP( obj3Types ); //obj3Types->addValue( GL_TRIANGLES ); //obj3Types->addValue( GL_QUADS ); //obj3Types->addValue( GL_TRIANGLES ); obj3Types->addValue( GL_POLYGON ); endEditCP( obj3Types ); beginEditCP( obj3Lengths ); //obj3Lengths->addValue( 3 ); //obj3Lengths->addValue( 4 ); //obj3Lengths->addValue( 3 ); obj3Lengths->addValue( 6 ); endEditCP( obj3Lengths ); beginEditCP( obj3Colors ); for( UInt32 i=0; i<obj3Pnts->getSize(); ++i ) { obj3Colors->addValue( Color3f(.7,.7,.7) ); } endEditCP( obj3Colors ); beginEditCP( obj3Index ); //for( UInt32 i=0; i<obj3Pnts->getSize(); ++i ) //{ // obj3Index->addValue( i ); //} obj3Index->addValue( 0 ); obj3Index->addValue( 1 ); obj3Index->addValue( 5 ); obj3Index->addValue( 9 ); obj3Index->addValue( 6 ); obj3Index->addValue( 2 ); endEditCP( obj3Index ); beginEditCP( obj3Core ); obj3Core->setIndices( obj3Index ); obj3Core->setPositions( obj3Pnts ); obj3Core->setTypes( obj3Types ); obj3Core->setLengths( obj3Lengths ); obj3Core->setColors( obj3Colors ); endEditCP( obj3Core ); beginEditCP( objects[3] ); objects[3]->setCore( obj3Core ); endEditCP( objects[3] ); calcFaceNormals( GeometryPtr::dcast(objects[3]->getCore()) ); normals[3] = calcFaceNormalsGeo( GeometryPtr::dcast(objects[3]->getCore()), 0.5 ); //ROOT root = Node::create(); GroupPtr rootCore = Group::create(); beginEditCP(root); root->setCore(rootCore); root->addChild(transNode); root->addChild(objects[0]); root->addChild(normals[0]); activeObj = root->findChild( objects[0] ); activeNorm = root->findChild( normals[0] ); endEditCP(root); camera = PerspectiveCamera::create(); camera->setBeacon( beaconNode ); camera->setFov( 90 ); camera->setNear( 0.1 ); camera->setFar( 10000 ); SolidBackgroundPtr background = SolidBackground::create(); viewp = Viewport::create(); viewp->setCamera( camera ); viewp->setBackground( background ); viewp->setRoot( root ); viewp->setSize( 0,0, 1,1 ); GLint glVP[4]; glGetIntegerv( GL_VIEWPORT, glVP ); GLUTWindowPtr gwin = GLUTWindow::create(); gwin->setId(winID); gwin->setSize(glVP[2], glVP[3]); window = gwin; window->addPort( viewp ); window->init(); drAct = DrawAction::create(); Vec3f pos( 0, 0, 3 ); tball.setMode( Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( Trackball::OSGFree ); glutMainLoop(); return 0; }