Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

If you want use a custom mesh format you can extend atoms with a new mesh loader. Atoms supports atoms mesh and alembic mesh formats (from version 2.0). To add a new mesh format you must create a new class definition that extend the Atoms::BaseMeshLoader, then you must register the new loader class inside an atoms plugin


Class definition

#include <Atoms/Globals.h>
#include <AtomsCore/Metadata/MapMetadata.h>
#include <Atoms/Loaders/BaseMeshLoader.h>

#define kFooMeshLoaderId 101

namespace Atoms
{
	class ATOMSPLUGIN_EXPORT FooMeshLoader : public BaseMeshLoader
	{
	public:
		//! Type string
		/*!
		\return Class type string
		*/
		std::string typeStr() const;

		//! Class static type string. This is also the file extension of your file format
		static std::string const staticTypeStr;

		//! Type id
		/*!
		\return Class type id
		*/
		unsigned int typeId() const;

		//! Class static type id
		static const unsigned int staticTypeId;

		//! Constructor
		FooMeshLoader();

		//! Destructor
		~FooMeshLoader();

		//! Creator function
		/*!
		\return Return a new AlembicMeshLoader object
		*/
		static AtomsPtr<BaseMeshLoader> creator();

		//! load
		/*!
		Load an atoms file
		*/
		AtomsPtr<AtomsCore::MapMetadata> load(const std::string &filePath, const std::string& filter = "*");
	};
}

namespace Atoms
{
std::string const FooMeshLoader::staticTypeStr = "foo"; // the file extension

std::string FooMeshLoader::typeStr() const
{
	return FooMeshLoader::staticTypeStr;
}

const unsigned int FooMeshLoader::staticTypeId = kFooMeshLoaderId;

unsigned int FooMeshLoader::typeId() const
{
	return FooMeshLoader::staticTypeId;
}

FooMeshLoader::FooMeshLoader() :
	BaseMeshLoader()
{
}

FooMeshLoader::~FooMeshLoader()
{
}

AtomsPtr<BaseMeshLoader> FooMeshLoader::creator()
{
	return std::dynamic_pointer_cast<BaseMeshLoader>(std::make_shared<FooMeshLoader>());
}

AtomsPtr<AtomsCore::MapMetadata> FooMeshLoader::load(const std::string &filePath, const std::string& filter = "*")
{
	AtomsPtr<AtomsCore::MapMetadata>  skinMeshMetadata(new AtomsCore::MapMetadata);
	std::string fullPath = AtomsUtils::solvePath(filePath);
	std::vector<std::string> filterVec;
	if ((filter != "*") || (filter != ""))
	{
		AtomsUtils::splitString(AtomsUtils::eraseFromString(filter, ' '), ',', filterVec);
	}

	//load your mesh file here and start to fill the mapmetadata
	for (const std::string& geoName: fooGeoFileList)
	{
		//Check if the current geo is passing the filter
		if ((filterVec.size() > 0) && (!AtomsUtils::filterNames(filterVec, geoName)))
			continue;
	}

	...
	return skinMeshMetadata;
}
}


Atoms calls the load function to read the new mesh format. This function must fill and return a MapMetadata with the data read from your mesh file.

This MapMetadata can contain multiple meshes and it must follow this structure:

