Skip to content

Commit ec3b5dd

Browse files
committed
S22_114 update
1 parent b6c67f1 commit ec3b5dd

File tree

6 files changed

+445
-0
lines changed

6 files changed

+445
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# UVW Tag
2+
3+
A UVWTag stores UVW coordinates for a (polygon) object.
4+
For each polygon a set of four UVW coordinates is stored.
5+
6+
UVWTag objects are an instance of c4d.Tuvw.
7+
8+
Classic API:
9+
- **c4d.UVWTag**: *A c4d.VariableTag that represents the UVW tag. Handles the UVW coordinates for textures.*
10+
11+
## Examples
12+
13+
### uvwtag_retrieve_uv_point_pinned
14+
Version: S22.114 - Win/Mac
15+
16+
Sets the polygon point selection to the uv points pinned.
17+
18+
### uvwtag_addselection_to_uv_point_pinned
19+
Version: S22.114 - Win/Mac
20+
21+
Adds the polygon point selection to the uv points pinned.
22+
23+
### uvwtag_removeselection_to_uv_point_pinned
24+
Version: S22.114 - Win/Mac
25+
26+
Removes the polygon point selection to the uv points pinned.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""
2+
Copyright: MAXON Computer GmbH
3+
Author: Maxime Adam
4+
5+
Description:
6+
- Adds the polygon point selection to the uv points pinned.
7+
8+
Class/method highlighted:
9+
- c4d.UVWTag
10+
- UVWTag.ClearPinSelection()
11+
- UVWTag.AddToPinSelection()
12+
- c4d.BaseSelect
13+
- c4d.modules.bodypaint.UpdateMeshUV()
14+
15+
Notes:
16+
UV Points are indexed by 4 * polygon + point where `c` polygon is the polygon index and `c` point is the point index between `0` and `3` (a, b, c, d).
17+
In this example UVWTag.ClearPinSelection() and UVWTag.AddToPinSelection() is used, UVWTag.SetPinSelection() can be used to do the exact same things.
18+
19+
Compatible:
20+
- Win / Mac
21+
- S22.114
22+
"""
23+
import c4d
24+
25+
26+
def CPolygonGetItem(cPoly, idx):
27+
"""
28+
Map 0-1-2-3 to the member a b c d of a c4d.CPolygon
29+
:param cPoly: c4d.CPolygon
30+
:param idx: A polygon point index
31+
"""
32+
# Checks if the cpolygon is a c4d.CPolygon
33+
if not isinstance(cPoly, c4d.CPolygon):
34+
raise TypeError("cPoly is not a c4d.CPolygon.")
35+
36+
if not 0 <= idx <= 3:
37+
raise ValueError("{0} is not between 0 and 3 included.".format(idx))
38+
39+
if idx == 0:
40+
return cPoly.a
41+
elif idx == 1:
42+
return cPoly.b
43+
elif idx == 2:
44+
return cPoly.c
45+
elif idx == 3:
46+
return cPoly.d
47+
raise RuntimeError("Unexpected Error.")
48+
49+
50+
def main():
51+
# Checks if selected object is valid
52+
if op is None:
53+
raise ValueError("op is none, please select one object.")
54+
55+
# Checks if the selected object is a PolygonObject
56+
if not isinstance(op, c4d.PolygonObject):
57+
raise TypeError("op is not a c4d.PolygonObject.")
58+
59+
# Retrieves teh first UVW tag on the current object
60+
uvwTag = op.GetTag(c4d.Tuvw)
61+
if uvwTag is None:
62+
raise RuntimeError("Failed to retrieves a uvw tag on the object.")
63+
64+
# Retrieves the current Point Selection stored in the PointObject
65+
ptSelect = op.GetPointS()
66+
if ptSelect is None:
67+
raise RuntimeError("Failed to retrieves the selected point.")
68+
69+
# Retrieves all elements, selected or not, as booleans in a list
70+
rawSelectionList = ptSelect.GetAll(op.GetPointCount())
71+
72+
# Retrieves the point ID that are selected from the rawSelectionList
73+
pointIdSelected = [i for i, value in enumerate(rawSelectionList) if value]
74+
75+
# Gets all CPolygon of the selected object
76+
polyList = op.GetAllPolygons()
77+
78+
# Creates a new pinSelection To Set
79+
pinsToSet = c4d.BaseSelect()
80+
81+
# For each CPolygon convert point selection to uv point id
82+
for polyId in range(op.GetPolygonCount()):
83+
# Get the CPolygon
84+
cPoly = polyList[polyId]
85+
86+
# Iterate over each Point of a CPolygon (4 points), a, b ,c and d
87+
for polyPtId in range(4):
88+
# Selects the uv point pinned if PointId of the CPolygon is selected
89+
ptId = CPolygonGetItem(cPoly, polyPtId)
90+
if ptId in pointIdSelected:
91+
pinsToSet.Select(polyId * 4 + polyPtId)
92+
93+
# Clears the current Pin Selection
94+
uvwTag.ClearPinSelection()
95+
96+
# Adds the built selection to the current pin selection
97+
uvwTag.AddToPinSelection(pinsToSet)
98+
99+
# Refresh the UV view
100+
c4d.modules.bodypaint.UpdateMeshUV(False)
101+
102+
# Pushes an update event to Cinema 4D
103+
c4d.EventAdd()
104+
105+
106+
if __name__ == "__main__":
107+
main()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"""
2+
Copyright: MAXON Computer GmbH
3+
Author: Maxime Adam
4+
5+
Description:
6+
- Removes the polygon point selection to the uv points pinned.
7+
8+
Class/method highlighted:
9+
- c4d.UVWTag
10+
- UVWTag.RemoveFromPinSelection()
11+
- c4d.BaseSelect
12+
- c4d.modules.bodypaint.UpdateMeshUV()
13+
14+
Notes:
15+
UV Points are indexed by 4 * polygon + point where `c` polygon is the polygon index and `c` point is the point index between `0` and `3` (a, b, c, d).
16+
17+
Compatible:
18+
- Win / Mac
19+
- S22.114
20+
"""
21+
import c4d
22+
23+
24+
def CPolygonGetItem(cPoly, idx):
25+
"""
26+
Map 0-1-2-3 to the member a b c d of a c4d.CPolygon
27+
:param cPoly: c4d.CPolygon
28+
:param idx: A polygon point index
29+
"""
30+
# Checks if the cpolygon is a c4d.CPolygon
31+
if not isinstance(cPoly, c4d.CPolygon):
32+
raise TypeError("cPoly is not a c4d.CPolygon.")
33+
34+
if not 0 <= idx <= 3:
35+
raise ValueError("{0} is not between 0 and 3 included.".format(idx))
36+
37+
if idx == 0:
38+
return cPoly.a
39+
elif idx == 1:
40+
return cPoly.b
41+
elif idx == 2:
42+
return cPoly.c
43+
elif idx == 3:
44+
return cPoly.d
45+
raise RuntimeError("Unexpected Error.")
46+
47+
48+
def main():
49+
# Checks if selected object is valid
50+
if op is None:
51+
raise ValueError("op is none, please select one object.")
52+
53+
# Checks if the selected object is a PolygonObject
54+
if not isinstance(op, c4d.PolygonObject):
55+
raise TypeError("op is not a c4d.PolygonObject.")
56+
57+
# Retrieves teh first UVW tag on the current object
58+
uvwTag = op.GetTag(c4d.Tuvw)
59+
if uvwTag is None:
60+
raise RuntimeError("Failed to retrieves a uvw tag on the object.")
61+
62+
# Retrieves the current Point Selection stored in the PointObject
63+
ptSelect = op.GetPointS()
64+
if ptSelect is None:
65+
raise RuntimeError("Failed to retrieves the selected point.")
66+
67+
# Retrieves all elements, selected or not, as booleans in a list
68+
rawSelectionList = ptSelect.GetAll(op.GetPointCount())
69+
70+
# Retrieves the point ID that are selected from the rawSelectionList
71+
pointIdSelected = [i for i, value in enumerate(rawSelectionList) if value]
72+
73+
# Gets all CPolygon of the selected object
74+
polyList = op.GetAllPolygons()
75+
76+
# Creates a new pinSelection To Set
77+
pinsToSet = c4d.BaseSelect()
78+
79+
# For each CPolygon convert point selection to uv point id
80+
for polyId in range(op.GetPolygonCount()):
81+
# Get the CPolygon
82+
cPoly = polyList[polyId]
83+
84+
# Iterate over each Point of a CPolygon (4 points), a, b ,c and d
85+
for polyPtId in range(4):
86+
# Selects the uv point pinned if PointId of the CPolygon is selected
87+
ptId = CPolygonGetItem(cPoly, polyPtId)
88+
if ptId in pointIdSelected:
89+
pinsToSet.Select(polyId * 4 + polyPtId)
90+
91+
# Adds the built selection to the current pin selection
92+
uvwTag.RemoveFromPinSelection(pinsToSet)
93+
94+
# Refresh the UV view
95+
c4d.modules.bodypaint.UpdateMeshUV(False)
96+
97+
# Pushes an update event to Cinema 4D
98+
c4d.EventAdd()
99+
100+
101+
if __name__ == "__main__":
102+
main()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
"""
2+
Copyright: MAXON Computer GmbH
3+
Author: Maxime Adam
4+
5+
Description:
6+
- Sets the polygon point selection to the uv points pinned.
7+
8+
Class/method highlighted:
9+
- c4d.UVWTag
10+
- UVWTag.GetPinSelection()
11+
- c4d.BaseSelect
12+
- c4d.modules.bodypaint.UpdateMeshUV()
13+
14+
Notes:
15+
UV Points are indexed by 4 * polygon + point where `c` polygon is the polygon index and `c` point is the point index between `0` and `3` (a, b, c, d).
16+
17+
Compatible:
18+
- Win / Mac
19+
- S22.114
20+
"""
21+
import c4d
22+
23+
24+
def CPolygonGetItem(cPoly, idx):
25+
"""
26+
Map 0-1-2-3 to the member a b c d of a c4d.CPolygon
27+
:param cPoly: c4d.CPolygon
28+
:param idx: A polygon point index
29+
"""
30+
# Checks if the cpolygon is a c4d.CPolygon
31+
if not isinstance(cPoly, c4d.CPolygon):
32+
raise TypeError("cPoly is not a c4d.CPolygon.")
33+
34+
if not 0 <= idx <= 3:
35+
raise ValueError("{0} is not between 0 and 3 included.".format(idx))
36+
37+
if idx == 0:
38+
return cPoly.a
39+
elif idx == 1:
40+
return cPoly.b
41+
elif idx == 2:
42+
return cPoly.c
43+
elif idx == 3:
44+
return cPoly.d
45+
raise RuntimeError("Unexpected Error.")
46+
47+
48+
def main():
49+
# Checks if selected object is valid
50+
if op is None:
51+
raise ValueError("op is none, please select one object.")
52+
53+
# Checks if the selected object is a PolygonObject
54+
if not isinstance(op, c4d.PolygonObject):
55+
raise TypeError("op is not a c4d.PolygonObject.")
56+
57+
# Retrieves teh first UVW tag on the current object
58+
uvwTag = op.GetTag(c4d.Tuvw)
59+
if uvwTag is None:
60+
raise RuntimeError("Failed to retrieves a uvw tag on the object.")
61+
62+
# Retrieves the Pin Selection Stored in the uvTag
63+
pinSelection = uvwTag.GetPinSelection()
64+
if pinSelection.GetCount() == 0:
65+
raise ValueError("There is no uv point pinned.")
66+
67+
# Retrieves the current Point Selection stored in the PointObject
68+
ptSelect = op.GetPointS()
69+
if ptSelect is None:
70+
raise RuntimeError("Failed to retrieves the selected point.")
71+
72+
# Deselects all points on the Polygon Object
73+
ptSelect.DeselectAll()
74+
75+
# Retrieves all elements, selected or not, as booleans in a list
76+
rawSelectionList = pinSelection.GetAll(op.GetPointCount())
77+
78+
# Retrieves the uv point pinned ID that are selected from the rawSelectionList
79+
pinnedUvPointIds = [i for i, value in enumerate(rawSelectionList) if value]
80+
81+
# For each uv point pinned Id convert Uv Point baseSelect to PointObject BaseSelect
82+
polyList = op.GetAllPolygons()
83+
for pinnedUvPointId in pinnedUvPointIds:
84+
# Retrieves the polygon ID and the Cpolygon ID
85+
polyId = pinnedUvPointId // 4
86+
cpolyPtId = pinnedUvPointId % 4
87+
88+
# Retrieve the real PtID from the Cpolygon
89+
ptId = CPolygonGetItem(polyList[polyId], cpolyPtId)
90+
91+
# Select the 3D point ptID
92+
ptSelect.Select(ptId)
93+
94+
# Refresh the UV view
95+
c4d.modules.bodypaint.UpdateMeshUV(False)
96+
97+
# Pushes an update event to Cinema 4D
98+
c4d.EventAdd()
99+
100+
101+
if __name__ == "__main__":
102+
main()

0 commit comments

Comments
 (0)