[TexGen] Python console

发布于 2023-08-21  304 次阅读


Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------

改变纤维束颜色

# 获取窗口
rw = GetRenderWindow()
# 设置窗口背景色
rw.SetBackgroundColor(COLOR(0,0,0))
# 设置纤维束颜色,第一个参数为纤维束编号,第二个为颜色
rw.SetYarnColor(0,COLOR(0,0,0))

常用颜色:
绿色: COLOR(0, 1, 0)
红色:COLOR(1, 0, 0)
蓝色:COLOR(0, 0, 1)

减小数值可以降低相应颜色的亮度

使用脚本改变纤维束颜色

将以下代码存为.py文件,使用菜单栏Python --> Run script ...加载执行即可应用打开的织物,纤维束编号应该相应调整:

from _Embedded import *
from TexGen.Core import *
from TexGen.Renderer import *
from TexGen.Export import *
from TexGen.WeavePattern import *
from TexGen.WiseTex import *
from TexGen.FlowTex import *
import math
import runpy


rw = GetRenderWindow()
# rw = GetRenderWindow('3DWeave(W:6,H:8)')
rw.SetBackgroundColor(COLOR(1.0, 1.0, 1.0))

domain = CDomainPlanes()
domain.AddPlane(PLANE(XYZ(1, 0, 0), 2.5))
domain.AddPlane(PLANE(XYZ(-1, 0, 0), -16.75))
domain.AddPlane(PLANE(XYZ(0, 1, 0), 0))
domain.AddPlane(PLANE(XYZ(0, -1, 0), -22.7025))
domain.AddPlane(PLANE(XYZ(0, 0, 1), -0.4875))
domain.AddPlane(PLANE(XYZ(0, 0, -1), -3.6375))

weave = GetTextile('3DWeave(W:6,H:8)')
# weave.DeleteYarn(16)
weave.AssignDomain(domain)
rw.RemoveDomains()
rw.RefreshView()

for i in range(0, 16):
    if i%4 != 3:
        rw.SetYarnColor(i,COLOR(0, 0, 0.95))
    else:
        rw.SetYarnColor(i,COLOR(0, 0.95, 0))

for i in range(16, 36):
    rw.SetYarnColor(i,COLOR(0.95, 0, 0))

获取层叠后的织物信息

#  If you have several textiles open and want to retrieve a specific one then you need to specify the textile name as a parameter in the `GetTextile` command or only keep the one to be processed loaded.
# Return the textile name with following script. Note that it might be the name of the first tab if more than one is opened.
texName = GetTextile().GetName() 

# assume `texName = "LayeredTextile(Layers:2)"
weave = GetTextile(texName).GetLayeredTextile()
# which is equivalent with:
weave = GetTextile("LayeredTextile(Layers:2)").GetLayeredTextile()
# Number of layers
weave.GetNumLayers()
# Number of yarns
weave.GetNumYarns()

在GUI中,织物的名称为选项卡中显示的所有内容,即包含括号和括号之中的内容。如下图所示,该选项卡的织物名称应该是"3DWeave(W:6,H:8)"。不应该漏掉括号中的内容。

Reference

  1. 2023-08-21 Scripting Export Mesh - TexGen
届ける言葉を今は育ててる
最后更新于 2023-08-21