Changeset 8505:5a39af2c4644 in orange


Ignore:
Timestamp:
07/28/11 10:30:56 (3 years ago)
Author:
matejd <matejd@…>
Branch:
default
Convert:
4d04886ffcbef7c34337f6b821cf95ed5090ec2d
Message:

Ability to load 3d symbols normals when specified for smoother appearance

Location:
orange/OrangeWidgets/plot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/plot/owplot3d.py

    r8497 r8505  
    10241024            ss = size*0.08 
    10251025            for v0, v1, v2, n0, n1, n2 in triangles: 
    1026                 vertices.extend([x,y,z, ai, ss*v0[0],ss*v0[1],ss*v0[2], r,g,b,a, n0,n1,n2, 
    1027                                  x,y,z, ai, ss*v1[0],ss*v1[1],ss*v1[2], r,g,b,a, n0,n1,n2, 
    1028                                  x,y,z, ai, ss*v2[0],ss*v2[1],ss*v2[2], r,g,b,a, n0,n1,n2]) 
     1026                vertices.extend([x,y,z, ai, ss*v0[0],ss*v0[1],ss*v0[2], r,g,b,a, n0[0],n0[1],n0[2], 
     1027                                 x,y,z, ai, ss*v1[0],ss*v1[1],ss*v1[2], r,g,b,a, n1[0],n1[1],n1[2], 
     1028                                 x,y,z, ai, ss*v2[0],ss*v2[1],ss*v2[2], r,g,b,a, n2[0],n2[1],n2[2]]) 
    10291029 
    10301030        # Build Vertex Buffer + Vertex Array Object. 
  • orange/OrangeWidgets/plot/owprimitives3d.py

    r8489 r8505  
    11import os 
     2import re 
    23from owplot3d import Symbol, normal_from_points 
    34 
    45symbol_map = { 
    5     Symbol.RECT:      'primitives/cube.obj', 
     6    Symbol.RECT:      'primitives/sphere.obj', 
    67    Symbol.TRIANGLE:  'primitives/pyramid.obj', 
    78    Symbol.DTRIANGLE: 'primitives/dpyramid.obj', 
     
    2425    file_name = symbol_map[symbol] 
    2526    lines = open(os.path.join(os.path.dirname(__file__), file_name)).readlines() 
     27    normals_lines =  filter(lambda line: line.startswith('vn'), lines) 
    2628    vertices_lines = filter(lambda line: line.startswith('v'), lines) 
     29    faces_lines =    filter(lambda line: line.startswith('f'), lines) 
     30    normals =  [map(float, line.split()[1:]) for line in normals_lines] 
    2731    vertices = [map(float, line.split()[1:]) for line in vertices_lines] 
    28     faces_lines = filter(lambda line: line.startswith('f'), lines) 
    29     faces = [map(int, line.split()[1:]) for line in faces_lines] 
    30     triangles = [[vertices[face[0]-1], 
    31                   vertices[face[1]-1], 
    32                   vertices[face[2]-1]] for face in faces] 
    33     for triangle in triangles: 
    34         triangle.extend(normal_from_points(*triangle)) 
     32    if len(normals) > 0: 
     33        pattern = 'f (\d+)//(\d+) (\d+)//(\d+) (\d+)//(\d+)' 
     34        faces = [map(int, re.match(pattern, line).groups()) for line in faces_lines] 
     35        triangles = [[vertices[face[0]-1], 
     36                      vertices[face[2]-1], 
     37                      vertices[face[4]-1], 
     38                      normals[face[1]-1], 
     39                      normals[face[3]-1], 
     40                      normals[face[5]-1]] for face in faces] 
     41    else: 
     42        faces = [map(int, line.split()[1:]) for line in faces_lines] 
     43        triangles = [] 
     44        for face in faces: 
     45            v0 = vertices[face[0]-1] 
     46            v1 = vertices[face[1]-1] 
     47            v2 = vertices[face[2]-1] 
     48            normal = normal_from_points(v0, v1, v2) 
     49            triangles.append([v0, v1, v2, normal, normal, normal]) 
    3550    symbol_data[symbol] = triangles 
    3651    return triangles 
Note: See TracChangeset for help on using the changeset viewer.