-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlenderScript.py
More file actions
126 lines (92 loc) · 3.41 KB
/
BlenderScript.py
File metadata and controls
126 lines (92 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import bpy
import numpy as np
import math
import sys
import os
dir = os.path.dirname(bpy.data.filepath)
if not dir in sys.path:
sys.path.append(dir )
#print(sys.path)
import fonctionsFichierProvisoire as fichierProvisoire
import fonctionsFichier as fichier
# this next part forces a reload in case you edit the source after you first start the blender session
import imp
imp.reload(fichierProvisoire)
imp.reload(fichier)
def createMesh(name, origin, verts, edges, faces):
# Create mesh and object
me = bpy.data.meshes.new(name+'Mesh')
ob = bpy.data.objects.new(name, me)
ob.location = origin
ob.show_name = True
# Link object to scene
bpy.context.scene.collection.objects.link(ob)
# Create mesh from given verts, edges, faces. Either edges or
# faces should be [], or you ask for problems
me.from_pydata(verts, edges, faces)
# Update mesh with new data
me.update(calc_edges=True)
return ob
def run(origin,verts,nom):
(x,y,z) = (0.707107, 0.258819, 0.965926)
ob2 = createMesh(nom.replace("\n",""), origin, verts, [] , [])
return
def decrypt(path):
file = open(path,"r")
nom = fichier.getNom(file)
date = fichier.getDate(file)
precision = fichier.getPrecision(file)
distance = float(fichier.getDistance(file))
angle = float(fichier.getAngle(file))
title,lineDetect = file.read().split("!")
ListHeight = lineDetect.split("\n")
n = 0
for line in ListHeight :
if line == ListHeight[0]:
coordPx = np.array([line.split(":")] )
b = n
n = np.size(coordPx)
else:
try:
coordPx = np.append(coordPx, [line.split(":")] , axis=0 )
b = n
n = np.size(coordPx)
except ValueError:
pass
return title,coordPx,angle,distance,nom
def vertGenerator(coord,A,E) :
verts = []
B = 63.1
Bp = 49.5
d = 640
dp = 480
for step in range(coord.shape[0]) :
for H in range(coord.shape[1]) :
if(coord[step,H]!="" and coord[step,H]!="0.0"):
X=0
Y=0
x = float(coord[step,H])
D = 180-(180-B)/2-(B*x)/d
Dp = 180-(180-Bp)/2-(Bp*H)/dp
t = (-3*E)/(1+math.tan(math.radians(D))*math.tan(math.radians(A)))
X = (t+3*E)/(math.tan(math.radians(D)))
J = (360/coord.shape[0])*step
R = (abs(X))/math.sin(math.radians(A))
C = (180-J) /2
K = 2*R * math.cos( math.radians(C) )
G = 180-C-90+A
X = X + K*math.cos(math.radians(G)) # La 2ème partie rajoute la rotation
Y = t + K*math.sin(math.radians(G))
Z = (t+3*E)/math.tan(math.radians(Dp))
verts.append( ( X*0.1 , Y*0.1, -Z*0.1))
return verts
if __name__ == "__main__":
title,coord,angle,distance,nom = decrypt(fichierProvisoire.link().lien)
verts = vertGenerator(coord,angle,distance)
run((0,0,0),verts,nom)
#print(str(ListHeight))
#print(title)
#Debug = open("C:\\Users\\user\\Desktop\\LeTpeVersionActuelVideo\\blenderrun\\Debug.txt","w")
#fichierProvisoire.link().lien
#Debug.write(np.array2string(coord, precision=2, separator=','))
#print(coord.shape)