original_docstring: Performs the conversion.
  
          Call this function after initializing the Vox2UsdConverter object run the conversion.
          
docstring: Performs the conversion.
  Call this function after initializing the Vox2UsdConverter object run the conversion.
docstring_tokens: Performs the conversion . Call this function after initializing the Vox2UsdConverter object run the conversion .
code: def convert(self):
          """Performs the conversion.
  
          Call this function after initializing the Vox2UsdConverter object run the conversion.
          """
          print("\nImporting voxel file {}\n".format(self.vox_file_path))
  
          import time
          time_start = time.time()
          VoxReader(self.vox_file_path).read()
  
          print("Starting conversion...")
          stage_layer = Sdf.Layer.CreateNew(os.path.join(self.output_dir, self.output_file_name), args={"format": "usda"})
          self.model_stage = Usd.Stage.Open(stage_layer.identifier)
          UsdGeom.SetStageUpAxis(self.model_stage, UsdGeom.Tokens.z)
          UsdGeom.SetStageMetersPerUnit(self.model_stage, 1.0)
          asset_geom = UsdGeom.Xform.Define(self.model_stage, "/" + self.asset_name)
          self.model_stage.SetDefaultPrim(asset_geom.GetPrim())
          model_api = Usd.ModelAPI(asset_geom)
          model_api.SetKind(Kind.Tokens.component)
          model_api.SetAssetName(self.asset_name)
          model_api.SetAssetIdentifier(self.output_file_name)
          self.geometry_scope = UsdGeom.Scope.Define(self.model_stage, asset_geom.GetPath().AppendPath(GEOMETRY_SCOPE_NAME))
          self.looks_scope = UsdGeom.Scope.Define(self.model_stage, asset_geom.GetPath().AppendPath(LOOKS_SCOPE_NAME))
  
          self.geo_varset = asset_geom.GetPrim().GetVariantSets().AddVariantSet("Geometry")
          for variant_name in GeometryVariantSetNames.values():
              self.geo_varset.AddVariant(variant_name)
  
          self.geo_varset.SetVariantSelection(GeometryVariantSetNames.POINT_INSTANCES)
          with self.geo_varset.GetVariantEditContext():
              self.point_shape_varset = asset_geom.GetPrim().GetVariantSets().AddVariantSet("PointShape")
              for variant_name in PointShapeVariantSetNames.values():
                  self.point_shape_varset.AddVariant(variant_name)
          self.shader_varset = asset_geom.GetPrim().GetVariantSets().AddVariantSet("Shader")
          for variant_name in ShaderVariantSetNames.values():
              self.shader_varset.AddVariant(variant_name)
  
          GreedyMeshing.generate(self.voxel_size)
  
          for index in VoxBaseMaterial.used_palette_ids:
              mtl = VoxBaseMaterial.get(index)
              mtl = self.create_material("VoxelMtl_{}".format(mtl.get_display_id()), mtl)
              self.used_mtls[index] = {
                   "mtl": mtl,
                   GeometryVariantSetNames.MERGED_MESHES: [],
                   GeometryVariantSetNames.POINT_INSTANCES: {
                       PointShapeVariantSetNames.CUBES: [],
                       PointShapeVariantSetNames.SPHERES: [],
                       PointShapeVariantSetNames.STUDS: []
                   }
              }
  
          mesh_stage = Usd.Stage.CreateNew(self.mesh_payload_identifier)
          points_stage = Usd.Stage.CreateNew(self.points_payload_identifier)
  
          root_xform_node = VoxTransform.get_top_nodes()[0]
          root_group_node = root_xform_node.get_child()
  
          self._convert_node(mesh_stage, root_xform_node, mesh_stage.GetPseudoRoot(), self._voxels2mesh)
          self._convert_node(points_stage, root_xform_node, points_stage.GetPseudoRoot(), self._voxels2point_instances)
  
          default_prim = mesh_stage.GetPrimAtPath(mesh_stage.GetPseudoRoot().GetPath().AppendPath("VoxelGroup_{}".format(root_group_node.node_id)))
          mesh_stage.SetDefaultPrim(default_prim)
          default_prim = points_stage.GetPrimAtPath(points_stage.GetPseudoRoot().GetPath().AppendPath("VoxelGroup_{}".format(root_group_node.node_id)))
          points_stage.SetDefaultPrim(default_prim)
          mesh_stage.Save()
          points_stage.Save()
  
          voxel_root_path = self.geometry_scope.GetPath().AppendChild("VoxelRoot")
          self.voxel_root = self.model_stage.OverridePrim(voxel_root_path)
  
          self.geo_varset.SetVariantSelection(GeometryVariantSetNames.MERGED_MESHES)
          with self.geo_varset.GetVariantEditContext():
              self.voxel_root.GetPayloads().AddPayload(Sdf.Payload("./{}.mesh.usdc".format(self.asset_name)))
          self.geo_varset.SetVariantSelection(GeometryVariantSetNames.POINT_INSTANCES)
          with self.geo_varset.GetVariantEditContext():
              self.voxel_root.GetPayloads().AddPayload(Sdf.Payload("./{}.points.usdc".format(self.asset_name)))
  
          for mtl_id, item in self.used_mtls.items():
              mtl = item["mtl"]
              merged_mesh_targets = item[GeometryVariantSetNames.MERGED_MESHES]
              proto_targets = item[GeometryVariantSetNames.POINT_INSTANCES]
  
              self.geo_varset.SetVariantSelection(GeometryVariantSetNames.MERGED_MESHES)
              with self.geo_varset.GetVariantEditContext():
                  for target_path in merged_mesh_targets:
                      target_prim = self._get_target_prim(target_path)
                      UsdShade.MaterialBindingAPI(target_prim).Bind(mtl)
              self.geo_varset.SetVariantSelection(GeometryVariantSetNames.POINT_INSTANCES)
              with self.geo_varset.GetVariantEditContext():
                  for pt_shape_variant in PointShapeVariantSetNames.values():
                      self._bind_mtl_to_prototypes(mtl, proto_targets, pt_shape_variant)
  
          if self.flatten:
              self.geo_varset.SetVariantSelection(GeometryVariantSetNames.MERGED_MESHES)
              self.shader_varset.SetVariantSelection(ShaderVariantSetNames.PREVIEW)
              self.model_stage.Export(os.path.join(self.output_dir, self.output_file_name), args={"format": "usdc"})
              del self.model_stage
              del mesh_stage
              del points_stage
              os.remove(self.mesh_payload_identifier)
              os.remove(self.points_payload_identifier)
          else:
              self.geo_varset.SetVariantSelection(GeometryVariantSetNames.MERGED_MESHES)
              self.shader_varset.SetVariantSelection(ShaderVariantSetNames.OMNIVERSE)
              self.point_shape_varset.SetVariantSelection(PointShapeVariantSetNames.CUBES)
              self.model_stage.Save()
  
          print("Converted {} total voxels".format(self.total_voxels))
          print("Converted {} total triangles".format(self.total_triangles))
          print("\nSuccessfully converted {} in {:.3f} sec".format(self.vox_file_path, time.time() - time_start))
