Having thought about it, this is my best idea.
Firstly, as the mesh is read-only you will need to create a new mesh node every time you use a new geometry.
So when the node becomes invisible only remove the (child) mesh node, but not the (parent) model node. The model node can set the geometry to the static dummy geometry.
Quote:
Then the resource can not freed. (the scene node referenced the resource too)
Hopefully when you remove the mesh node and when you change the model node geometry to the dummy geometry with
Code:
h3dRemoveNode( meshNode );
h3dSetNodeParamI( modelNode, H3DModel::GeoResI, dummyGeometryResource );
it will decrease the reference count to the geometry each time.
If not, try using
Code:
int h3dRemoveResource( H3DRes res );
to decrease the reference count. The function returns the reference count, so you can know how many more times it may need to be called.
After doing the above, unload the geometry resource.
I assume that you are using h3dReleaseUnusedResources regularly to free the resources ?
When the node is becoming visible again you load the geometry and then attach the loaded geometry to the parent model node using h3dSetNodeParamI again.
Then create a new mesh node and attach to the model node.