Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Help on snippet

Help on snippet

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
c++pythondatabasetoolshelp
3 Posts 2 Posters 0 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    ant damage
    wrote on last edited by
    #1

    Hi I'm trying to convert a python script from blender to C++. The script is used to import 3D data from a file. Things have been going right until I got to this part of the script:

    # Generate verts and faces lists, without duplicates
    verts = []
    coords = {}
    index = 0

    for f in faces:
    if f: # Line might be blank
    for i, v in enumerate(f):
    try:
    f[i]= coords[v]
    except:
    f[i]= coords[v] = index
    index += 1
    verts.append(v)

    Since I don't know python, I need help to interpretate this part of the code.

    D 1 Reply Last reply
    0
    • A ant damage

      Hi I'm trying to convert a python script from blender to C++. The script is used to import 3D data from a file. Things have been going right until I got to this part of the script:

      # Generate verts and faces lists, without duplicates
      verts = []
      coords = {}
      index = 0

      for f in faces:
      if f: # Line might be blank
      for i, v in enumerate(f):
      try:
      f[i]= coords[v]
      except:
      f[i]= coords[v] = index
      index += 1
      verts.append(v)

      Since I don't know python, I need help to interpretate this part of the code.

      D Offline
      D Offline
      darkjade
      wrote on last edited by
      #2

      Hi - since my C++ is a bit rusty, I'll give you a pseudocode representation of the snippet:

      for each face in faces
      do
      if "face is not a blank line"
      then
      for i = 1 to length(face)
      do
      v = face[i]
      if v is not in coords // coords is a hashtable
      then
      coords.add_item(key=v, value=index)
      index += 1
      verts.append(v)
      fi
      face[i] = coords.get_item(key=v)
      end for
      fi
      end for

      I think that should be it. Hope it helps. Meh, just saw the date on this post - but now I have already typed it, so might as well submit :P

      A 1 Reply Last reply
      0
      • D darkjade

        Hi - since my C++ is a bit rusty, I'll give you a pseudocode representation of the snippet:

        for each face in faces
        do
        if "face is not a blank line"
        then
        for i = 1 to length(face)
        do
        v = face[i]
        if v is not in coords // coords is a hashtable
        then
        coords.add_item(key=v, value=index)
        index += 1
        verts.append(v)
        fi
        face[i] = coords.get_item(key=v)
        end for
        fi
        end for

        I think that should be it. Hope it helps. Meh, just saw the date on this post - but now I have already typed it, so might as well submit :P

        A Offline
        A Offline
        ant damage
        wrote on last edited by
        #3

        It's ok! And thanks, it helped!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups