首页 > 解决方案 > Sketchup Ruby,为面添加纹理

问题描述

我正在使用它来添加绘制一个盒子,然后为盒子着色。

l=96
w=60
h=60
clr='Gray'
ent = Sketchup.active_model.entities

#---------Clear All
Sketchup.active_model.entities.clear!       
#----------------
model = Sketchup.active_model

model.start_operation "Create Box"
#-----------------------------------------------------------------------------      

entities = model.active_entities
group = entities.add_group
entities = group.entities
group.name = "Box"
@pt0 = [0, 0, 0]
@pt1 = [0, l*12, 0]
@pt2 = [w*12.0, l*12, 0]
@pt3 = [w*12, 0, 0]

newface = entities.add_face(@pt0, @pt1, @pt2, @pt3)
newface.material = Sketchup::Color.new clr
newface.reverse!
newface.pushpull h*12

我也想添加纹理,但找不到如何做到这一点。

就像“Metal Corrugated Shiny”一样,但还没有弄清楚如何做到这一点。

有人知道如何用红宝石添加纹理吗?

在此处输入图像描述

标签: rubysketchup

解决方案


你想要的元素是Texture. 这是公开图像纹理信息(如宽度和高度、平均颜色等)的类对象。

设置纹理的最简单方法是直接在材质上。

newface.material = Sketchup::Color.new clr
newface.material.texture = "C:\\MyMaterialDirectory\\MyMaterial.jpg"

显然,该文件需要是有效的图像并位于适当的目录中。

https://ruby.sketchup.com/Sketchup/Texture.html


推荐阅读