MapMetadata{
	"geo1":
	MapMetadata{
		"geo": MeshMetadata(), //This is the render/preview geo geo

		"cloth": MeshMetadata(), //If the mesh is a cloth mesh then fill this entry instead the geo

		"jointIndices": (optional)
		ArrayMetadata[ // skin joint ids per vertex, this must have the same length of the points array
			IntArrayMetadata(), // array of joint (influence) indices for the current vertex
			IntArrayMetadata(),
			...
		],

		"jointWeights": (optional)
		ArrayMetadata[ // skin joint weights per vertex, this must have the same length of the points array
			DoubleArrayMetadata(), // array of joint (influence) weight for the current vertex
			DoubleArrayMetadata(),
			...
		],

		"blendShapes": // Blend shapes data (optional)
		ArrayMetadata[
			MapMetadata{
				"id":IntMetadata(), // index of the current blend shape, this index is used at render/preview time to get the target weight from the agent metadata
				"name":StringMetadata(), // name of the target
				"P":Vector3ArrayMetadata(),
				"N":Vector3ArrayMetadata()
			},
			MapMetadata{
				"id":IntMetadata(),
				"name":StringMetadata(),
				"P":Vector3ArrayMetadata(),
				"N":Vector3ArrayMetadata()
			},
			...
		],

		"atoms":
		MapMetadata{ //Custom data. This data is written on the mesh sent to the renderer. You can use these attributes to drive shader attributes from he mesh. The mesh attribute on the arnold/rman/vray mesh will use the atoms_ prefix. (optional)
			"fooattr":DobuleMetadata(),
			"fooattr1":StringMetadata(),
			...
		},
		"arnold":
		MapMetadata{ // These attributes are converted to arnold polymesh node attributes (optional)
			"fooattr":DobuleMetadata(),
			"fooattr1":StringMetadata(),
			...
		},
		"rman":
		MapMetadata{ // These attributes are converted to rman mesh node attributes (optional)
			"fooattr":DobuleMetadata(),
			"fooattr1":StringMetadata(),
			...
		},
		"vray":
		MapMetadata{ // These attributes are converted to vray mesh node attributes (optional)
			"fooattr":DobuleMetadata(),
			"fooattr1":StringMetadata(),
			...
		}

		"xgen_Pref":Vector3ArrayMetadata(), // xgen pref point attribute (optional)
		"__Pref":Vector3ArrayMetadata(), // renderman pref point attribute (optional)
		"__WPref":Vector3ArrayMetadata(), // renderman wpref point attribute (optional)
		"__Nref":Vector3ArrayMetadata(), // renderman nref point attribute (optional)
		"__WNref":Vector3ArrayMetadata(), // renderman nwref point attribute (optional)


		"color":Vector3Metadata(), // Color used for preview without the textures by the skin mode (optional)
		"colorTexture":ImageMetadata(), // Texture used for preview by the skin mode (optional)
		"specularColor":Vector3Metadata(), // Specular color used for preview without the textures by the skin mode (optional)
		"specularColorTexture":ImageMetadata(), // Specular texture used for preview by the skin mode (optional)
	},

	"geo2":
	MapMetadata{...},
		
	"geo3":
	MapMetadata{...},

	...
}


To register the new loader to atoms:

extern "C"
{
	ATOMSPLUGIN_EXPORT bool initializePlugin()
	{
		MeshLoaderFactory& factory = MeshLoaderFactory::instance();
		factory.registerMeshLoader(FooMeshLoader::staticTypeStr, &FooMeshLoader::creator);
	}
}


Compile the behaviour module

Since the loader is used also by the procedurals you must compile your new plugin 2 times. The first time link to the Atoms.so/lib library. The second time link to the AtomsProcedural.so/lib library.

Windows:

In visual studio create a dll projects, add the atoms, tbb and openexr includes and add

BUILD_ATOMSPLUGIN,WIN,_CRT_SECURE_NO_WARNINGS,_CRT_NONSTDC_NO_DEPRECATE,FBXSDK_SHARED

to the preprocessor definitions.

Then create another target and link AtomsProcedural instead to link Atoms.


Linux:

Compile as a shared object adding the atoms, tbb and opendexr includes and BUILD_ATOMSPLUGIN to the preprocessor definitions.

Then create another target and link AtomsProcedural instead to link Atoms.


Use the plugin

Add to the ATOMS_PLUGINS_PATH environment variable, the folder where the library compiles against Atoms is located, while add to the ATOMS_PROCEDURAL_PLUGINS_PATH env variable the path where the library compiled against AtomsProcedural is located.

  • No labels