I am trying to understand how to load resources from memory.
I want to dynamically create geometry, load a texture, create a material and attach the texture, then create a mesh node and attach the material.
But how may I load the material? What kind of data is a material resource waiting for?
Code:
h3dLoadResource( materialResource, 0x0, 0 );
Here is my code
Code:
// Create a geometry resource
H3DRes geometryResource = h3dutCreateGeometryRes( name.c_str(), num_vertices, num_indices, &positionData[0], &indexData[0], &normalData[0], 0x0, 0x0, &textureData[0], 0x0 );
if ( !geometryResource )
return 0x0;
// Add a new texture resource, with parameter source as the name/filename
H3DRes textureResource = h3dAddResource( H3DResTypes::Texture, source.c_str(), H3DResFlags::NoTexMipmaps );
if ( !textureResource )
{
h3dRemoveResource( geometryResource );
return 0x0;
}
// Load the file from disk, ensure we have at least one ImageElem resource element
if ( !h3dutLoadResourcesFromDisk( _contentDir.c_str() ) || h3dGetResElemCount( textureResource, H3DTexRes::ImageElem ) < 1 )
{
h3dRemoveResource( textureResource );
h3dRemoveResource( geometryResource );
return 0x0;
}
// Create a model scene node and attach the geometry
H3DNode modelNode = h3dAddModelNode( H3DRootNode, (name + "Model").c_str(), geometryResource );
if ( !modelNode )
{
h3dRemoveResource( textureResource );
h3dRemoveResource( geometryResource );
return 0x0;
}
h3dSetNodeParamI( modelNode, H3DModel::GeoResI, geometryResource ); // attach geometry
// Create a material resource and attach the texture
H3DRes materialResource = h3dAddResource( H3DResTypes::Material, (name + "Material").c_str(), 0 );
if ( !materialResource )
{
h3dRemoveNode( modelNode );
h3dRemoveResource( textureResource );
h3dRemoveResource( geometryResource );
return 0x0;
}
h3dSetResParamI( materialResource, H3DMatRes::SamplerElem, 0, H3DMatRes::SampTexResI, textureResource ); // attach texture
h3dSetResParamStr( materialResource, H3DMatRes::SamplerElem, 0, H3DMatRes::SampNameStr, (name + "Sampler").c_str() );
// ????? Load the material resource ?????
bool resourceLoaded = h3dLoadResource( materialResource, 0x0, 0 );
// Create a mesh node and attach the material resource
H3DNode meshNode = h3dAddMeshNode( modelNode, (name + "Mesh").c_str(), materialResource, 0, num_indices, 0, num_vertices-1 );
if ( !meshNode )
{
h3dRemoveResource( materialResource );
h3dRemoveNode( modelNode );
h3dRemoveResource( textureResource );
h3dRemoveResource( geometryResource );
return 0x0;
}
So how should I create the data for a material? What data is it looking for?
What I really want to know is, how can I do it dynamically in code without using xml files or any files at all (except the image file)?