Jump to content

problems with saving the node


photo

Recommended Posts

Hello.
I create a software mesh, fill it with vertices, indexes, texture coordinates,
and save it to a file,
then I create the material and also save it to a file,
then create a node through a function
Unigine :: ObjectMeshStatic :: create (mesh)
set the material for it, then

UGUID & guid = Unigine :: FileSystem :: get () -> getGUID (mesh_name.c_str ());
node-> setMeshName (guid.getFileSystemString ());

but the guide returns "guide: //"
therefore, when called

world-> saveNode (name.c_str (), node-> getNode ()))
the mesh is not saved in the node file

what could be the problem?

why does the preservation of such objects as a mesh, node, property, material depend at all?

in the SDK conditions are not specified

Link to comment

mesh class
why method: static MeshPtr create (const char * name)
works like: int load (const char * name) ?
shouldn't he re-create the mesh and not load it?

Link to comment

Hi Silent,
initially, the node pointer was not saved in the node when it was saved.
I realized that this was due to the fact that I was trying to save the node outside the "date" directory.
Now when saving the node inside the "date" directory, a pointer to the mesh (guide) is written in the node file but this guide does not match the guide of the previously saved mesh.
An interesting feature is observed when saving the material - instead of saving the guide or path to the texture to be set - do you keep the pointer to the white texture in the material file? (this is if you use the setTextureImage function), when using the setTexture function, the pointer is not saved at all

//save material

           MaterialPtr mesh_base;
            if (!(mesh_base = materials->findMaterial(parent_mat_name.c_str())))
            {
                   mesh_base = materials->findMaterial("mesh_base");
            }
            // inherit a new material from it
            material_shape = mesh_base->inherit(material_name.c_str(), name.c_str());         

           Unigine::String full_absolut_path = Unigine::FileSystem::get()->getAbsolutePath(texture_name.c_str());
            ImagePtr image = Image::create();
            if (image->load(full_absolut_path))
            {
                Unigine::TexturePtr mat_texture = Unigine::Texture::create();
                mat_texture->create(image);
                int num = material_shape->findTexture("albedo");
                if (num != -1)
                {
                    //material_shape->setTexture(num, mat_texture);
                    int res = false;
                    if (!(res = material_shape->setTextureImage(num, image)))
                    {
                        MessageBox("Convert Error", "Can't save texture to material \"%s\" file", texture_name);
                    }
                }
            }

           full_absolut_path = Unigine::FileSystem::get()->getAbsolutePath(name.c_str());
           if (material_shape->canSave())
            {
                if (!material_shape->save(full_absolut_path))
                    MessageBox("Convert Error","Can't save material \"%s\" file", name);
            }

        sMateral sm;
        sm.MaterialName = material_shape->getName();
        sm.MaterialGUID = material_shape->getFileGUID();
        sm.SurfaceName = _mesh->getSurfaceName(last_surface);
        materilas.push_back(sm);

        material_shape->release();
        material_shape->grab();

// saved file *.mat

<?xml version="1.0" encoding="utf-8"?>
<material version="2.7.3.0" name="AngarSaray2" guid="05a532d682635621daf0fc6296bda6630e96a5c8" base_material="mesh_base">
    <texture name="albedo">core/textures/common/white.dds</texture>
</material>

//--------------------------------------------------------------------

//another function

//save mesh

if (mesh->save(mesh_name) == 0)
    {
        MessageBox("Export Error", "Can't save \"%s\" file", mesh_name);
        return false;
    }

// save node

    Unigine::ObjectMeshStaticPtr node = Unigine::ObjectMeshStatic::create(mesh);
     node->setName(name_node);
              if (materilas.size() > 0)
                        {
                            for (int i = 0; i < mesh->getNumSurfaces(); i++)
                            {
                                node->setMaterial(materilas.MaterialGUID, i);
                            }
                        }

       UGUID guid = Unigine::FileSystem::get()->getGUID(mesh_name.c_str());
       node->setMeshName(guid.getFileSystemString());
       Unigine::String full_absolut_path = Unigine::FileSystem::get()->getAbsolutePath(file_name_node.c_str());
        if (!world->saveNode(full_absolut_path, node->getNode()))
          {
                MessageBox("!!!Error save node ", file_name_node);
          }
      node.destroy();

