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. sheilan
    S
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 19
    • Best 1
    • Controversial 0
    • Groups 0

    sheilan

    @sheilan

    2
    Reputation
    55
    Profile views
    19
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    sheilan Unfollow Follow

    Best posts made by sheilan

    • RE: Adding polygon UVs & Normals.

      Well then that'll be it. Thanks a lot for all the help!
      I'll definitely read the manual to get a better idea of each tag.

      Here is the final, working code to anyone who reads this thread having the same problems:

      def CreateNormalTag(op,polyCnt):
          """
           Creates a NormalTag on the passed PolygonObject.
      
          :param op: The PolygonObject that will received a normal Tag.
          :type op: c4d.PolygonObject
          :return: The created tag.
          :rtype: c4d.NormalTag
          """
          # Checks if the passed object is a polygon object.
          if not isinstance(op, c4d.PolygonObject):
              raise TypeError("op is not a c4d.PolygonObject.")
          
      
          # Creates a Normal Tag in memory only
          normalTag = c4d.NormalTag(polyCnt)
          if normalTag is None:
              raise MemoryError("Failed to creates a normal Tag.")
      
          # Inserts the tag to the passed object
          op.InsertTag(normalTag)
      
          # Notifies the object he need to update to take care of the newly created normal tag
          op.Message(c4d.MSG_UPDATE)
          return normalTag
      def WriteNormalTag(tag, normalList):
          """
          Write the raw data to a Normal Tag.
      
          :param tag: The Normal Tag to write the data to.
          :type tag: c4d.NormalTag
          :param normalList: A list with all the raw data.
          :type normalList: list[int]
          """
          # Retrieves the write buffer array
          buffer = tag.GetLowlevelDataAddressW()
          if buffer is None:
              raise RuntimeError("Failed to retrieves internal write data for the normal tag.")
      
          # Translates list of short int 16 to a BitSeq (string are byte in Python 2.7)
          intArray = array.array('h')
          intArray.fromlist(normalList)
          data = intArray.tostring()
          buffer[:len(data)] = data
      
      # Some of the data was read in a binary file/determined earlier but the variable names should be enough to tell what they are
      for i in range(surfaceCount):
              # Surface triangles count
              triCount = read_ushort(c2m)
              # Surface Material Name
              materialName = read_string(c2m)
              tri_vertexgroups = {}
              tri_uvgroups = {}
              tri_normalgroups = {}
              for f in range(triCount):
                  vertex = vertex1,vertex2,vertex3 # pre-loaded 3 vertex indices for current face
                  uv = uv1,uv2,uv3 # pre-loaded 3 UV indices for current face
                  normal = normal1,normal2,normal3 # pre-loaded 3 normal indices for current face
      
                  # Add them to a dictionary
                  tri_vertexgroups[f] = vertex
                  tri_uvgroups[f] = uv
                  tri_normalgroups[f] = normal
      
              # Create dictionary for surface's vertices
              surface_vertices = {}
              # Unique vertex index (used to avoid creating the same vertex twice)
              unique_vertex = 0
      
              # Create new poly
              mypoly = c4d.BaseObject(c4d.Opolygon) #Create an empty polygon object
              mypoly.SetName(materialName) 
              uv_tag = c4d.UVWTag(triCount)   
              nrm_tag = CreateNormalTag(mypoly,triCount)
              phong_tag = c4d.BaseTag(c4d.Tphong)
              phong_tag[c4d.PHONGTAG_PHONG_ANGLELIMIT]=True
              phong_tag[c4d.PHONGTAG_PHONG_ANGLE]=c4d.utils.Rad(25.5)
              phong_tag[c4d.PHONGTAG_PHONG_USEEDGES]=True
              normalList = []
              # Loop through number of triangles
              for f in range(triCount):
                  # Load vertices for current triangle from the list of polygon's vertices
                  tri_vertices = tri_vertexgroups[f]
      
                  # Load each vertex of the triangle from a dictionary with all the UVs in the scene using it's index
                  vertex1 = vertices_positions[tri_vertices[0]]
                  vertex2 = vertices_positions[tri_vertices[1]]
                  vertex3 = vertices_positions[tri_vertices[2]]
      
                  # Check if vertex was not added already, add if not.
                  if vertex1 not in surface_vertices:
                      # Add vertex1 to surface(polygon object)'s dictionary, with a unique index
                      surface_vertices[vertex1] = unique_vertex
                      unique_vertex += 1
                      # Resize our object to allow another point to be created
                      mypoly.ResizeObject(unique_vertex, triCount)
                      # Create new point
                      mypoly.SetPoint(surface_vertices[vertex1],c4d.Vector(vertex1[0],vertex1[1],vertex1[2]))
      
                  if vertex2 not in surface_vertices:
                      surface_vertices[vertex2] = unique_vertex
                      unique_vertex += 1
                      mypoly.ResizeObject(unique_vertex, triCount)
                      mypoly.SetPoint(surface_vertices[vertex2],c4d.Vector(vertex2[0],vertex2[1],vertex2[2]))
      
                  if vertex3 not in surface_vertices:
                      surface_vertices[vertex3] = unique_vertex
                      unique_vertex += 1
                      mypoly.ResizeObject(unique_vertex, triCount)
                      mypoly.SetPoint(surface_vertices[vertex3],c4d.Vector(vertex3[0],vertex3[1],vertex3[2]))
      
                  # Load UVs for current triangle from the list of polygon's UVs
                  tri_uvs = tri_uvgroups[f]
                  
                  # Load each UV of the triangle from a dictionary with all the UVs in the scene using it's index
                  uv1 = vertices_uvs[tri_uvs[0]]
                  uv2 = vertices_uvs[tri_uvs[1]]
                  uv3 = vertices_uvs[tri_uvs[2]]
      
                  # Create polygon(triangle)
                  mypoly.SetPolygon(f, c4d.CPolygon(surface_vertices[vertex1],surface_vertices[vertex2],surface_vertices[vertex3]))
                  # Add our UV data to the UV tag
                  uv_tag.SetSlow(f, c4d.Vector(uv1[0], uv1[1], 0),
                              c4d.Vector(uv2[0], uv2[1], 0),  
                              c4d.Vector(uv3[0], uv3[1], 0),  
                              c4d.Vector(0,0,0))  
      
                  # Load normals for current triangle from the list of polygon's normals
                  tri_normals = tri_normalgroups[f]
      
                  # Load each normal of the triangle from a dictionary with all the normals in the scene using it's index
                  normal1 = vertices_normals[tri_normals[0]] # Vector3 of normal direction
                  normal2 = vertices_normals[tri_normals[1]]
                  normal3 = vertices_normals[tri_normals[2]]
                  normal4 = [0.0, 0.0, 0.0]  # Even if it's a Tri, you should pass a value.
      
                  # Add normals to normalList
                  normalList.extend(normal1)
                  normalList.extend(normal2)
                  normalList.extend(normal3)
                  normalList.extend(normal4)
                  
              # Maps data from float to int16 value
              normalListToSet = [int(normal * 32000.0) for normal in normalList]
      
              # Writes the previous list to the normal tag.
              WriteNormalTag(nrm_tag, normalListToSet)
      
              doc.InsertObject(mypoly,None,None)
              mypoly.Message(c4d.MSG_UPDATE)
              mypoly.InsertTag(uv_tag)
              mypoly.Message(c4d.MSG_UPDATE)
              mypoly.InsertTag(phong_tag)
              mypoly.Message(c4d.MSG_UPDATE)
              
              c4d.EventAdd()
      

      Thank you once again Maxime, your help is appreciated!

      posted in Cinema 4D SDK
      S
      sheilan

    Latest posts made by sheilan

    • RE: Matrix/HPB to XYZ and vice versa

      @m_magalhaes said in Matrix/HPB to XYZ and vice versa:

      convert the matrix to XYZ

      xyz =  c4d.utils.MatrixToHPB(m, order=c4d.ROTATIONORDER_XYZGLOBAL)
      
      # convert from radian to deg
      for i in xrange(3):
          xyz[i] = c4d.utils.RadToDeg(xyz[i])
      
      print xyz
      

      Works perfectly. Thanks!

      posted in Cinema 4D SDK
      S
      sheilan
    • RE: Matrix/HPB to XYZ and vice versa

      @m_magalhaes

      I tried creating a cube and setting it's HBP manually.
      HBP - 47º 0º 0º
      XYZ - 0º 47º 0º

      and the result is

      Vector(0.82, 0, 0)
      Vector(0, 0.82, 0)
      Vector(0, 0.82, 0)
      

      What I need is a result of Vector float that shows (0.0, 47.0, 0,0) (XYZ) as a result.

      posted in Cinema 4D SDK
      S
      sheilan
    • RE: Matrix/HPB to XYZ and vice versa

      @m_magalhaes Hello,

      You misunderstood. I'm able to get Matrix & HBP but I need XYZ. I'm looking for either MatrixToXYZ or HPBToXYZ (preferably the first one).

      Thanks,
      Sheilan.

      posted in Cinema 4D SDK
      S
      sheilan
    • Matrix/HPB to XYZ and vice versa

      Hello,

      I've got some models in two different softwares, when one is using XYZ rotation and the other (cinema 4d) uses HPB/Matrix.
      I couldn't find a way to get my model's XYZ via Python (only Matrix), so I'm looking to see how can I translate rotation matrix or HPB to XYZ and vice versa.

      Thanks in advance,
      Sheilan.

      posted in Cinema 4D SDK python r20
      S
      sheilan
    • RE: Getting Tag by name

      @m_magalhaes Oh yeah I forgot to add the tags. I'm using Python by the way.
      You can count this post as solved.

      posted in Cinema 4D SDK
      S
      sheilan
    • Getting Tag by name

      Hello,

      Is it possible to just get a tag by its name without looping through all tags and checking each name?

      Thanks,
      Sheilan.

      posted in Cinema 4D SDK python r20
      S
      sheilan
    • RE: Moving\Deleting nodes with Python

      Works perfectly. Thanks!

      posted in Cinema 4D SDK
      S
      sheilan
    • Moving\Deleting nodes with Python

      Hello,

      I've got a GvNode that I can rename and control, but I'm not sure how I can delete or move it's position in Xpresso.

      Thanks in advance,
      Sheilan.

      posted in Cinema 4D SDK python r20
      S
      sheilan
    • RE: Accessing Octane node editor with python

      @Graeme Thank you very much!
      @r_gigante Will do, thanks.

      posted in General Talk
      S
      sheilan
    • Accessing Octane node editor with python

      Hello,

      I know Octane isnt related to Maxon devs, but perhaps someone knows how to do that.
      Ive creates new octane material and assigned image textures, but unfortunately thats not enough. I need to access the node editor to modify those images using the nodes, but I cant seem to find anything about Octane + Python.

      Thanks,
      Sheilan.

      posted in General Talk r20
      S
      sheilan