Skip to content

Instantly share code, notes, and snippets.

View fwilleke80's full-sized avatar
💭
Mostly inactive, sometimes active, I really don't feel like updating my status

Frank Willeke fwilleke80

💭
Mostly inactive, sometimes active, I really don't feel like updating my status
View GitHub Profile
@fwilleke80
fwilleke80 / c4d-map-range.cpp
Last active March 17, 2017 11:32
[C4D] Map a value from one range to another
/// Maps a value from an input range to an output range
/// e.g. from -180° ... 180° to 0.0 ... 1.0
/// Basically like the range mapper node in XPresso.
///
/// @param[in] value The input value
/// @param[in] minInput Defines the lower limit of the input range
/// @param[in] maxInput Defines the upper limit of the input range
/// @param[in] minOutput Defines the lower limit of the output range
/// @param[in] maxOutput Defines the upper limit of the output range
/// @return The mapped value
@fwilleke80
fwilleke80 / c4d-round-grid.cpp
Last active April 19, 2017 00:51
[C4D] Round a value to the nearest grid point
/// Round a value to a grid.
/// This is an extended version of Round(), rounding not just to the nearest whole number but to the nearest point in a grid with arbitrary spacing.
/// Using "1.0" as value for grid will give the same results as Round().
///
/// @param[in] value The input value
/// @param[in] grid The grid spacing
/// @return The rounded value
static inline Float RoundGrid(Float value, Float grid = 1.0)
{
if (grid == 0.0)
@fwilleke80
fwilleke80 / c4d-csto.cpp
Last active March 17, 2017 11:32
[C4D] Calling MCOMMAND_CURRENTSTATETOOBJECT on an object... the proper way
/// Calls MCOMMAND_CURRENTSTATETOOBJECT on an object and returns the result
///
/// @note: This is time and memory consuming, so only do it when necessary, and then cache the result!
///
/// @param[in] op The object you want to CSTO
/// @return The resulting object. Caller owns the pointed object.
PolygonObject* CurrentStateToObject(BaseObject *op)
{
// Create AliasTranslate
AutoAlloc<AliasTrans> aliasTrans;
@fwilleke80
fwilleke80 / c4d-dynamicdescription.cpp
Last active March 17, 2017 11:51
[C4D] Dynamic descriptions. Add description elements to an existing description at runtime by calling these functions from NodeData::GetDDescription().
#include "c4d-dynamicdescription.h"
Bool IsSingleID(const DescID &id, const DescID *singleid)
{
return !singleid || id.IsPartOf(*singleid, NULL);
}
Bool DescriptionAddCycle(Description *description, Int32 id, Int32 groupId, const String &name, const BaseContainer &cycleItems, BaseContainer *cycleIcons, Int32 defaultValue)
@fwilleke80
fwilleke80 / c4d-get-vertex-normal.cpp
Last active May 12, 2017 09:13
[C4D] Get vertex normal
/// Return the normal vector for a vertex of a polygon object.
/// The normal is computed as an average of the normals of all polygons that are neighbors to the specified vertex.
///
/// @param[in] op The PolygonObject
/// @param[in] neighbor Pointer to a Neighbor object. Must already be initialized, caller owns the pointed object.
/// @param[in] pointIndex The index of the vertex we want the normal of
/// @return The normal of the point in local object space
static Vector GetVertexNormal(PolygonObject *op, Neighbor *neighbor, Int32 pointIndex)
{
// Variables
@fwilleke80
fwilleke80 / c4d-restartcommand.cpp
Created March 17, 2017 22:47
[C4D] A really tiny command plugin that restarts Cinema 4D. Only 16 lines long.
#include "c4d.h"
class RestartCommand : public CommandData
{
virtual Bool Execute(BaseDocument *doc)
{
if (GeOutString("Really restart?", GEMB_ICONQUESTION|GEMB_YESNO) == GEMB_R_YES)
RestartApplication();
return true;
}
@fwilleke80
fwilleke80 / c4d-matrix-target.cpp
Last active March 26, 2017 22:43
[C4D] Create a matrix that targets a position with an optional up vector.
/// Align a matrix to a target, using an up vector
///
/// @param[in] pos The position we're targeting from
/// @param[in] targetPos The position we're targeting at
/// @param[in] upVector The up vector, to avoid gimbal lock. Defaults to +Y
/// @return A matrix with an offset of 'pos', targeting 'targetPos' with its Z axis.
static inline Matrix Target(const Vector &pos, const Vector &targetPos, const Vector &upVector = Vector(0.0, 1.0, 0.0))
{
Matrix m(DC); // New matrix. Don't call default constructor, as we're filling the values now anyway.
m.off = pos; // Set position
@fwilleke80
fwilleke80 / c4d-hidedescription.cpp
Last active July 6, 2017 09:01
[C4D] Show or hide an element from a node's description
/// Show or hide an element from a node's description
///
/// param[in] node The node whose description we're changing
/// param[in] descr The description we're changing
/// param[in] MyDescID The ID of the element
/// param[in] show Pass true to show, or false to hide
/// return False if an error occurred, otherwise true
static Bool ShowDescription(GeListNode *node, Description *descr, Int32 descID, Bool show)
{
AutoAlloc<AtomArray> ar;
@fwilleke80
fwilleke80 / c4d-messagetostring.cpp
Last active July 6, 2017 09:14
[C4D] Return the name of a message ID as string. Very handy to find out what messages you're receiving. Call this from any Message() function in the Cinema 4D API, and simply pass the message ID and message data pointer.
#include "c4d_general.h"
#include "c4d_plugin.h"
#include "ge_sys_math.h"
#include "c4d_string.h"
#include "ge_prepass.h"
#include "c4d_baselist.h"
#include "c4d_commanddata.h"
#include "c4d_falloffdata.h"
#include "c4d_messageplugin.h"
#include "c4d_baseeffectordata.h"
@fwilleke80
fwilleke80 / c4d-list-tags-on-object.py
Last active September 17, 2019 14:28
[C4D] This script lists all tags attached to the selected object, by name and plugin ID. It also shows if a tag is visible or invisible.
"""
Name-US:List tags on object
Description-US:List all tags attached to the selected object, by name and plugin ID
"""
import c4d
"""
This script lists all tags attached to the selected object, by name and plugin ID.
It also shows if a tag is visible or invisible.
"""