//saved node file

<?xml version="1.0" encoding="utf-8"?>
<nodes version="2.7.3.0">
    <node type="ObjectMeshStatic" id="13139810" name="AngarSaray2">
        <mesh_name>guid://317456c776a691cadaaf8b379ff441e433e0fd87</mesh_name>
        <surface name="ifsANGARSARAY2" material="5315e8acd2c4dc7dddfae459d8fb040dff5ad3b6"/>
        <transform>1 0 0 0.0 0 1 0 0.0 0 0 1 0.0 0 0 0 1.0</transform>
    </node>
</nodes>

 

in saved files
the material guide does not match (material guide in *. node and guide in *. mat)
in the material file, the name of the texture does not match the one recorded in the image
and the mesh guide in the file node does not match the file itself

in unigine log

---- UNIGINE Editor 2 ----

Version: 1.1

Script loading "editor2/editor.usc" 51ms

---- Interpreter ----

Version: 2.90

Unigine~# config_readonly 0

Script loading "core/unigine.usc" 29ms

Loading "core/locale/unigine.locale" dictionary 0ms

Mesh::info(): unknown format of "guid://317456c776a691cadaaf8b379ff441e433e0fd87" file

Xml::printUnusedData(): unused argument "material=5315e8acd2c4dc7dddfae459d8fb040dff5ad3b6" in "surface" node in "CObjects/AngarSaray2/AngarSaray2.node" file

Xml::printUnusedData(): unused argument "material=5315e8acd2c4dc7dddfae459d8fb040dff5ad3b6" in "surface" node in "CObjects/AngarSaray2/AngarSaray2.node" file

Link to comment

Thanks for the test code.

You need to update guids.db file after you finished with files (when GUIDS are generated and files are saved to disk). You can do it via following code:

Unigine::FileSystem::get()->saveGUIDs("guids.db", false);

After that engine runtime should be able to load all your files.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Are you sure that the matter is in guides.db
because in the metafile of the mesh and the node file  the guides do not match

//file node

<?xml version="1.0" encoding="utf-8"?>
<nodes version="2.7.3.0">
    <node type="ObjectMeshStatic" id="13139810" name="AngarSaray2">
        <mesh_name>guid://317456c776a691cadaaf8b379ff441e433e0fd87</mesh_name>
        <surface name="ifsANGARSARAY2" material="5315e8acd2c4dc7dddfae459d8fb040dff5ad3b6"/>
        <transform>1 0 0 0.0 0 1 0 0.0 0 0 1 0.0 0 0 0 1.0</transform>
    </node>
</nodes>

// meta file mesh

<?xml version="1.0" encoding="utf-8"?>
<asset version="2.7.3.0">
    <guid>fe1a78a91f9e9ad79ca275d918b525f3759e151b</guid>
    <type>mesh</type>
    <hash>531270bb</hash>
    <parameters>
        <parameter type="bool" name="unchanged">1</parameter>
        <parameter type="float" name="scale">1</parameter>
        <parameter type="bool" name="animation">1</parameter>
        <parameter type="bool" name="vertex_cache">1</parameter>
    </parameters>
    <runtimes>
        <runtime id="fe1a78a91f9e9ad79ca275d918b525f3759e151b" name="AngarSaray2.mesh" link="0"/>
    </runtimes>
</asset>

the same situation with the material guide

//material file

<?xml version="1.0" encoding="utf-8"?>
<material version="2.7.3.0" name="AngarSaray2" guid="05a532d682635621daf0fc6296bda6630e96a5c8" base_material="mesh_base">
    <texture name="albedo">core/textures/common/white.dds</texture>
</material>

// meta file material

