def test_R6_SOB_Structure(self):
        """Tests reading an R6 SOB file, specifically ak47.sob"""
        settings = load_settings(TEST_SETTINGS_FILE)

        sob_filepath = path.join(settings["gamePath_R6"], "data", "model",
                                 "ak47.sob")

        loadedFile = SOBModelReader.SOBModelFile()
        readSucessfullyToEOF = loadedFile.read_file(sob_filepath)

        self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

        self.check_section_strings(loadedFile)

        self.assertEqual(loadedFile.materialListHeader.numMaterials, 7,
                         "Unexpected number of materials in header")

        self.assertEqual(len(loadedFile.materials), 7,
                         "Unexpected number of materials read")

        self.assertEqual(loadedFile.materials[0].material_name.string,
                         "aK barell", "Unexpected material name")

        self.assertEqual(loadedFile.materials[0].texture_name.string,
                         "AK47_BARREL_32.BMP", "Unexpected material name")

        self.assertEqual(len(loadedFile.geometryObjects), 1,
                         "Unexpected number of geometry objects")

        self.assertEqual(loadedFile.geometryObjects[0].name_string.string,
                         "AK47", "Unexpected object name")

        self.assertEqual(loadedFile.geometryObjects[0].vertexCount, 81,
                         "Unexpected number of vertices")
def convert_SOB(filename):
    """ Reads an SOB file and then writes to OBJ format """
    print("Processing: " + filename)

    modelFile = SOBModelReader.SOBModelFile()
    modelFile.read_file(filename)

    meta = JSONMetaInfo.JSONMetaInfo()
    meta.add_info("filecontents", modelFile)
    meta.add_info("filename", filename)
    newFilename = filename + ".JSON"
    meta.writeJSON(newFilename)

    countBadNormals = 0
    countGoodNormals = 0
    for geoObj in modelFile.geometryObjects:
        for vertexParam in geoObj.vertexParams:
            if is_vector_normal(vertexParam.normal):
                countGoodNormals += 1
            else:
                countBadNormals += 1

    print("Num bad normals: " + str(countBadNormals))
    print("Num good normals: " + str(countGoodNormals))

    write_OBJ(filename + ".obj", modelFile)

    print("===============================================")
    def test_load_all_R6_SOBs(self):
        """Attempt to load and validate the sections of each map in the directory"""
        settings = load_settings(TEST_SETTINGS_FILE)

        discovered_files = gather_files_in_path(".SOB",
                                                settings["gamePath_R6_EW"])

        for sob_filepath in discovered_files:
            loadedFile = SOBModelReader.SOBModelFile()
            readSucessfullyToEOF = loadedFile.read_file(sob_filepath)

            self.assertTrue(readSucessfullyToEOF, "Failed to read whole file")

            self.check_section_strings(loadedFile)
Ejemplo n.º 4
0
def import_SOB_to_scene(filename: str):
    """Opens SOB file and imports all relevant information"""
    SOBObject = SOBModelReader.SOBModelFile()
    SOBObject.read_file(filename)

    log.info("Beginning import")

    texturePaths = R6Settings.get_relevant_global_texture_paths(filename)

    blenderMaterials = BlenderUtils.create_blender_materials_from_list(
        SOBObject.materials, texturePaths)

    for geoObj in SOBObject.geometryObjects:
        create_objects_from_R6GeometryObject(geoObj, blenderMaterials)

    log.info("Success")
Ejemplo n.º 5
0
    def load_model(self):
        """Loads the file and creates appropriate assets in unreal"""
        self.filepath = "D:/R6Data/TestData/ReducedGames/R6GOG/data/model/cessna.sob"
        SOBFile = SOBModelReader.SOBModelFile()
        SOBFile.read_file(self.filepath)
        numGeoObjects = len(SOBFile.geometryObjects)
        ue.log("Num geoObjects: {}".format(numGeoObjects))

        ue.log("material definitions: " + str(len(SOBFile.materials)))
        self.materialDefinitions = SOBFile.materials
        self.LoadMaterials()

        for _, geoObj in enumerate(SOBFile.geometryObjects):
            name = geoObj.nameString

            ue.log("Processing geoobj: " + name)
            geoObjComponent = self.uobject.add_actor_component(
                SceneComponent, name, self.defaultSceneComponent)
            self.uobject.add_instance_component(geoObjComponent)
            self.uobject.modify()
            self.objectComponents.append(geoObjComponent)

            for srcMeshIdx, sourceMesh in enumerate(geoObj.meshes):
                renderableName = name + "_" + sourceMesh.nameString + "_" + str(
                    srcMeshIdx)
                currRenderables = geoObj.generate_renderable_arrays_for_mesh(
                    sourceMesh)

                mergedRenderables = merge_renderables_by_material(
                    currRenderables)

                newMeshComponent = self.import_renderables_as_mesh_component(
                    renderableName, mergedRenderables, self.shift_origin,
                    geoObjComponent)

                set_rse_geometry_flags_on_mesh_component(
                    newMeshComponent, False, sourceMesh.geometryFlagsEvaluated)