code_tokens: def convert ( self ) : print ( "\nImporting voxel file {}\n" . format ( self . vox_file_path ) ) import time time_start = time . time ( ) VoxReader ( self . vox_file_path ) . read ( ) print ( "Starting conversion..." ) stage_layer = Sdf . Layer . CreateNew ( os . path . join ( self . output_dir , self . output_file_name ) , args = { "format" : "usda" } ) self . model_stage = Usd . Stage . Open ( stage_layer . identifier ) UsdGeom . SetStageUpAxis ( self . model_stage , UsdGeom . Tokens . z ) UsdGeom . SetStageMetersPerUnit ( self . model_stage , 1.0 ) asset_geom = UsdGeom . Xform . Define ( self . model_stage , "/" + self . asset_name ) self . model_stage . SetDefaultPrim ( asset_geom . GetPrim ( ) ) model_api = Usd . ModelAPI ( asset_geom ) model_api . SetKind ( Kind . Tokens . component ) model_api . SetAssetName ( self . asset_name ) model_api . SetAssetIdentifier ( self . output_file_name ) self . geometry_scope = UsdGeom . Scope . Define ( self . model_stage , asset_geom . GetPath ( ) . AppendPath ( GEOMETRY_SCOPE_NAME ) ) self . looks_scope = UsdGeom . Scope . Define ( self . model_stage , asset_geom . GetPath ( ) . AppendPath ( LOOKS_SCOPE_NAME ) ) self . geo_varset = asset_geom . GetPrim ( ) . GetVariantSets ( ) . AddVariantSet ( "Geometry" ) for variant_name in GeometryVariantSetNames . values ( ) : self . geo_varset . AddVariant ( variant_name ) self . geo_varset . SetVariantSelection ( GeometryVariantSetNames . POINT_INSTANCES ) with self . geo_varset . GetVariantEditContext ( ) : self . point_shape_varset = asset_geom . GetPrim ( ) . GetVariantSets ( ) . AddVariantSet ( "PointShape" ) for variant_name in PointShapeVariantSetNames . values ( ) : self . point_shape_varset . AddVariant ( variant_name ) self . shader_varset = asset_geom . GetPrim ( ) . GetVariantSets ( ) . AddVariantSet ( "Shader" ) for variant_name in ShaderVariantSetNames . values ( ) : self . shader_varset . AddVariant ( variant_name ) GreedyMeshing . generate ( self . voxel_size ) for index in VoxBaseMaterial . used_palette_ids : mtl = VoxBaseMaterial . get ( index ) mtl = self . create_material ( "VoxelMtl_{}" . format ( mtl . get_display_id ( ) ) , mtl ) self . used_mtls [ index ] = { "mtl" : mtl , GeometryVariantSetNames . MERGED_MESHES : [ ] , GeometryVariantSetNames . POINT_INSTANCES : { PointShapeVariantSetNames . CUBES : [ ] , PointShapeVariantSetNames . SPHERES : [ ] , PointShapeVariantSetNames . STUDS : [ ] } } mesh_stage = Usd . Stage . CreateNew ( self . mesh_payload_identifier ) points_stage = Usd . Stage . CreateNew ( self . points_payload_identifier ) root_xform_node = VoxTransform . get_top_nodes ( ) [ 0 ] root_group_node = root_xform_node . get_child ( ) self . _convert_node ( mesh_stage , root_xform_node , mesh_stage . GetPseudoRoot ( ) , self . _voxels2mesh ) self . _convert_node ( points_stage , root_xform_node , points_stage . GetPseudoRoot ( ) , self . _voxels2point_instances ) default_prim = mesh_stage . GetPrimAtPath ( mesh_stage . GetPseudoRoot ( ) . GetPath ( ) . AppendPath ( "VoxelGroup_{}" . format ( root_group_node . node_id ) ) ) mesh_stage . SetDefaultPrim ( default_prim ) default_prim = points_stage . GetPrimAtPath ( points_stage . GetPseudoRoot ( ) . GetPath ( ) . AppendPath ( "VoxelGroup_{}" . format ( root_group_node . node_id ) ) ) points_stage . SetDefaultPrim ( default_prim ) mesh_stage . Save ( ) points_stage . Save ( ) voxel_root_path = self . geometry_scope . GetPath ( ) . AppendChild ( "VoxelRoot" ) self . voxel_root = self . model_stage . OverridePrim ( voxel_root_path ) self . geo_varset . SetVariantSelection ( GeometryVariantSetNames . MERGED_MESHES ) with self . geo_varset . GetVariantEditContext ( ) : self . voxel_root . GetPayloads ( ) . AddPayload ( Sdf . Payload ( "./{}.mesh.usdc" . format ( self . asset_name ) ) ) self . geo_varset . SetVariantSelection ( GeometryVariantSetNames . POINT_INSTANCES ) with self . geo_varset . GetVariantEditContext ( ) : self . voxel_root . GetPayloads ( ) . AddPayload ( Sdf . Payload ( "./{}.points.usdc" . format ( self . asset_name ) ) ) for mtl_id , item in self . used_mtls . items ( ) : mtl = item [ "mtl" ] merged_mesh_targets = item [ GeometryVariantSetNames . MERGED_MESHES ] proto_targets = item [ GeometryVariantSetNames . POINT_INSTANCES ] self . geo_varset . SetVariantSelection ( GeometryVariantSetNames . MERGED_MESHES ) with self . geo_varset . GetVariantEditContext ( ) : for target_path in merged_mesh_targets : target_prim = self . _get_target_prim ( target_path ) UsdShade . MaterialBindingAPI ( target_prim ) . Bind ( mtl ) self . geo_varset . SetVariantSelection ( GeometryVariantSetNames . POINT_INSTANCES ) with self . geo_varset . GetVariantEditContext ( ) : for pt_shape_variant in PointShapeVariantSetNames . values ( ) : self . _bind_mtl_to_prototypes ( mtl , proto_targets , pt_shape_variant ) if self . flatten : self . geo_varset . SetVariantSelection ( GeometryVariantSetNames . MERGED_MESHES ) self . shader_varset . SetVariantSelection ( ShaderVariantSetNames . PREVIEW ) self . model_stage . Export ( os . path . join ( self . output_dir , self . output_file_name ) , args = { "format" : "usdc" } ) del self . model_stage del mesh_stage del points_stage os . remove ( self . mesh_payload_identifier ) os . remove ( self . points_payload_identifier ) else : self . geo_varset . SetVariantSelection ( GeometryVariantSetNames . MERGED_MESHES ) self . shader_varset . SetVariantSelection ( ShaderVariantSetNames . OMNIVERSE ) self . point_shape_varset . SetVariantSelection ( PointShapeVariantSetNames . CUBES ) self . model_stage . Save ( ) print ( "Converted {} total voxels" . format ( self . total_voxels ) ) print ( "Converted {} total triangles" . format ( self . total_triangles ) ) print ( "\nSuccessfully converted {} in {:.3f} sec" . format ( self . vox_file_path , time . time ( ) - time_start ) )
short_docstring: Performs the conversion.
short_docstring_tokens: Performs the conversion .
comment: """Performs the conversion.
  
          Call this function after initializing the Vox2UsdConverter object run the conversion.
          """