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
    1. Maxon Developers Forum
    2. yanmasterson
    3. Posts
    Y
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by yanmasterson

    • RE: Creating shaders from PSD files

      Thanks Maxime! I'm relieved it's a bug, I was looking everywhere for functions to manually fix the OpenGL preview. I will try with this approach.

      Y.

      posted in Cinema 4D SDK
      Y
      yanmasterson
    • RE: Creating shaders from PSD files

      Hi Maxime,

      The PSD file is just a test file, so at the moment it's a very simple layered file. Four layers, everything completely rasterised, no text or effects or anything special. Here's the code I'm using - you'll need to replace "/MyPath/test.psd" with a path to your PSD image.

      Than you so much for helping!

      import c4d
      from c4d import bitmaps
      
      def CreateMaterial(matName, fileName, layerName, i):
          # Create a new material from scratch
          mat = c4d.Material()
          mat.SetName(matName)
          doc = c4d.documents.GetActiveDocument()
          doc.InsertMaterial(mat)
      
          # create a texture shader and assign it to the color channel
          
          # enable the color channel
          mat[c4d.MATERIAL_USE_COLOR] = True
          # create a bitmap shader
          texshader = c4d.BaseShader(c4d.Xbitmap)
          texshader[c4d.BITMAPSHADER_FILENAME] = fileName
          # provide the layer set information
          layerSet = c4d.LayerSet()
          layerSet.SetMode(c4d.LAYERSETMODE_LAYERS)
          layerSet.AddLayer(layerName)
          texshader[c4d.BITMAPSHADER_LAYERSET] = layerSet
          # insert the bitmap shader into the material
          mat.InsertShader(texshader)
          # assign the bitmap shader to the color channel
          mat[c4d.MATERIAL_COLOR_SHADER] = texshader
          
          # enable the alpha channel
          mat[c4d.MATERIAL_USE_ALPHA] = True
          # create a bitmap shader
          texshader = c4d.BaseShader(c4d.Xbitmap)
          texshader[c4d.BITMAPSHADER_FILENAME] = fileName
          # provide the layer set information
          layerSet = c4d.LayerSet()
          layerSet.SetMode(c4d.LAYERSETMODE_LAYERALPHA)
          layerSet.AddLayer(layerName)
          texshader[c4d.BITMAPSHADER_LAYERSET] = layerSet
          layerSet.SetPreviewMode(0)
          # insert the bitmap shader into the material
          mat.InsertShader(texshader)
          # assign the bitmap shader to the color channel
          mat[c4d.MATERIAL_ALPHA_SHADER] = texshader
          
          # by default the reflectance channel is enabled,
          # let's disable it
          mat[c4d.MATERIAL_USE_REFLECTION] = False
         
         
          # Create a new null and plane from scratch
          nl = c4d.BaseObject(c4d.Onull)
          nl.SetName(matName)
          nl.SetRelScale(c4d.Vector(i,i,i))
          doc.InsertObject(nl)
          pl = c4d.BaseObject(c4d.Oplane)
          pl.SetName(matName)
          pl[c4d.PRIM_PLANE_WIDTH] = 192
          pl[c4d.PRIM_PLANE_HEIGHT] = 108
          pl[c4d.PRIM_PLANE_SUBW] = 1
          pl[c4d.PRIM_PLANE_SUBH] = 1
          pl[c4d.PRIM_AXIS] = 5
          pl.SetRelPos(c4d.Vector(0,0, 200))
          doc.InsertObject(pl,nl)
          
          
          # Add a texture tag to the plane
          tt = c4d.TextureTag()
          tt.SetName(matName)
          tt.SetMaterial(mat)
          
          pl.InsertTag(tt)
           
          return
      
      
      
      
      def main():
      
          # load a multi layer psd file
          path = "/MyPath/test2.psd"
      
          bc = c4d.BaseContainer()
          bc.SetFilename(c4d.LOADTEXTURE_FILENAME, path.encode('utf-8'))
          tex = c4d.modules.bodypaint.SendPainterCommand(c4d.PAINTER_LOADTEXTURE, doc=doc, tex=None, bc=bc)
          if tex is None:
              print "Failed loading file"
              return
          
          # iterate over the layers and create the materials
          layer = tex.GetFirstLayer()
          i = 0
          while layer:
              i += 1
              layerName = layer.GetName()
              materialName = layerName
              CreateMaterial(materialName, path, layerName, i)
              
              # up to the next layer in the PSD
              layer = layer.GetNext()
          
              c4d.EventAdd()
            
          
      
      if __name__=='__main__':
          main()
      
      
      posted in Cinema 4D SDK
      Y
      yanmasterson
    • Creating shaders from PSD files

      Hi,

      Newbie here so forgive any breach of protocol etc!

      I'm trying to use python to assign PSD layers to individual materials, then apply these materials to a texture tag on individual planes (this can be used to create a pop-up book effect for example). The material previews look fine in the material window, and perfect when rendered with the standard renderer, but in the C4d view panel they all appear as the PSD layers all merged together (see pic attached of viewport vs rendered, with the material previews below). I suspect I'm missing a command to create a specific viewport or OpenGL texture from the material, or from the shader... Does anyone have any obvious suggestions or pointers?

      opengl texture is merged layers.jpg

      Thanks, Yan.

      posted in Cinema 4D SDK python
      Y
      yanmasterson