3ds Max Plugins
DataBlock class for reading and writing hierarchically structured data.
-
class DataBlock
- #include <datablk.h>
Class for reading and writing hierarchically structured data.
DataBlock itself is a node of the tree that has a name and hosts typified named parameters and named sub-nodes.
Parameter or sub-block name can be non-unique for a given DataBlock object. This is useful for enumerating data that can be repeated arbitrary number of times.
For clarity, names are restricted to C indentifier rules.
Actual names are stored in NameMap that is shared by all DataBlocks in the tree. Blocks and parameters use integer ids to address names in the NameMap, so there are methods that take name ids and those that take character strings. You can use name ids when you look for multiple blocks or parameters with the same name for performance gain.
DataBlock tree contents can be serialized in binary or text form.
Text files of this format usually have extension “.blk”.
Loading
-
bool loadText(char *text, int text_length, const char *filename = NULL)
Load DataBlock tree from specified text. Filename is for error output only.
-
bool loadText(Tab<char> &text, const char *filename = NULL)
Load DataBlock tree from specified text. Filename is for error output only.
Note
This method will modify text when including files.
Saving
-
bool saveToTextFile(const char *filename) const
Save this DataBlock (and its sub-tree) to the specified file (text form)
Names
-
int getNameId(const char *name) const
Returns name id from NameMap, or -1 if there’s no such name in the NameMap.
Block Name
Sub-blocks
-
DataBlock *getBlockByName(int name_id, int start_after = -1) const
Returns pointer to sub-block with specified name id, or NULL if not found.
-
inline DataBlock *getBlockByName(const char *name, int start_after = -1) const
Returns pointer to sub-block with specified name, or NULL if not found.
-
inline DataBlock *getBlockByNameEx(const char *name, DataBlock *def_blk) const
Get sub-block by name, returns def_blk, if not found.
-
inline DataBlock *getBlockByNameEx(const char *name) const
Get block by name, returns (always valid) emptyBlock, if not found.
-
DataBlock *addBlock(const char *name)
Add block or get existing one. See also addNewBlock() and getBlockByNameEx(const char *name) const.
-
DataBlock *addNewBlock(const char *name)
Add new block. See also addBlock().
-
void setParamsFrom(const DataBlock *copy_from)
Copies all parameters (not sub-blocks!) from specified DataBlock.
-
DataBlock *addNewBlock(const DataBlock *copy_from, const char *as_name = NULL)
Create new block as a copy of specified DataBlock, with copy of all its sub-tree.
-
bool removeBlock(const char *name)
Remove all sub-blocks with specified name. Returns false if no sub-blocks were removed.
-
inline DataBlock *setBlock(const DataBlock *blk, const char *as_name = NULL)
Similar to addNewBlock(const DataBlock *copy_from, const char *as_name), but removes existing sub-blocks with the same name first.
Parameters - Getting and Enumeration
-
int getParamType(int param_number) const
Returns type of i-th parameter. See ParamType enum.
-
int getParamNameId(int param_number) const
Returns i-th parameter name id. See getNameId().
-
inline const char *getParamName(int param_number) const
Returns i-th parameter name. Uses getName().
-
int findParam(int name_id, int start_after = -1) const
Find parameter by name id. Returns parameter index or -1 if not found.
-
inline int findParam(const char *name, int start_after = -1) const
Find parameter by name. Uses getNameId(). Returns parameter index or -1 if not found.
Parameters - Getting by Index
These methods get parameter value by parameter index in the block, the index number is from 0 to paramCount() -1.
On parameter type mismatch, zero-like value is returned.
Use them for enumerating parameters together with DataBlock::getParamNameId() / DataBlock::getParamName() and DataBlock::getParamType().
-
const char *getStr(int param_number) const
-
bool getBool(int param_number) const
-
int getInt(int param_number) const
-
real getReal(int param_number) const
-
Point2 getPoint2(int param_number) const
-
Point3 getPoint3(int param_number) const
-
Point4 getPoint4(int param_number) const
-
IPoint2 getIPoint2(int param_number) const
-
IPoint3 getIPoint3(int param_number) const
-
E3DCOLOR getE3dcolor(int param_number) const
Parameters - Getting by Name
These methods get parameter value by parameter name.
If there is no parameter with specified name in this DataBlock, or it has different type, default value is returned.
If there is more than one matching parameter, value of the first one is returned.
-
const char *getStr(const char *name, const char *def) const
-
bool getBool(const char *name, bool def) const
-
int getInt(const char *name, int def) const
-
real getReal(const char *name, real def) const
-
Point2 getPoint2(const char *name, const Point2 &def) const
-
Point3 getPoint3(const char *name, const Point3 &def) const
-
Point4 getPoint4(const char *name, const Point4 &def) const
-
IPoint2 getIPoint2(const char *name, const IPoint2 &def) const
-
IPoint3 getIPoint3(const char *name, const IPoint3 &def) const
-
E3DCOLOR getE3dcolor(const char *name, E3DCOLOR def) const
Parameters - Setting
These methods set value of the parameter with the specified name.
If parameter of requested type doesn’t exist, it’s added, otherwise its value is set to the specified one.
-
int setStr(const char *name, const char *value)
-
int setBool(const char *name, bool value)
-
int setInt(const char *name, int value)
-
int setReal(const char *name, real value)
-
int setPoint2(const char *name, const Point2 &value)
-
int setPoint3(const char *name, const Point3 &value)
-
int setPoint4(const char *name, const Point4 &value)
-
int setIPoint2(const char *name, const IPoint2 &value)
-
int setIPoint3(const char *name, const IPoint3 &value)
-
int setE3dcolor(const char *name, const E3DCOLOR value)
Parameters - Adding
These methods add new parameter with the specified name.
It’s possible to add multiple parameters with the same name and type.
If you want just to add / set single parameter value, use set* methods.
-
int addStr(const char *name, const char *value)
-
int addBool(const char *name, bool value)
-
int addInt(const char *name, int value)
-
int addReal(const char *name, real value)
-
int addPoint2(const char *name, const Point2 &value)
-
int addPoint3(const char *name, const Point3 &value)
-
int addPoint4(const char *name, const Point4 &value)
-
int addIPoint2(const char *name, const IPoint2 &value)
-
int addIPoint3(const char *name, const IPoint3 &value)
-
int addE3dcolor(const char *name, const E3DCOLOR value)
Parameters - Removing
-
bool removeParam(const char *name)
Remove all parameters with the specified name. Returns false if no parameters were removed.
Other methods
Public Types
-
enum ParamType
Parameter types enum.
Values:
-
enumerator TYPE_NONE
-
enumerator TYPE_STRING
Text string.
-
enumerator TYPE_INT
Integer.
-
enumerator TYPE_POINT2
Point2.
-
enumerator TYPE_POINT3
Point3.
-
enumerator TYPE_POINT4
Point4.
-
enumerator TYPE_IPOINT2
IPoint2.
-
enumerator TYPE_IPOINT3
IPoint3.
-
enumerator TYPE_BOOL
Boolean.
-
enumerator TYPE_E3DCOLOR
E3DCOLOR.
-
enumerator TYPE_NONE
Public Functions
-
DataBlock()
Default constructor, constructs empty block.
-
~DataBlock()
Destructor, destroys all sub-blocks.
-
DataBlock(const char *filename)
Constructor that loads DataBlock tree from specified file. If you want error checking, use default constructor and loadFile().
-
void clearData()
Delete all sub-blocks.
-
bool loadText(char *text, int text_length, const char *filename = NULL)
Warning
doxygenfile: Cannot find file “e3DCOLOR.H
common classes and functions for 2D, 3D and 4D math
-
class Matrix33
- #include <math3d.h>
-
class TMatrix
- #include <math3d.h>
4x3 transformation matrix. last column (3rd, counting from zero) is translation
See also
Matrix3 TMatrix4 Point3 Point2 Point4
-
class BBox2
- #include <math3d.h>
-
class BBox3
- #include <math3d.h>
-
class StaticMeshRayTracer
- #include <math3d.h>
Subclassed by StaticMeshRTracer
NameMap class derived from DObject that maps string to integers and back.
-
class BaseNameMap
- #include <namemap.h>
This class maps strings to integers and back. NULL is mapped to -1. All other strings are mapped to non-negative numbers (>=0). NOTE: this class misses some methods that are implemented in NameMap and NameMapCI.
Subclassed by NameMap, NameMapCI
Public Functions
-
BaseNameMap()
Constructor. Memory allocator can be specified (defaults to #tmpmem).
-
~BaseNameMap()
-
void clear()
Clear name list.
-
inline int nameCount() const
Number of names in list. You can get them all by iterating from 0 to nameCount()-1.
-
const char *getName(int name_id) const
Returns NULL when name_id is invalid.
-
void save(FILE*) const
Save this name map.
-
void load(FILE*)
Load this name map.
Protected Functions
-
void copyFrom(const BaseNameMap &nm)
Protected Attributes
-
Tab<String> names
Private Functions
-
inline BaseNameMap(const BaseNameMap &nm)
-
inline BaseNameMap &operator=(const BaseNameMap &nm)
-
BaseNameMap()
-
class NameMap : public BaseNameMap
- #include <namemap.h>
Case-sensitive version of BaseNameMap.
-
class NameMapCI : public BaseNameMap
- #include <namemap.h>
Case-insensitive version of BaseNameMap.
Warning
doxygenfile: Cannot find file “str.H