gr4ph0s / C4D_RedshiftWrapper_API

A c4d wrapper around Redshift API
MIT License
35 stars 7 forks source link

C4D_RedshiftWrapper_API

Wrapper class for the current API of Redshift for c4d
More detailled documentation Here
Download a minified version here https://gist.github.com/gr4ph0s/cdbcf67a05ee6ad8d365220435ae1f93#file-a-minified-version-of-my-module-c4d_redshiftwrapper_api Example for use minified version https://pastebin.com/BRggfGdA

Class Presentation

Redshift

**Redshift class is the main wrapper. Use it for any interaction of the GraphView.

Node

Node class represent a c4d.modules.graphview.GvNode inside a redshift shader network.

MetaName

Represent all metaname possible for create redshift shader.

Examples

Basic exemple to get the redshift material, add a fresnel shader and constant node, and link all nodes. (Constant => Fresnel => Material => Output)

import c4d
from RedshiftWrapper.Redshift import Redshift

def main():
    rs = Redshift()
    if rs is False:
        return

    #Assign Material
    rs.SetMat(doc.GetFirstMaterial())

    #Create Constant Node
    ConstNode = rs.CreateShader(c4d.ID_OPERATOR_CONST, x=100, y=500)

    #Create Fresnel shader and expose parameter
    FresnelNode = rs.CreateShader("Fresnel", x=200, y=500)
    FresnelNode.ExposeParameter(c4d.REDSHIFT_SHADER_FRESNEL_USER_CURVE, c4d.GV_PORT_INPUT)

    #Connect Constant and fresnel
    rs.CreateConnection(ConstNode, FresnelNode, 0, 0)

    #Get default material node and output node
    listNode = rs.GetAllNodes()
    MatNode = None
    OutPutNode = None
    for node in listNode:
        if node.GetType() == "Output":
            OutPutNode = node
        elif node.GetType() == "Material":
            MatNode = node

    if not MatNode or not OutPutNode:
        return

    #Expose a paramter of the material
    MatNode.ExposeParameter(c4d.REDSHIFT_SHADER_MATERIAL_DIFFUSE_WEIGHT, c4d.GV_PORT_INPUT)

    #Connect Fresnel shader to the material
    rs.CreateConnection(FresnelNode, MatNode, 0, 0)

    #Connect material shader to the output
    rs.CreateConnection(MatNode, OutPutNode, 0, 0)

    c4d.EventAdd()
if __name__=='__main__':
    main()

Installation

To use it as a library simply copy RedshiftWrapper folder into

Before R23

R23 and more

Even if I suggest to use it as a library you are free to only include it into your project. For doing it in proper way I suggest you to read Best Practice For Imports from official support forum and then use py-localimport from Niklas Rosenstein

Compatibility

Tested and build on Redshift 2.5.32 and R17/R18/R19/23