Newer
Older
Maurice Raybaud
committed
except (ValueError):
pass
cache = []
Maurice Raybaud
committed
if word == 'box':
box_search = True
name_search = False
if box_search:
cache.append(word)
if cache[-1] == '}':
try:
x0 = float(cache[2])
y0 = float(cache[3])
z0 = float(cache[4])
x1 = float(cache[5])
y1 = float(cache[6])
z1 = float(cache[7])
# imported_corner_1=(x0, y0, z0)
# imported_corner_2 =(x1, y1, z1)
center = (
(x0 + x1) / 2,
(y0 + y1) / 2,
(z0 + z1) / 2,
)
Maurice Raybaud
committed
bpy.ops.pov.addbox()
ob = context.object
ob.location = center
Maurice Raybaud
committed
except (ValueError):
pass
cache = []
Maurice Raybaud
committed
if word == 'cylinder':
cylinder_search = True
name_search = False
if cylinder_search:
cache.append(word)
if cache[-1] == '}':
try:
x0 = float(cache[2])
y0 = float(cache[3])
z0 = float(cache[4])
x1 = float(cache[5])
y1 = float(cache[6])
z1 = float(cache[7])
imported_cyl_loc = (x0, y0, z0)
imported_cyl_loc_cap = (x1, y1, z1)
Maurice Raybaud
committed
r = float(cache[8])
vec = Vector(imported_cyl_loc_cap) - Vector(
imported_cyl_loc
)
Maurice Raybaud
committed
depth = vec.length
rot = Vector((0, 0, 1)).rotation_difference(
vec
) # Rotation from Z axis.
trans = rot @ Vector(
(0, 0, depth / 2)
) # Such that origin is at center of the base of the cylinder.
# center = ((x0 + x1)/2,(y0 + y1)/2,(z0 + z1)/2)
scaleZ = (
sqrt(
(x1 - x0) ** 2
+ (y1 - y0) ** 2
+ (z1 - z0) ** 2
)
/ 2
)
bpy.ops.pov.addcylinder(
R=r,
imported_cyl_loc=imported_cyl_loc,
imported_cyl_loc_cap=imported_cyl_loc_cap,
)
Maurice Raybaud
committed
ob = context.object
ob.location = (x0, y0, z0)
ob.rotation_euler = rot.to_euler()
ob.scale = (1, 1, scaleZ)
# scale data rather than obj?
Maurice Raybaud
committed
# bpy.ops.object.mode_set(mode='EDIT')
# bpy.ops.mesh.reveal()
# bpy.ops.mesh.select_all(action='SELECT')
# bpy.ops.transform.resize(value=(1,1,scaleZ), orient_type='LOCAL')
Maurice Raybaud
committed
# bpy.ops.mesh.hide(unselected=False)
# bpy.ops.object.mode_set(mode='OBJECT')
mat_search(cache)
Maurice Raybaud
committed
except (ValueError):
pass
cache = []
cylinder_search = False
if word == 'sphere':
sphere_search = True
name_search = False
if sphere_search:
cache.append(word)
if cache[-1] == '}':
Maurice Raybaud
committed
try:
x = float(cache[2])
y = float(cache[3])
z = float(cache[4])
r = float(cache[5])
Maurice Raybaud
committed
except (ValueError):
pass
except:
x = y = z = float(cache[2])
r = float(cache[3])
bpy.ops.pov.addsphere(R=r, imported_loc=(x, y, z))
ob = context.object
ob.location = (x, y, z)
ob.scale = (r, r, r)
Maurice Raybaud
committed
cache = []
##################End Primitives Import##################
Maurice Raybaud
committed
if word == '#declare':
name_search = True
if name_search:
cache.append(word)
if word == 'mesh2':
name_search = False
if cache[-2] == '=':
name = cache[-3]
else:
Maurice Raybaud
committed
cache = []
if word in {'texture', ';'}:
Maurice Raybaud
committed
name_search = False
cache = []
if word == 'vertex_vectors':
Maurice Raybaud
committed
if verts_search:
Maurice Raybaud
committed
if word == '}':
verts_search = False
Maurice Raybaud
committed
cache.pop()
cache.pop(0)
cache.pop(0)
cache.pop(0)
for i in range(int(lenverts)):
x = i * 3
y = (i * 3) + 1
z = (i * 3) + 2
verts.append(
(
float(cache[x]),
float(cache[y]),
float(cache[z]),
)
)
# if word == 'face_indices':
# faces_search = True
if word == 'texture_list': ########
tex_search = True #######
if tex_search: #########
if (
word
not in {
'texture_list',
'texture',
'{',
'}',
'face_indices',
}
and word.isdigit() == False
): ##############
povMats.append(word) #################
Maurice Raybaud
committed
if word == 'face_indices':
tex_search = False ################
faces_search = True
Maurice Raybaud
committed
if faces_search:
Maurice Raybaud
committed
if word == '}':
faces_search = False
lenfaces = cache[2]
cache.pop()
cache.pop(0)
cache.pop(0)
cache.pop(0)
lf = int(lenfaces)
var = int(len(cache) / lf)
Maurice Raybaud
committed
for i in range(lf):
if var == 3:
v0 = i * 3
v1 = i * 3 + 1
v2 = i * 3 + 2
faces.append(
(
int(cache[v0]),
int(cache[v1]),
int(cache[v2]),
)
)
Maurice Raybaud
committed
if var == 4:
v0 = i * 4
v1 = i * 4 + 1
v2 = i * 4 + 2
m = i * 4 + 3
Maurice Raybaud
committed
materials.append((int(cache[m])))
faces.append(
(
int(cache[v0]),
int(cache[v1]),
int(cache[v2]),
)
)
Maurice Raybaud
committed
if var == 6:
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
v0 = i * 6
v1 = i * 6 + 1
v2 = i * 6 + 2
m0 = i * 6 + 3
m1 = i * 6 + 4
m2 = i * 6 + 5
materials.append(
(
int(cache[m0]),
int(cache[m1]),
int(cache[m2]),
)
)
faces.append(
(
int(cache[v0]),
int(cache[v1]),
int(cache[v2]),
)
)
# mesh = pov_define_mesh(None, verts, [], faces, name, hide_geometry=False)
# ob = object_utils.object_data_add(context, mesh, operator=None)
me = bpy.data.meshes.new(name) ########
ob = bpy.data.objects.new(name, me) ##########
bpy.context.collection.objects.link(ob) #########
me.from_pydata(verts, [], faces) ############
for mat in bpy.data.materials: ##############
blendMats.append(mat.name) #############
for mName in povMats: #####################
if mName not in blendMats: ###########
povMat = bpy.data.materials.new(
mName
) #################
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
ob.data.materials.append(
bpy.data.materials[mName]
) ###################
if materials: ##################
for i, val in enumerate(
materials
): ####################
try: ###################
ob.data.polygons[
i
].material_index = (
val
) ####################
except TypeError: ###################
ob.data.polygons[
i
].material_index = int(
val[0]
) ##################
blendMats = [] #########################
povMats = [] #########################
materials = [] #########################
Maurice Raybaud
committed
cache = []
name_search = True
if name in matrixes and self.import_at_cur == False:
global_matrix = Matrix.Rotation(
pi / 2.0, 4, 'X'
)
Maurice Raybaud
committed
ob = bpy.context.object
matrix = ob.matrix_world
v = matrixes[name]
matrix[0][0] = v[0]
matrix[1][0] = v[1]
matrix[2][0] = v[2]
matrix[0][1] = v[3]
matrix[1][1] = v[4]
matrix[2][1] = v[5]
matrix[0][2] = v[6]
matrix[1][2] = v[7]
matrix[2][2] = v[8]
matrix[0][3] = v[9]
matrix[1][3] = v[10]
matrix[2][3] = v[11]
matrix = global_matrix * ob.matrix_world
Maurice Raybaud
committed
ob.matrix_world = matrix
verts = []
faces = []
# if word == 'pigment':
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
# try:
# #all indices have been incremented once to fit a bad test file
# r,g,b,t = float(S[2]),float(S[3]),float(S[4]),float(S[5])
# color = (r,g,b,t)
# except (IndexError):
# #all indices have been incremented once to fit alternate test file
# r,g,b,t = float(S[3]),float(S[4]),float(S[5]),float(S[6])
# color = (r,g,b,t)
# except UnboundLocalError:
# # In case no transmit is specified ? put it to 0
# r,g,b,t = float(S[2]),float(S[3]),float(S[4],0)
# color = (r,g,b,t)
# except (ValueError):
# color = (0.8,0.8,0.8,0)
# pass
# if colors == [] or (colors != [] and color not in colors):
# colors.append(color)
# name = ob.name+"_mat"
# matNames.append(name)
# mat = bpy.data.materials.new(name)
# mat.diffuse_color = (r,g,b)
# mat.alpha = 1-t
# if mat.alpha != 1:
# mat.use_transparency=True
# ob.data.materials.append(mat)
# print (colors)
# else:
# for i in range(len(colors)):
# if color == colors[i]:
# ob.data.materials.append(bpy.data.materials[matNames[i]])
# for obj in bpy.context.view_layer.objects:
# if obj.type == "CAMERA":
# track = obj.constraints.new(type = "TRACK_TO")
# track.target = ob
# track.track_axis ="TRACK_NEGATIVE_Z"
# track.up_axis = "UP_Y"
# obj.location = (0,0,0)
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
classes = (
POVRAY_OT_lathe_add,
POVRAY_OT_superellipsoid_add,
POVRAY_OT_superellipsoid_update,
POVRAY_OT_supertorus_add,
POVRAY_OT_supertorus_update,
POVRAY_OT_loft_add,
POVRAY_OT_plane_add,
POVRAY_OT_box_add,
POVRAY_OT_cylinder_add,
POVRAY_OT_cylinder_update,
POVRAY_OT_sphere_add,
POVRAY_OT_sphere_update,
POVRAY_OT_cone_add,
POVRAY_OT_cone_update,
POVRAY_OT_isosurface_box_add,
POVRAY_OT_isosurface_sphere_add,
POVRAY_OT_sphere_sweep_add,
POVRAY_OT_blob_add,
POVRAY_OT_rainbow_add,
POVRAY_OT_height_field_add,
POVRAY_OT_torus_add,
POVRAY_OT_torus_update,
POVRAY_OT_prism_add,
POVRAY_OT_parametric_add,
POVRAY_OT_parametric_update,
POVRAY_OT_shape_polygon_to_circle_add,
ImportPOV,
)
def register():
# from bpy.utils import register_class