OBJDataHandle (object)

The OBJDataHandle is used to expose a C++ library for opening and loading obj files.

参考

FbxHandle

OBJDataHandle OBJDataHandle OBJDataHandle

Members

Data handle  
/*
** Example: OBJDataHandle
*/

require FabricOBJ;
require FileIO;
require Geometry;

function parseObjPolygonMesh(
  io OBJDataHandle objHandle,
  ImporterIdentifier identifier,
  io PolygonMesh mesh
) {
  UInt32 i, j, k, src;

  Size polySizes[];
  Size packedPolyPoints[];
  Size packedPolyAttrIndices[];

  objHandle.getEntityFaceTopologyIndices( identifier.index, packedPolyPoints );
  objHandle.getEntityFaceIndices( identifier.index, packedPolyAttrIndices );
  objHandle.getEntityFaceSizes( identifier.index, polySizes );

  UInt32 nbPoly = polySizes.size();
  UInt32 nbPoints = 0;
  for( i = 0; i < packedPolyPoints.size(); ++i ) {
    if( UInt32(packedPolyPoints[i]) >= nbPoints )
      nbPoints = packedPolyPoints[i]+1;
  }
  mesh.createPoints( nbPoints );
  mesh.addPolygons( polySizes, packedPolyPoints );

  Vec3 vec3Data[];
  Ref<Vec3Attribute> normals = mesh.getOrCreateNormals();

  objHandle.getEntityPoints( identifier.index, vec3Data );
  BitVector initPos;
  initPos.resize(nbPoints);
  src = 0;
  for( i = 0; i < nbPoly; ++i ) {
    UInt32 polSize = UInt32(polySizes[i]);
    for( j = 0; j < polSize; ++j ) {
      UInt32 point = mesh.getPolygonPoint( i, j );
      if( !initPos.get(point) ) {
        initPos.set(point);
        UInt32 srcIndex = packedPolyAttrIndices[src];
        mesh.setPointPosition( point, vec3Data[srcIndex] );
      }
      src++;
    }
  }
  objHandle.getEntityNormals( identifier.index, vec3Data );

  mesh.setAttributeFromPolygonPackedData( "normals", vec3Data, packedPolyAttrIndices );

  Boolean hasTextureCoords = false;
  objHandle.hasTextureCoords( hasTextureCoords );

  if( hasTextureCoords ) {
    Vec2 vec2Data[];
    objHandle.getEntityTextureCoords( identifier.index, vec2Data );
    mesh.setAttributeFromPolygonPackedData( "uvs0", vec2Data, packedPolyAttrIndices );
  }
}


operator entry(){
  // Load an Fbx file to provide the clip data. 

  FilePath path = FilePath("${FABRIC_SCENE_GRAPH_DIR}/Python/Apps/Resources/Obj/cow.obj").expandEnvVars();
  OBJDataHandle objHandle();
  ImporterOptions options;
  objHandle.openFileHandle(path.string(), options);

  ImporterIdentifier identifiers[];
  objHandle.getIdentifiers(identifiers);

  Size nbPts, nbTris;
  objHandle.getNbEntityPoints(-1, nbPts);
  objHandle.getNbEntityFaces(-1, nbTris);
  report("OBJ : " + identifiers.size() + " identifiers: " + nbPts + " vertices, " + nbTris + " triangles");
  
  String materialNames[];
  objHandle.getMaterialNames( materialNames );
  report("materialNames:" + materialNames);

  for( Size i = 0; i < identifiers.size(); ++i ) {
    objHandle.getNbEntityPoints(i, nbPts);
    objHandle.getNbEntityFaces(i, nbTris);
    String name = (identifiers[i].name != "" ? identifiers[i].name : "(none)");
    String groupName = (identifiers[i].getStringData("groupName") != "" ? identifiers[i].getStringData("groupName") : "(none)");
    String matName = (identifiers[i].getStringData("materialName") != "" ? identifiers[i].getStringData("materialName") : "(none)");
    report("  Entity #" + i + ": objName: " + name + ", groupName: " + groupName  + ", matName: " + matName + ", " + nbPts + " vertices, " + nbTris + " triangles");
  }

  PolygonMesh meshes[];
  meshes.resize(identifiers.size());
  for( Size i = 0; i < identifiers.size(); ++i ) {
    meshes[i] = PolygonMesh();
    parseObjPolygonMesh(objHandle, identifiers[i], meshes[i]);
    meshes[i]._validate();
  }
}

