-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBL_EdgesGen.py
More file actions
93 lines (78 loc) · 3.42 KB
/
BL_EdgesGen.py
File metadata and controls
93 lines (78 loc) · 3.42 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
import bpy
import random
from . BL_Tool import *
from bpy.types import Operator,PropertyGroup
from bpy.props import FloatProperty, PointerProperty,StringProperty
#import numpy as np
#from random import random, randint 这代码也是看起来人模狗样的啊
#scene = bpy.context.scene
class EdgesGen:
def __init__(self,name,BaseMin,BaseMax,vNumber,location):#,xu,yu,zu,xv,yv,zv
if name is None:
name = "EdgesGen"
self.name = name
#调参数区
self.BaseMin = BaseMin#-5
self.BaseMax = BaseMax#5
self.vNumber = vNumber#10
self.ENumber = self.vNumber - 1
self.location = location
self.verts = []
self.edges = []
self.faces = []
def add_EdgeMesh(self):#默认位置location=(0,0,0)
verts = self.random_verts() #Define vertices and faces
edges = self.random_edges()
faces = [] #faces = [(0,1,2,3)]
col_name="0AutoMech"#1设置集合名字
MyMesh = bpy.data.meshes.new(self.name)#Name in edit mesh
MyObject = bpy.data.objects.new(self.name, MyMesh)#name in object
cube_collection = find_collection(bpy.context, MyObject)#2通过函数find_collection制作合集
new_collection = make_collection(col_name,cube_collection)#3NEW col 将合集交给1GenLine
col = bpy.data.collections.get(col_name)#4
col.objects.link(MyObject)
bpy.context.view_layer.objects.active = MyObject
MyObject.select_set(True)#选择生成的所有物体
MyMesh.from_pydata(verts, edges, faces)#Create mesh
MyObject.location = self.location#Set location and scene of object
MyMesh.update(calc_edges=True)#
def random_verts(self):#把上面的变量传进来
rand_verts = []
amProperty = bpy.context.scene.amProperties
sampleProperty = bpy.context.scene.AMOldPropertyGroup
#if amProperty.GenLineEnum == 'GenLineOnly':
if sampleProperty.edgeXYZ == True:
xu=random.uniform(sampleProperty.xuMin,0)
yu=random.uniform(sampleProperty.yuMin,0)
zu=random.uniform(sampleProperty.zuMin,0)
xv=random.uniform(0, sampleProperty.xvMax)
yv=random.uniform(0, sampleProperty.yvMax)
zv=random.uniform(0, sampleProperty.zvMax)
else:
xu=random.uniform(self.BaseMin,0)#暂不传值
yu=random.uniform(self.BaseMin,0)
zu=random.uniform(self.BaseMin,0)
xv=random.uniform(0, self.BaseMax)
yv=random.uniform(0, self.BaseMax)
zv=random.uniform(0, self.BaseMax)
x_u,y_u,z_u = self.BaseMin+xu,self.BaseMin+yu,self.BaseMin+zu
x_v,y_v,z_v = self.BaseMax+xv,self.BaseMax+yv,self.BaseMax+zv
for v in range(self.vNumber):
#random.uniform(1,5.0) random.randint(self.BaseMin, self.BaseMax) random.random()
x = random.uniform(x_u,x_v)
y = random.uniform(y_u,y_v)
z = random.uniform(z_u,z_v)
rand_verts.append((x,y,z))
#print("rand_verts: ")
#print(rand_verts)
self.verts = rand_verts #old_verts = random.shuffle(old_verts)
return self.verts
def random_edges(self):
rand_edges = []
for e in range(self.ENumber):
u = e
v = u + 1
rand_edges.append((u,v))
#print(rand_edges)
self.edges = rand_edges
return self.edges