-
首页
-
C4D R23.110 C++ SDK
Volume Tools Manual
内容表
关于
Volumes can be created and edited with specific commands and functions provided in the
maxon::VolumeToolsInterface
.
Commands
These commands can be used to handle volume data (see
Commands Manual
):
The
maxon::VolumeCommandData
structure has these members:
// This example performs multiple commands to turn the
// given polygon objects into volumes, to perform a
// boolean operation on these volumes and to create
// a polygon hull for the result volume.
VolumeObject
* volumeObjectA =
nullptr
;
VolumeObject
* volumeObjectB =
nullptr
;
VolumeObject
* resultVolume =
nullptr
;
MAXON_SCOPE
{
// make volume objects
maxon::LegacyCommandDataRef context = maxon::LegacyCommandDataClasses::VOLUMEDATA().Create()
iferr_return
;
maxon::BaseArray<BaseObject*>
sourceObjects;
sourceObjects.
Append
(polyObjectA)
iferr_return
;
sourceObjects.
Append
(polyObjectB)
iferr_return
;
maxon::VolumeCommandData
data;
data.
op
= &sourceObjects;
const
maxon::Int
dataIndex = 0;
context.Set(
MESHTOVOLUMESETTINGS::GRIDSIZE
, 10.0)
iferr_return
;
context.SetLegacyData<
maxon::VolumeCommandData
>(data, dataIndex)
iferr_return
;
const
auto
command = maxon::CommandClasses::MESHTOVOLUME();
const
maxon::COMMANDRESULT
res = context.Invoke(command,
false
)
iferr_return
;
if
(res !=
maxon::COMMANDRESULT::OK
)
return
maxon::OK
;
const
maxon::VolumeCommandData
& result = context.GetLegacyData<
maxon::VolumeCommandData
>(dataIndex)
iferr_return
;
if
(result.
result
.GetCount() == 2)
{
volumeObjectA =
static_cast<
VolumeObject
*
>
(result.
result
[0]);
volumeObjectB =
static_cast<
VolumeObject
*
>
(result.
result
[1]);
}
}
MAXON_SCOPE
{
// perform bool operation
maxon::LegacyCommandDataRef context = maxon::LegacyCommandDataClasses::VOLUMEDATA().Create()
iferr_return
;
maxon::BaseArray<BaseObject*>
sourceObjects;
sourceObjects.
Append
(volumeObjectA)
iferr_return
;
sourceObjects.
Append
(volumeObjectB)
iferr_return
;
maxon::VolumeCommandData
data;
data.
op
= &sourceObjects;
const
maxon::Int
dataIndex = 0;
// 1 equals BOOLTYPE::DIFF
context.Set(
BOOLESETTINGS::BOOLETYPE
, 1)
iferr_return
;
context.SetLegacyData<
maxon::VolumeCommandData
>(data, dataIndex)
iferr_return
;
const
auto
command = maxon::CommandClasses::BOOLE();
const
maxon::COMMANDRESULT
res = context.Invoke(command,
false
)
iferr_return
;
if
(res !=
maxon::COMMANDRESULT::OK
)
return
maxon::OK
;
const
maxon::VolumeCommandData
& result = context.GetLegacyData<
maxon::VolumeCommandData
>(dataIndex)
iferr_return
;
if
(result.
result
.GetCount() == 1)
{
resultVolume =
static_cast<
VolumeObject
*
>
(result.
result
[0]);
}
}
MAXON_SCOPE
{
// create mesh
maxon::LegacyCommandDataRef context = maxon::LegacyCommandDataClasses::VOLUMEDATA().Create()
iferr_return
;
maxon::BaseArray<BaseObject*>
sourceObjects;
sourceObjects.
Append
(resultVolume)
iferr_return
;
maxon::VolumeCommandData
data;
data.
op
= &sourceObjects;
const
maxon::Int
dataIndex = 0;
context.SetLegacyData<
maxon::VolumeCommandData
>(data, dataIndex)
iferr_return
;
const
auto
command = maxon::CommandClasses::VOLUMETOMESH();
const
maxon::COMMANDRESULT
res = context.Invoke(command,
false
)
iferr_return
;
if
(res !=
maxon::COMMANDRESULT::OK
)
return
maxon::OK
;
const
maxon::VolumeCommandData
& result = context.GetLegacyData<
maxon::VolumeCommandData
>(dataIndex)
iferr_return
;
if
(result.
result
.GetCount() == 1)
{
BaseObject
*
const
object
= result.
result
[0];
doc->
InsertObject
(
object
,
nullptr
,
nullptr
);
}
}
// free data
VolumeObject::Free
(resultVolume);
VolumeObject::Free
(volumeObjectA);
VolumeObject::Free
(volumeObjectB);
工具
The
maxon::VolumeToolsInterface
provides multiple functions to handle volumes.
Load volumes from files:
另请参阅
maxon::VolumeInterface::CreateFromFile()
(
VolumeInterface Manual
).
Volume operations:
Volume creation:
Volume conversion:
// This example uses multiple tools to turn the
// given polygon objects into volumes, to perform a
// boolean operation on these volumes and to create
// a polygon hull for the result volume.
// lambda funtion to convert the given PolygonObject to a VolumeRef
auto
PolyToVolume = [](
PolygonObject
*
const
poly) ->
maxon::Result<maxon::Volume>
{
iferr_scope
;
// check polygon object data
const
向量
*
const
points = poly->GetPointR();
const
CPolygon
*
const
polys = poly->GetPolygonR();
const
maxon::Bool
noPoints = points ==
nullptr
;
const
maxon::Bool
noPolys = polys ==
nullptr
;
if
(noPoints || noPolys)
return
maxon::UnexpectedError(
MAXON_SOURCE_LOCATION
);
// get polygon object data
const
Int32
pointCount = poly->GetPointCount();
const
Int32
polyCount = poly->GetPolygonCount();
const
矩阵
objectMatrix = poly->GetMg();
const
maxon::COLLECTION_RESIZE_FLAGS
flags =
maxon::COLLECTION_RESIZE_FLAGS::ON_GROW_UNINITIALIZED
;
// point array
maxon::BaseArray<maxon::Vector>
volPoints;
volPoints.
Resize
(pointCount, flags)
iferr_return
;
// copy point data
for
(
Int32
pointIndex = 0; pointIndex < pointCount; ++pointIndex)
volPoints[pointIndex] = objectMatrix * points[pointIndex];
// polygon array
maxon::BaseArray<maxon::VolumeConversionPolygon>
volPolys;
volPolys.
Resize
(polyCount, flags)
iferr_return
;
// copy polygon data
for
(
Int32
polyIndex = 0; polyIndex < polyCount; polyIndex++)
{
volPolys[polyIndex] = *
reinterpret_cast<
const
maxon::VolumeConversionPolygon
*
>
(&polys[polyIndex]);
if
(polys[polyIndex].IsTriangle())
volPolys[polyIndex].SetTriangle();
}
const
maxon::ThreadInterface
*
const
thread =
maxon::ThreadRef::GetCurrentThread
().GetPointer();
if
(thread ==
nullptr
)
return
maxon::UnexpectedError(
MAXON_SOURCE_LOCATION
);
const
maxon::ThreadRef
threadRef =
const_cast<
maxon::ThreadInterface
*
>
(thread);
return
maxon::VolumeToolsInterface::MeshToVolume
(volPoints, volPolys, objectMatrix, 10.0, 10, 10, threadRef);
};
// convert polygon objects to volumes
const
maxon::Volume volumeA = PolyToVolume(polyObjectA)
iferr_return
;
const
maxon::Volume volumeB = PolyToVolume(polyObjectB)
iferr_return
;
// perform bool
const
maxon::Volume resultVolume =
maxon::VolumeToolsInterface::BoolVolumes
(volumeA, volumeB,
BOOLTYPE::DIFF
)
iferr_return
;
// result to mesh
PolygonObject
*
const
mesh =
maxon::VolumeToolsInterface::VolumeToMesh
(resultVolume, 10.0, 10.0)
iferr_return
;
if (mesh ==
nullptr
)
return
maxon
::UnexpectedError(
MAXON_SOURCE_LOCATION
);
doc->InsertObject(mesh,
nullptr
,
nullptr
);
// This example creates a vector volume from the given field object.
// prepare conversion
maxon::FieldSampleData
sampleData;
sampleData.
doc
= doc;
sampleData.
fieldList
=
nullptr
;
sampleData.
fieldOwner
= fieldObject;
sampleData.
extraTransform
= fieldObject->
GetMg
();
sampleData.
flags
=
FIELDLAYER_FLAG::NONE
;
maxon::Range<maxon::Vector>
sampleBox;
sampleBox.
_minValue
=
maxon::Vector
{ -100.0 };
sampleBox.
_maxValue
=
maxon::Vector
{ 100.0 };
maxon::ThreadRef
thread;
const
maxon::Float
gridSize = 10.0;
// convert
const
maxon::Volume volume =
maxon::VolumeToolsInterface::ConvertFieldsToVectorVolume
(sampleData, gridSize, sampleBox, thread,
nullptr
,
nullptr
)
iferr_return
;
// make volume object
VolumeObject
* const volumeObject =
VolumeObject
::Alloc();
if (volumeObject ==
nullptr
)
return
maxon
::OutOfMemoryError(
MAXON_SOURCE_LOCATION
);
doc->InsertObject(volumeObject,
nullptr
,
nullptr
);
// store volume data
volumeObject->SetVolume(volume);
延伸阅读
定义:
lib_volumeobject.h:40
BaseArray<::BaseObject * > * op
定义:
volumecommands.h:36
void InsertObject(BaseObject *op, BaseObject *parent, BaseObject *pred, Bool checknames=false)
The maxon namespace contains all declarations of the MAXON API.
定义:
c4d_basedocument.h:15
@ OK
The command was executed properly.
Represents a polygon that can be either a triangle or a quadrangle.
定义:
c4d_baseobject.h:43
Matrix GetMg() const
定义:
c4d_baseobject.h:482
return OK
定义:
apibase.h:2532
@ BOOLETYPE
Int32 The Boole type (union, difference, intersection).
ResultMem Resize(Int newCnt, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::DEFAULT)
定义:
basearray.h:1077
static StrongRef< const ThreadInterface > GetCurrentThread()
定义:
thread.h:356
bool Bool
boolean type, possible values are only false/true, 8 bit
定义:
apibase.h:177
COMMANDRESULT
Defines the result of the command after execution.
定义:
commandbase.h:35
FIELDLAYER_FLAG flags
定义:
volumetools.h:141
#define iferr_return
定义:
resultbase.h:1434
#define MAXON_SOURCE_LOCATION
定义:
memoryallocationbase.h:66
Float64 Float
定义:
apibase.h:193
::FieldList * fieldList
定义:
volumetools.h:142
Matrix extraTransform
定义:
volumetools.h:140
@ GRIDSIZE
Float Grid voxel cube size.
@ ON_GROW_UNINITIALIZED
Do not initialize added elements (usually PODs) when resizing the array (is supported by all collecti...
COLLECTION_RESIZE_FLAGS
Flags for Resize(). Depending on the type of collection the flags might be ignored (except for ON_GRO...
定义:
collection.h:125
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
定义:
basearray.h:569
BaseArray<::BaseObject * > result
定义:
volumecommands.h:41
Int64 Int
signed 32/64 bit int, size depends on the platform
定义:
apibase.h:184
#define iferr_scope
定义:
resultbase.h:1343
maxon::Int32 Int32
定义:
ge_sys_math.h:58
static void Free(VolumeObject *&p)
定义:
lib_volumeobject.h:66
T _minValue
The inclusive minimum boundary of this range.
定义:
range.h:256
定义:
c4d_baseobject.h:1597
::BaseDocument * doc
定义:
volumetools.h:144
::BaseList2D * fieldOwner
定义:
volumetools.h:143
T _maxValue
The inclusive maximum boundary of this range. If the minimum boundary is not less than or equal to th...
定义:
range.h:257
#define MAXON_SCOPE
定义:
apibase.h:2645