Hey everyone,
I've been working on a Cinema 4D plugin that maps and arranges textures onto a pixel grid. The goal is to make it easier to create voxel-style or Minecraft-like models by linking real-world units (e.g., centimeters) to pixels. (for example, 1 pixel = 6.25 cm)
Right now, I’ve left out most of the other planned features, since I mainly want to confirm whether I’m heading in the right direction with my current approach or if I’ve gone off track somewhere.
I’m still fairly new to the Cinema 4D SDK (using the Cinema 4D 2024 SDK and the cinema namespace), so I’d really appreciate any feedback on whether this implementation makes sense and if I’m structuring it correctly.
using namespace cinema;
// Function to create the vox UV islands
maxon::Result<void> VoxUvIslandCommand::CreateVoxUVIslands(Float pixelSize)
{
// Implement a customizable pixel grid that has the grid set to 128x128, 256X256 or 512x512 for optimal packaging
// A pixel should match a set size in the 3d world like 6.25 cm
// Allocate the document
BaseDocument* doc = AutoAlloc(GetActiveDocument());
// Allocate the objects needed to create the UV islands
AutoAlloc<BaseObject> selectedObject;
AutoAlloc<BaseBitmap> bitmap;
AutoAlloc<BaseTag> foundTag;
AutoAlloc<UVWTag> foundUVWTag;
if (!doc || !selectedObject || !bitmap || !foundTag)
return maxon::FAILED;
selectedObject = AutoAlloc(doc->GetActiveObject());
if (!selectedObject)
return maxon::FAILED;
// Get the UV data from the selected object
foundUVWTag = AutoAlloc((UVWTag*)selectedObject->GetTag(Tuvw));
// Check if the UVW tag exists, otherwise create it
if (!foundUVWTag) {
}
// Check if the UVW tag is valid
if (foundUVWTag->GetType() != Tuvw)
return maxon::FAILED;
Int32 dataCount = foundUVWTag->GetDataCount();
// Get the UV data from the UVW tag
bitmap = AutoAlloc((BaseBitmap*)foundUVWTag->GetObject());
return maxon::OK;
}
A huge thanks in advance to anyone willing to take a look. Any feedback and/or suggestions are greatly appreciated!