/*
** Output:

OBJ : 1 identifiers: 0 vertices, 0 triangles
materialNames:[]
  Entity #0: objName: (none), groupName: (none), matName: (none), 0 vertices, 0 triangles

*/

Methods

  OBJDataHandle ( in OBJDataHandle other )
  OBJDataHandle ()
  clear ! ()
OBJDataHandle clone ? ()
  getEntityFaceIndices ! ( in Integer entity, out Size faceIndices[] )
  getEntityFaceMaterialIndices ! ( in Integer entity, out Size triangleIndices[] )
  getEntityFaceSizes ! ( in Integer entity, out Size faceSizes[] )
  getEntityFaceTopologyIndices ! ( in Integer entity, out Size faceIndices[] )
  getEntityNormals ! ( in Integer entity, out Vec3 normals[] )
  getEntityNormalsSliced ! ( in Integer entity, out Vec3 normals<> )
  getEntityPoints ! ( in Integer entity, out Vec3 points[] )
  getEntityPointsSliced ! ( in Integer entity, out Vec3 points<> )
  getEntityTextureCoords ! ( in Integer entity, out Vec2 texCoords[] )
  getEntityTextureCoordsSliced ! ( in Integer entity, out Vec2 texCoords<> )
  getIdentifiers ! ( io ImporterIdentifier identifiers[] )
  getMaterialNames ! ( out String materialNames[] )
  getNbEntityFaces ! ( in Integer entity, out Size nbTriangles )
  getNbEntityPoints ! ( in Integer entity, out Size nbPoints )
  hasTextureCoords ! ( out Boolean hasTextureCoords )
  isValid ! ( out Boolean valid )
  openFileHandle ! ( in String filePath, in ImporterOptions options )
  ~OBJDataHandle ()

Methods in detail

OBJDataHandle ( in OBJDataHandle other )

copy constructor


OBJDataHandle ()

default constructor


OBJDataHandle.clear! ()


OBJDataHandle OBJDataHandle.clone? ()

clone method


OBJDataHandle.getEntityFaceIndices! ( in Integer entity, out Size faceIndices[] )


OBJDataHandle.getEntityFaceMaterialIndices! ( in Integer entity, out Size triangleIndices[] )


OBJDataHandle.getEntityFaceSizes! ( in Integer entity, out Size faceSizes[] )


OBJDataHandle.getEntityFaceTopologyIndices! ( in Integer entity, out Size faceIndices[] )


OBJDataHandle.getEntityNormals! ( in Integer entity, out Vec3 normals[] )


OBJDataHandle.getEntityNormalsSliced! ( in Integer entity, out Vec3 normals<> )


OBJDataHandle.getEntityPoints! ( in Integer entity, out Vec3 points[] )


OBJDataHandle.getEntityPointsSliced! ( in Integer entity, out Vec3 points<> )


OBJDataHandle.getEntityTextureCoords! ( in Integer entity, out Vec2 texCoords[] )


OBJDataHandle.getEntityTextureCoordsSliced! ( in Integer entity, out Vec2 texCoords<> )


OBJDataHandle.getIdentifiers! ( io ImporterIdentifier identifiers[] )


OBJDataHandle.getMaterialNames! ( out String materialNames[] )


OBJDataHandle.getNbEntityFaces! ( in Integer entity, out Size nbTriangles )


OBJDataHandle.getNbEntityPoints! ( in Integer entity, out Size nbPoints )


OBJDataHandle.hasTextureCoords! ( out Boolean hasTextureCoords )


OBJDataHandle.isValid! ( out Boolean valid )


OBJDataHandle.openFileHandle! ( in String filePath, in ImporterOptions options )

Opens the obj file specified by the given path.

filePath The location of the file to open.
options The set of optoins used to configure the obj handle.


~ OBJDataHandle ()