Summary
The XStream® HDVR® SDK supports loading of OBJ and STL format mesh files into the current dataset through the IPolygonUtilContext or hdrcPolygonUtilContext class. Details of these file formats are found in the Mesh File Types section.
Loading Mesh Data
In the C++ API, mesh loading is supported through the IPolygonUtilContext::LoadOBJ() and IPolygonUtilContext::LoadSTL() methods. Input parameters specify the path to the file to be loaded and the ENUM_PU_SMOOTH_MODES enumeration that controls how vertex normals are loaded and processed. These methods convert the designated file type into an IVertexCallListContext object that contains the vertex, normal, and shading data for the geometry. A transform matrix may then be applied to the object to set its position and orientation.
// Create an IPolygonUtilContext object
IPolygonUtilContext *pPolygonUtil;
pServerContext->CreatePolygonUtil(&pPolygonUtil);
// Load an OBJ file into an IVertexCallListContext object
IVertexCallListContext *pVertexCallList;
pServerContext->CreateVertexCallList(&pVertexCallList);
pPolygonUtil->LoadOBJ("C:/Data/SampleObject.obj", pVertexCallList, SMOOTH_MODE_NOP);
In the Java/.NET API, mesh loading is supported through the hdrcPolygonUtilContext.loadOBJ() and hdrcPolygonUtilContext.loadSTL() methods. Input parameters specify the path to the file to be loaded, and smoothing value that controls how vertex normals are loaded and processed. These methods convert the designated file type into an hdrcVertexCallListContext object that contains the vertex, normal, and shading data for the geometry. A transform matrix may then be applied to the object to set its position and orientation.
// Create an hdrcPolygonUtilContext object
hdrcPolygonUtilContext polygonUtil;
polygonUtil = serverContext.createPolygonUtil();
// Load an OBJ file into an hdrcVertexCallListContext object
hdrcVertexCallListContext vertexCallList;
vertexCallList = serverContext.createVertexCallList();
polygonUtil.loadOBJ("C:/Data/SampleObject.obj", vertexCallList, hdrcPolygonUtilContext.SMOOTH_MODE_NOP);
Importing Texture Maps with OBJ Files
JPEG texture map rendering applied to the OBJ files is supported through the IPolygonUtilContext::LoadObjWithTextureMap() or hdrcPolygonUtilContext.loadOBJWithTextureMap() methods. The texture map is applied through vertex colorization, rather than through a conventional texture mapping process. Each vertex in the OBJ file is colored according to the pixel color of the texture map image corresponding to the UV mapping coordinates. Each triangle in the mesh object is then colored based on the interpolated colors of its vertices. This vertex colorization process will result in some loss of texture map color detail, depending on the OBJ mesh complexity and the resolution of the texture map image. For example, if a high detail texture image is applied to a two triangle rectangular quad, almost none of the texture map detail will be visible on the quad. Meshes with a higher polygon count will show more texture detail, due to the higher number of vertices that can be colored.
The XStream HDVR SDK also supports conventional texture mapping. For more information on texture mapping in HDVR, see the Texture Mapping section.
Mesh viewed in OpenGL. Note the continuous texture mapping. |
Mesh viewed in HDVR. Note altered texture resolution. |
// Create an IPolygonUtilContext object
IPolygonUtilContext *pPolygonUtil;
pServerContext->CreatePolygonUtil(&pPolygonUtil);
// Load an OBJ file into an IVertexCallListContext object
IVertexCallListContext *pVertexCallList;
pServerContext->CreateVertexCallList(&pVertexCallList);
pPolygonUtil->LoadOBJWithTextureMap("C:/Data/SampleObject.obj", "C:/Data/TextureMap.jpg", pVertexCallList, SMOOTH_MODE_NOP);
// Create a hdrcPolygonUtilContext object
hdrcPolygonUtilContext polygonUtil;
polygonUtil = serverContext.createPolygonUtil();
// Load an OBJ file into an IVertexCallListContext object
hdrcVertexCallListContext vertexCallList;
vertexCallList = serverContext.createVertexCallList();
polygonUtil.loadOBJWithTextureMap("C:/Data/SampleObject.obj", "C:/Data/TextureMap.jpg", vertexCallList, hdrcPolygonUtilContext.SMOOTH_MODE_NOP);
The .NET example code is included below:
// Create a hdrcPolygonUtilContext object
hdrcPolygonUtilContext polygonUtil;
polygonUtil = serverContext.createPolygonUtil();
// Load an OBJ file into an IVertexCallListContext object
hdrcVertexCallListContext vertexCallList;
vertexCallList = serverContext.createVertexCallList();
polygonUtil.loadOBJWithTextureMap("C:/Data/SampleObject.obj", "C:/Data/TextureMap.jpg", vertexCallList, hdrcPolygonUtilContext.SMOOTH_MODE_NOP);