<?xml version="1.0" encoding="utf-8"?>
<asset version="2.7.3.0">
    <guid>05a532d682635621daf0fc6296bda6630e96a5c8</guid>
    <type>material</type>
    <hash>36232104</hash>
    <runtimes>
        <runtime id="05a532d682635621daf0fc6296bda6630e96a5c8" name="AngarSaray2" link="0"/>
    </runtimes>
</asset>

as you can see from the files, for some reason the unigine saves different guides

about guides.db
  Do I need to call this function before every file save?
Unigine :: FileSystem :: get () -> saveGUIDs ("guids.db", false);

Link to comment
Quote

about guides.db
  Do I need to call this function before every file save?

You need to do this after you finished to modify and save files to disk.

Quote

if I create two identical mesh files, then I get different guides and correspondingly different meta files from them, how should it be?

The whole point of GUID-based file system is to have unique identifiers for each file (even if files are identical). So in this case I would say it's expected behavior.

 

 

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

using the function Unigine :: FileSystem :: get () -> saveGUIDs ("guids.db", false); did not help.

maybe this situation may arise with guides due to the fact that I am performing these operations SystemLogic::init ?

Link to comment

hi, silent, thanks for the offer,
but I found a mistake
it turns out that if you create a mesh or any other element (property, material, etc.) and save it, then the system will assign them guides when saving.
If, after saving, these elements are added to the node, the system will automatically change their guides in the node, so the saved node will no longer be referenced to the saved elements, therefore, the elements of the node need to be saved only after the node itself has been saved.
I just did not find such a description in the SDK, and this is misleading.

Link to comment

Is there a way to control the generation of guides of stored resources (some function that needs to be called after saving the resource so that it generates a guide and meta file)?
I noticed that the generation of guides is not consistent with the conservation of resources, so there are problems with links between resources.
As I understand it, a similar problem was in the subject
https://developer.unigine.com/forum/topic/5000-meta-file-regeneration-does-not-generate-stable-guid/?tab=comments#comment-25717

How to programmatically generate a meta file and save it?

Edited by Vladimir_tyutenkov
Link to comment
Quote

I noticed that the generation of guides is not consistent with the conservation of resources, so there are problems with links between resources.

There is indeed was an issue in 2.7.x releases, however it was fixed in the 2.8.

 

Quote

How to programmatically generate a meta file and save it?

Only Editor can generate this files (there is no Engine API methods to do that). If you need to generate .meta files on your side consider to fill the XML structure on your side manually.

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Editor uses additional internal logics that tied to the whole Asset System workflow to generate GUID. In short: generate GUIDs that will match the Editor GUID pattern is very tricky to achieve. We do not plan to expose these algorithms.

Is there any issues with that?

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

the fact is that the presence of a meta file will uniquely determine the GUID of the resource,
while the usual saving of the resource programmatically can produce a GUID different from the saved one.
therefore, it would be most correct when saving any resource (node, material, property mesh) to immediately generate and save a meta file to it, so that further the resource GUID is always unambiguous and GUID referring to missing resources do not appear.

Such files are further requested to be transferred from project to project.

The presence of only a record in the guide.db does not save the situation when creating new resources, errors may occur

Link to comment

I think the only way is to modify already generated .meta files and replace all GUIDs to a valid values:

<?xml version="1.0" encoding="utf-8"?>
<asset version="2.9.0.0">
	<guid>${GUID}</guid>
	<type>mesh</type>
	<hash>d2627c42</hash>
	<parameters>
		<parameter type="bool" name="unchanged">1</parameter>
		<parameter type="float" name="scale">1</parameter>
		<parameter type="bool" name="animation">1</parameter>
		<parameter type="bool" name="vertex_cache">1</parameter>
	</parameters>
	<runtimes>
		<runtime id="${GUID}" name="test_mesh.mesh" link="0"/>
	</runtimes>
</asset>
<?xml version="1.0" encoding="utf-8"?>
<asset version="2.9.0.0">
	<guid>${GUID}</guid>
	<type>node</type>
	<hash>7313cfdb</hash>
	<runtimes>
		<runtime id="${GUID}" name="test_node.node" link="0"/>
	</runtimes>
</asset>

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...