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

    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
    • 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
    • RE: Adding polygon UVs & Normals.

      Hello @m_adam ,

      Skip to the edit below.

      ────────────────────
      Thanks again for the reply but the normal tag still doesn't seem to be doing anything.
      Here's how the code looks right now :

      # Looping through each surface (polygon object/mesh/model) in the scene
      for i in range(surfaceCount):
          #Create new polygon object
          mypoly = c4d.BaseObject(c4d.Opolygon) #Create an empty polygon object
          mypoly.SetName(materialName)
          uv_tag = c4d.UVWTag(triCount)   
          # triCount & materialName are variables I use to store the name of the object + the polycount
          nrm_tag = CreateNormalTag(mypoly,triCount)
          normalList = [] # Fresh new normalList created for each PolygonObject I'm working on
      
          # loop through each triangle/poly and gather it's data from my binary file
          for f in range(triCount):
              # The points, polys & uv creation part is unnecessary here so I skipped right to normals
      
              a = [normal1[0],normal1[1],normal1[2]]
              b = [normal2[0],normal2[1],normal2[2]]
              c = [normal3[0],normal3[1],normal3[2]]
              d = [0.0, 0.0, 0.0] 
      
              # Add normals to normalList
              normalList.extend(a)
              normalList.extend(b)
              normalList.extend(c)
              normalList.extend(d)
      
          # After we are done looping through the triangles, all polys are created including their points, polygons, UVs & the normalList
          normalListToSet = [int(normal * 32000.0) for normal in normalList] # set of all normals for this polygon object
          WriteNormalTag(nrm_tag, normalListToSet)
          nrm_tag = mypoly.GetTag(c4d.Tnormal) # This is probably unnecessary but I used it just in case
      
          # Retrieves the raw data stored into the tag
          rawNormalData = ReadNormalTag(nrm_tag)
      
          # Prints the current value stored in tag, since data are stored as int16 and not float you have to divide them by 32000.0
          print "current data stored in tag - should go from 0 to 1"
          print [normal / 32000.0 for normal in rawNormalData]
      
          # Creates a list representing a float gradient value from 0 to 1 then remap these value from float to int16 by multiplying them
          valueToSet = [int(float(normalID) / len(rawNormalData) * 32000.0) for normalID in xrange(len(rawNormalData))]
      
          # Writes the previous list to the normal tag.
          WriteNormalTag(nrm_tag, valueToSet)
      
          print "new values of normal tag"        
          print [normal / 32000.0 for normal in ReadNormalTag(nrm_tag)]
      

      Now here are results of few of the normal tags in the scene

      old data stored in tag
      
      [0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.994125, -0.07825, -0.05478125, 0.0, 0.0, 0.0]
      
      new data of normal tag
      
      [0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
      
      old data stored in tag
      
      [1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0]
      
      new data of normal tag
      
      [0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
      
      old data stored in tag
      
      [-1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]
      
      new data of normal tag
      
      [0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
      
      old data stored in tag
      
      [-1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.0, 0.0, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.7064375, 0.7064375, 0.0, 0.0, 0.0, 0.0]
      
      new data of normal tag
      
      [0.0, 0.0208125, 0.04165625, 0.0625, 0.0833125, 0.10415625, 0.125, 0.1458125, 0.16665625, 0.1875, 0.2083125, 0.22915625, 0.25, 0.2708125, 0.29165625, 0.3125, 0.3333125, 0.35415625, 0.375, 0.3958125, 0.41665625, 0.4375, 0.4583125, 0.47915625, 0.5, 0.5208125, 0.54165625, 0.5625, 0.5833125, 0.60415625, 0.625, 0.6458125, 0.66665625, 0.6875, 0.7083125, 0.72915625, 0.75, 0.7708125, 0.79165625, 0.8125, 0.8333125, 0.85415625, 0.875, 0.8958125, 0.91665625, 0.9375, 0.9583125, 0.97915625]
      

      Could this happen because I don't use Phong Tag?

      Edit:

      Yes it was definitely Phong Tags! Also, this was enough using my initial normal data

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

      Anyway, I imported an .obj file that shares the same data as my binary file, and once I copied the Phong Tag settings and applied to my generated objects it was identical, which means Normal Tags are correct!

      I can't seem to find a page for Phong Tag though. How would I create a new Phong Tag, and set it's values?

      Your help has already done a lot and I really appreciate your responses.
      Thanks,
      Sheilan.

      posted in Cinema 4D SDK
      S
      sheilan
    • RE: Adding polygon UVs & Normals.

      @m_adam
      I'm getting an error when trying to use the functions he later posted as a workaround.

      Here's the updated code

      # Create UV Tag
      uv_tag = c4d.UVWTag(polyCount)
      # Create Normal Tag
      nrmTag = c4d.NormalTag(polyCount)
      # Create Normal List
      normalList = []
      
      for f in range(polyCount):
          # Loading & Creating points from the binary file
          ### I chose to not add this part as it's irrelevant
      
          # Load UV's for first point
          uv1 = vertices_uvs[tri_uvs[0]]
          # Load UV's for second point
          uv2 = vertices_uvs[tri_uvs[1]]
          # Load UV's for third point
          uv3 = vertices_uvs[tri_uvs[2]]
          # Create polygon with 3 points
          mypoly.SetPolygon(f, c4d.CPolygon(surface_vertices[vertex1],surface_vertices[vertex2],surface_vertices[vertex3]))
          # Create poly UV
          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 first point
          normal1 = vertices_normals[tri_normals[0]]
          # Load Normals for second point    
          normal2 = vertices_normals[tri_normals[1]]
          # Load Normals for third point
          normal3 = vertices_normals[tri_normals[2]]
          
          # Add normals to their points
          a = c4d.Vector(normal1[0],normal1[1],normal1[2])
          b = c4d.Vector(normal2[0],normal2[1],normal2[2])
          c = c4d.Vector(normal3[0],normal3[1],normal3[2])
          d = c4d.Vector() # I tried setting as empty vector or same as C (it's a triangle poly)
      
          # Add normals to normalList
          normalList.append(a)
          normalList.append(b)
          normalList.append(c)
          normalList.append(d)
      
      # Set normalList to Normal Tag of object
      SetAllHighLevelNormals(nrmTag, normalList)
      normalList = GetLowLevelNormals(nrmTag,mypoly)
      SetAllHighLevelNormals(nrmTag, normalList)
      
      mypoly.Message(c4d.MSG_UPDATE)
      # Add object
      doc.InsertObject(mypoly,None,None)
      doc.AddUndo(c4d.UNDOTYPE_NEW, mypoly)
      # Add UV Tag
      mypoly.InsertTag(uv_tag)
      doc.AddUndo(c4d.UNDOTYPE_NEW, uv_tag)
      # Add Normal Tag
      mypoly.InsertTag(nrmTag)
      doc.AddUndo(c4d.UNDOTYPE_NEW, nrmTag) 
      mypoly.Message(c4d.MSG_UPDATE)
      c4d.EventAdd()
      doc.EndUndo()
      

      I get TypeError: unsupported operand type(s) for *: 'int' and 'c4d.PolygonObject'
      I'm rather confused about what type of variable polygon is in his function as theres no context.

      posted in Cinema 4D SDK
      S
      sheilan
    • RE: Adding polygon UVs & Normals.

      Ok I seem to be doing something wrong with the Normals.

      Even though the Normal Tag is there, it doesn't seem to be doing anything.
      Here's the code (using functions from the post you posted)

      # Create UV Tag
      uv_tag = c4d.UVWTag(polyCount)
      # Create Normal Tag
      nrmTag = c4d.NormalTag(polyCount)
      # Create Normal List
      normalList = []
      
      for f in range(polyCount):
          # Loading & Creating points from the binary file
          ### I chose to not add this part as it's irrelevant
      
          # Load UV's for first point
          uv1 = vertices_uvs[tri_uvs[0]]
          # Load UV's for second point
          uv2 = vertices_uvs[tri_uvs[1]]
          # Load UV's for third point
          uv3 = vertices_uvs[tri_uvs[2]]
          # Create polygon with 3 points
          mypoly.SetPolygon(f, c4d.CPolygon(surface_vertices[vertex1],surface_vertices[vertex2],surface_vertices[vertex3]))
          # Create poly UV
          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 first point
          normal1 = vertices_normals[tri_normals[0]]
          # Load Normals for second point    
          normal2 = vertices_normals[tri_normals[1]]
          # Load Normals for third point
          normal3 = vertices_normals[tri_normals[2]]
          
          # Add normals to their points
          a = c4d.Vector(normal1[0],normal1[1],normal1[2])
          b = c4d.Vector(normal2[0],normal2[1],normal2[2])
          c = c4d.Vector(normal3[0],normal3[1],normal3[2])
          d = c4d.Vector() # I tried setting as empty vector or same as C (it's a triangle poly)
      
          # Add normals to normalList
          normalList.append(a)
          normalList.append(b)
          normalList.append(c)
          normalList.append(d)
      
      # Set normalList to Normal Tag of object
      SetAllHighLevelNormals(nrmTag, normalList)
      mypoly.Message(c4d.MSG_UPDATE)
      # Add object
      doc.InsertObject(mypoly,None,None)
      doc.AddUndo(c4d.UNDOTYPE_NEW, mypoly)
      # Add UV Tag
      mypoly.InsertTag(uv_tag)
      doc.AddUndo(c4d.UNDOTYPE_NEW, uv_tag)
      # Add Normal Tag
      mypoly.InsertTag(nrmTag)
      doc.AddUndo(c4d.UNDOTYPE_NEW, nrmTag) 
      
      mypoly.Message(c4d.MSG_UPDATE)
      c4d.EventAdd()
      doc.EndUndo()
      

      I checked one of the normalLists before & after the conversion using the SetAllHighLevelNormals() function and those were the results
      before:

      [1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0]
      

      after:

      [32000, 0, 0, 32000, 0, 0, 0, 0, 0, 32000, 0, 0, 32000, 0, 0, 32000, 0, 0, 0, 0, 0, 32000, 0, 0, 0, 32000, 0, 0, 32000, 0, 0, 0, 0, 0, 32000, 0, 0, 32000, 0, 0, 32000, 0, 0, 0, 0, 0, 32000, 0, 0, 0, 32000, 0, 0, 32000, 0, 0, 0, 0, 0, 32000, 0, 0, 32000, 0, 0, 32000, 0, 0, 0, 0, 0, 32000, 0, 33536, 0, 0, 33536, 0, 0, 0, 0, 0, 33536, 0, 0, 33536, 0, 0, 33536, 0, 0, 0, 0, 0, 33536, 0, 33536, 0, 0, 33536, 0, 0, 0, 0, 0, 33536, 0, 0, 33536, 0, 0, 33536, 0, 0, 0, 0, 0, 33536, 0, 0]
      

      UVW Tag works perfectly, Normal Tag doesn't.

      Thanks,
      Sheilan.

      posted in Cinema 4D SDK
      S
      sheilan
    • RE: Adding polygon UVs & Normals.

      @m_adam

      Thanks a lot!
      I've managed to do UV's thanks to the first method, trying my luck with Normals now.

      One more thing I'm curious about is Phong Tag. When I'm importing the same mesh in OBJ format, it seems to create Normal tag & Phong tag, both seem to affect the normals of the mesh. Now since I'm working with the same data, should I use the vertex normal data to generate both Normal tag & Phong tag, or would one be enough?

      Thanks,
      Sheilan.

      posted in Cinema 4D SDK
      S
      sheilan
    • Adding polygon UVs & Normals.

      Hello,

      I've made a custom binary file format that contains model data similar to .OBJ (vertices, normals, uvs & indices for each triangle)
      I've managed to create the polygons with using the vertices via the faces indices, but adding Normals & UVs seems to be a little trickier. I've read the SDK about UVWTag but I can't seem to understand how to translate the two values used for each face (U & V) into a UVWTag via python.

      Any help appreciated!

      posted in Cinema 4D SDK python r20
      S
      sheilan
    • Force custom file format in LoadDialog()

      Hello, I see it's possible to select one of the four types but is it possible to force the LoadDialog to only show/load a specified file format?

      posted in Cinema 4D SDK python
      S
      sheilan