-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into surface_model_plus_plate
- Loading branch information
Showing
19 changed files
with
170 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/compas_timber/ghpython/components/CT_Bake_PlateBoxMap/code.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# flake8: noqa | ||
import math | ||
import random | ||
|
||
import rhinoscriptsyntax as rs | ||
from compas_rhino.conversions import frame_to_rhino | ||
from ghpythonlib.componentbase import executingcomponent as component | ||
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Error | ||
from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning | ||
from Rhino import Render | ||
from Rhino.Geometry import Interval | ||
from Rhino.Geometry import Plane | ||
from Rhino.RhinoDoc import ActiveDoc | ||
|
||
|
||
class BakePlateMap(component): | ||
def RunScript(self, model, map_size, swap_uv, bake): | ||
if map_size and len(map_size) != 3: | ||
self.AddRuntimeMessage( | ||
Error, "Input parameter MapSize requires exactly three float values (scale factors in x,y,z directions)" | ||
) | ||
return | ||
|
||
if map_size: | ||
dimx, dimy, dimz = map_size | ||
else: | ||
# for the pine 251 material bitmap, rotated | ||
dimx = 1.0 | ||
dimy = 1.0 | ||
dimz = 1.0 | ||
|
||
if not model: | ||
self.AddRuntimeMessage(Warning, "Input parameters Model failed to collect any Beam objects.") | ||
return | ||
|
||
if not bake: | ||
return | ||
|
||
try: | ||
frames = [frame_to_rhino(b.frame) for b in model.plates] | ||
breps = [beam.geometry.native_brep for beam in model.plates] | ||
|
||
if frames and breps: | ||
rs.EnableRedraw(False) | ||
|
||
for brep, frame in zip(breps, frames): | ||
guid = ActiveDoc.Objects.Add(brep) | ||
boxmap = self.create_box_map(frame, dimx, dimy, dimz, swap_uv) | ||
ActiveDoc.Objects.ModifyTextureMapping(guid, 1, boxmap) | ||
finally: | ||
rs.EnableRedraw(True) | ||
|
||
@staticmethod | ||
def create_box_map(pln, sx, sy, sz, swap_uv): | ||
""" | ||
pln: frame of beam box, where x=main axis, y=width, z=height | ||
sx,sy,sz: box map size in x,y,z direction | ||
""" | ||
|
||
v = pln.YAxis | ||
w = pln.ZAxis | ||
pt = pln.Origin | ||
|
||
# random deviation | ||
a = math.pi * 0.5 | ||
randangle = (random.random() - 0.5) * a | ||
v.Rotate(randangle, pln.XAxis) | ||
|
||
b = math.pi * 0.01 | ||
randangle = (random.random() - 0.5) * b | ||
w.Rotate(randangle, pln.XAxis) | ||
|
||
randpos = sx * random.random() | ||
pt += pln.XAxis * randpos | ||
|
||
# create box mapping | ||
mappingPln = Plane(pt, w, v) | ||
dx = Interval(-sx * 0.5, sx * 0.5) | ||
dy = Interval(-sy * 0.5, sy * 0.5) | ||
dz = Interval(-sz * 0.5, sz * 0.5) | ||
if swap_uv: | ||
mappingPln.Rotate(math.radians(90), mappingPln.XAxis) | ||
BoxMap = Render.TextureMapping.CreateBoxMapping(mappingPln, dx, dy, dz, False) | ||
|
||
return BoxMap |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions
39
src/compas_timber/ghpython/components/CT_Bake_PlateBoxMap/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "BakePlatesWithBoxMap", | ||
"nickname": "BakeWPlatesithBoxMap", | ||
"category": "COMPAS Timber", | ||
"subcategory": "Utils", | ||
"description": "Bakes Plate objects with a BoxMapping (by default the material is applied 'by layer' and has to be defined in the layer the objects are baked to).", | ||
"exposure": 4, | ||
"ghpython": { | ||
"isAdvancedMode": true, | ||
"iconDisplay": 0, | ||
"inputParameters": [ | ||
{ | ||
"name": "Model", | ||
"description": "Model object (optional).", | ||
"typeHintID": "none", | ||
"scriptParamAccess": 0 | ||
}, | ||
{ | ||
"name": "MapSize", | ||
"description": "Scaling of the BoxMap in x,y,z directions (list of three positive values) (optional).", | ||
"typeHintID": "float", | ||
"scriptParamAccess": 1 | ||
}, | ||
{ | ||
"name": "SwapUV", | ||
"description": "Rotates the BoxMap 90 degrees (optional).", | ||
"typeHintID": "bool", | ||
"scriptParamAccess": 0 | ||
}, | ||
{ | ||
"name": "Bake", | ||
"description": "Set to True to Bake. Nothing happens if None or False.", | ||
"typeHintID": "bool", | ||
"scriptParamAccess": 0 | ||
} | ||
], | ||
"outputParameters": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
4 changes: 2 additions & 2 deletions
4
...T_ShowSurfaceModelBeamTypes/metadata.json → ...ents/CT_ShowBeamsByCategory/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters