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-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-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-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-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-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-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