Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Mograph Camera Shader from Python

    Cinema 4D SDK
    2
    3
    524
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fasteffect
      last edited by m_adam

      I'm trying to write a script to add the mograph camera shader to the luminance channel of a material, and then set the Camera target. I can insert other shaders, but I cannot locate in the documentation the correct way to instantiate that shader, nor how to modify the property of a shader once added to the material.

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        hello ,

        here's an example on how to create a camera shader and set the link of the camera.

        Be aware you need to create the shader using it's ID so it could be changed in the future.

        I've used a script from @m_adam as a base and just added the camera shader stuff. You can thanks him a lot ^^

        Cheers
        Manuel

        
        import c4d
        from c4d import gui
        
        
        
        def main():
            # Gets the active object
            if op is None:
                raise ValueError("op is none, please select one object.")
        
            # Retrieves the BaseDraw of Render View
            bd = doc.GetRenderBaseDraw()
            if bd is None:
                raise ValueError("no BaseDraw found")
        
            # Retrieves the scene camera
            cam = bd.GetSceneCamera(doc)
            if cam is None:
                raise ValueError("there's no camera")
        
        
            # Creates a default Cinema 4D Material, the created material only exist in the memory
            mat = c4d.BaseMaterial(c4d.Mmaterial)
            if mat is None:
                raise RuntimeError("Failed to creates a new BaseMaterial.")
        
            # Inserts the material in the active document
            doc.InsertMaterial(mat)
        
            # Creates the Camera Shader
            #be aware you have to use the ID here but it can changed in future release
            sha = c4d.BaseList2D(440000050)
            if sha is None:
                raise RuntimeError("Failed to creates a bitmap shader.")
        
            # Defines the camera link inside the shader
            sha[c4d.MGCAMERASHADER_LINK] = cam
        
            # Inserts the shader into the material
            mat[c4d.MATERIAL_COLOR_SHADER] = sha
            mat.InsertShader(sha)
        
            # Checks if there is already a texture tag on the active object, if not creates it
            textureTag = op.GetTag(c4d.Ttexture)
            if not textureTag:
                textureTag = op.MakeTag(c4d.Ttexture)
        
            # If the texture tag is not available at this point, something went wrong
            if textureTag is None:
                raise RuntimeError("Failed to retrieves the texture tag.")
        
            # Links the newly created material from the textureTag Material link parameter
            textureTag[c4d.TEXTURETAG_MATERIAL] = mat
            
            # Changes the texture tag projection to UVW
            textureTag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
        
            # Informs Cinema 4D something changed in the scene
            c4d.EventAdd()
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        MAXON SDK Specialist

        MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • F
          fasteffect
          last edited by

          Thanks that worked perfectly. I thank you both!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post