vrUVService¶
-
class
vrUVService
¶
(Inherits vrBaseService
)
Service for UV mapping related functions.
New UVs can be created for a geometry by unfolding (flattening) with vrUVService.unfold(nodes, unfoldSettings, layoutSettings, uvSet), or with a projection method, vrUVService.applyPlanarProjection(nodes, settings, uvSet), vrUVService.applyCylindricalProjection(nodes, settings, uvSet), or vrUVService.applyTriplanarProjection(nodes, settings, uvSet).
To run a function on a shell geometry, pass the shell geometry node to the function, do not include its surface nodes in the list.
Find a list of geometry nodes (shells and meshes) in the Scenegraph with a function like this:
def findGeos(root):
return vrNodeService.findNodes(lambda node: node.isType(vrdGeometryNode), vrdFindOptions(), root)
# Example usage:
geos = findGeos(vrNodeService.findNode("Body38"))
# unfold using default settings
vrUVService.unfold(geos, vrdUVUnfoldSettings(), vrdUVLayoutSettings())
Please note, for shell geometries, functions vrUVService.unfold(nodes, unfoldSettings, layoutSettings, uvSet), vrUVService.layout(nodes, settings, uvSet), vrUVService.optimize(nodes, settings, uvSet) and vrUVService.sewAllIslands(nodes, onlyBordersBetweenIslands, uvSet) respect the current A/B-side render mode, as does the UV Editor module. That means those functions process only A-side surfaces of a shell in A-side render mode (default), but no B-side surfaces. Hidden surfaces of a shell are skipped when processing the shell node.
Summary¶
- Functions:
- applyCylindricalProjection(nodes, settings, uvSet)
- applyPlanarProjection(nodes, settings, uvSet)
- applyTriplanarProjection(nodes, settings, uvSet)
- applyTriplanarProjectionAndLayout(nodes, settings, layoutSettings, uvSet)
- applyWorldScale(nodes, uvSet)
- cutAlongSeams(nodes, settings, uvSet)
- cylindricalProjectionFitSize(nodes, settings, uvSet)
- getCylindricalProjectionDefaultSettings(nodes, textureWidth, textureHeight) → vrdUVCylindricalProjectionSettings
- getPlanarProjectionDefaultSettings(nodes, textureWidth, textureHeight) → vrdUVPlanarProjectionSettings
- getProjectionMode(node, uvSet) → vrUVTypes.UVProjectionMode
- getTriplanarProjectionDefaultSettings(nodes, textureWidth, textureHeight) → vrdUVTriplanarProjectionSettings
- hasCylindricalProjectionSettings(node, uvSet) → bool
- hasPlanarProjectionSettings(node, uvSet) → bool
- hasTriplanarProjectionSettings(node, uvSet) → bool
- layout(nodes, settings, uvSet)
- optimize(nodes, settings, uvSet)
- planarProjectionFitSize(nodes, settings, uvSet)
- readCylindricalProjectionSettings(node, uvSet) → vrdUVCylindricalProjectionSettings
- readPlanarProjectionSettings(node, uvSet) → vrdUVPlanarProjectionSettings
- readTriplanarProjectionSettings(node, uvSet) → vrdUVTriplanarProjectionSettings
- rotateUV(geometryNodes, center, angleDegree, uvSet)
- saveUVSnapshot(nodes, path, width, height, uvSet, style, mode, customSpace)
- scaleUV(nodes, center, uScale, vScale, uvSet)
- sewAllIslands(nodes, onlyBordersBetweenIslands, uvSet)
- translateUV(nodes, du, dv, uvSet)
- triplanarProjectionFitSize(nodes, settings, uvSet)
- unfold(nodes, unfoldSettings, layoutSettings, uvSet)
Functions¶
-
vrUVService.
applyCylindricalProjection
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ Applies a cylindrical projection to a list of geometry nodes. Existing UVs are overwritten.
The settings are stored in the node and can be fetched again later with readCylindricalProjectionSettings.
Parameters: - nodes (List[vrdGeometryNode]) – The nodes to apply the projection.
- settings (vrdUVCylindricalProjectionSettings) – The cylindrical projection settings to use.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
applyPlanarProjection
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ Applies a planar projection to a list of geometry nodes. Existing UVs are overwritten.
The 3d world-space positions of the vertices are projected into UV space.
The settings are stored in the node and can be fetched again later with readPlanarProjectionSettings.
Parameters: - nodes (List[vrdGeometryNode]) – The nodes to apply the projection.
- settings (vrdUVPlanarProjectionSettings) – The planar projection settings to use.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
applyTriplanarProjection
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ Applies a triplanar projection to a list of geometry nodes. Existing UVs are overwritten.
The settings are stored in the node and can be fetched again later with readTriplanarProjectionSettings.
Parameters: - nodes (List[vrdGeometryNode]) – The nodes to apply the projection.
- settings (vrdUVTriplanarProjectionSettings) – The triplanar projection settings to use.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
applyTriplanarProjectionAndLayout
(nodes, settings, layoutSettings, uvSet=vrUVTypes.MaterialUVSet)¶ Applies a triplanar projection to a list of geometry nodes and packs the UV islands into UV space according to the provided layout settings. Existing UVs are overwritten.
The settings are stored in the node and can be fetched again later with readTriplanarProjectionSettings.
Parameters: - nodes (List[vrdGeometryNode]) – The nodes to apply the projection.
- settings (vrdUVTriplanarProjectionSettings) – The triplanar projection settings to use.
- layoutSettings (vrdUVLayoutSettings) – Settings used to pack the projected UV islands into UV space.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
applyWorldScale
(nodes, uvSet=vrUVTypes.MaterialUVSet)¶ Scales the UV coordinates according to the average triangle area in scene units. Use in combination with vrdTexture.setUseTextureSize(s) to get a real world scaling of your textures.
Parameters: - nodes (List[vrdGeometryNode]) – The nodes to apply the UV scaling to.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
cutAlongSeams
(nodes, settings, uvSet)¶ Does a cut with the given seam settings on the given nodes.
Example of organic cut:
geometryNodes = [vrNodeService.findNode("Box")] settings = vrdUVSeamSettings() settings.setMode(vrUVTypes.SeamMode.Organic) settings.setOrganicUsePipesCutter(True) settings.setOrganicSegmentationAmount(0) vrUVService.cutAlongSeams(geometryNodes, settings, vrUVTypes.UVSet.MaterialUVSet)
Example of manufactured cut:
geometryNodes = [vrNodeService.findNode("Box")] settings = vrdUVSeamSettings() settings.setMode(vrUVTypes.SeamMode.Manufactured) settings.setManufacturedAngle(45) settings.setManufacturedAreaRatio(0.5) vrUVService.cutAlongSeams(geometryNodes, settings, vrUVTypes.UVSet.MaterialUVSet)
Example of baking cut:
geometryNodes = [vrNodeService.findNode("Box")] settings = vrdUVSeamSettings() settings.setMode(vrUVTypes.SeamMode.Baking) settings.setBakingAngle(45) settings.setBakingSizeOfMinPatch(0) vrUVService.cutAlongSeams(geometryNodes, settings, vrUVTypes.UVSet.MaterialUVSet)
Parameters: - nodes (List[vrdGeometryNode]) – The list of nodes
- settings (vrdUVSeamSettings) – Settings to use for the seaming
- uvSet (vrUVTypes.UVSet) – The UV set to work on (MaterialUVSet for the material UVs or LightmapUVSet for the lightmap UVs).
-
vrUVService.
cylindricalProjectionFitSize
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ Applies a cylindrical projection and adjusts the projection size to the given list of nodes.
Parameters: - nodes (List[vrdGeometryNode]) – The geometry nodes
- settings (vrdUVCylindricalProjectionSettings) – The cylindrical projection settings to use.
- uvSet (vrUVTypes.UVSet) – The uv set to work on.
-
vrUVService.
getCylindricalProjectionDefaultSettings
(nodes, textureWidth, textureHeight)¶ Gets default settings for a cylindrical projection for a list of geometry nodes based on their overall bounding box and the specified texture resolution.
The texture resolution (parameter textureWidth and textureHeight) is used to setup a projection that matches the texture aspect ratio.
Parameters: - nodes (List[vrdGeometryNode]) – The geometry nodes
- textureWidth (integer) – The texture width used for aspect ratio calculation.
- textureHeight (integer) – The texture height used for aspect ratio calculation.
Returns: The cylindrical projection settings.
Return type:
-
vrUVService.
getPlanarProjectionDefaultSettings
(nodes, textureWidth, textureHeight)¶ Gets default settings for a planar projection for a given list of geometry nodes based on their overall bounding box and the specified texture resolution.
The texture resolution (parameter textureWidth and textureHeight) is used to setup a projection that matches the texture aspect ratio.
Parameters: - nodes (List[vrdGeometryNode]) – The geometry nodes
- textureWidth (integer) – The texture width used for aspect ratio calculation.
- textureHeight (integer) – The texture height used for aspect ratio calculation.
Returns: The planar projection settings.
Return type:
-
vrUVService.
getProjectionMode
(node, uvSet=vrUVTypes.MaterialUVSet)¶ Gets the kind of projection that was last applied to the node to create UV coordinates.
Parameters: - node (vrdGeometryNode) – The node to query.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
Returns: The projection mode.
Return type:
-
vrUVService.
getTriplanarProjectionDefaultSettings
(nodes, textureWidth, textureHeight)¶ Gets default settings for a triplanar projection for a list of geometry nodes based on their bounding box center and the specified texture resolution.
The texture resolution (parameter textureWidth and textureHeight) is used to setup a projection that matches the texture aspect ratio.
Parameters: - nodes (List[vrdGeometryNode]) – The geometry nodes
- textureWidth (integer) – The texture width used for aspect ratio calculation.
- textureHeight (integer) – The texture height used for aspect ratio calculation.
Returns: The triplanar projection settings.
Return type:
-
vrUVService.
hasCylindricalProjectionSettings
(node, uvSet=vrUVTypes.MaterialUVSet)¶ Determines if a node has settings for a cylindrical projection.
Parameters: - node (vrdGeometryNode) – The node to query.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
Returns: True if the node has settings for cylindrical projection, False otherwise.
Return type: bool
-
vrUVService.
hasPlanarProjectionSettings
(node, uvSet=vrUVTypes.MaterialUVSet)¶ Determines if a node has settings for a planar projection.
Parameters: - node (vrdGeometryNode) – The node to query.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
Returns: True if the node has settings for planar projection, False otherwise.
Return type: bool
-
vrUVService.
hasTriplanarProjectionSettings
(node, uvSet=vrUVTypes.MaterialUVSet)¶ Determines if a node has settings for a triplanar projection.
Parameters: - node (vrdGeometryNode) – The node to query.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
Returns: True if the node has settings for triplanar projection, False otherwise.
Return type: bool
-
vrUVService.
layout
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ For each geometry, packs its UV islands into a box in UV space. (By default, into [0,1]x[0,1].) UV islands are scaled, rotated and moved according to the provided settings so they all fit into the box without overlapping.
The packing is done separately for each geometry in the input list. This function only works on geometries that have UVs. Degenerate triangles are removed from the input geometry.
To run layout on a shell geometry, pass the shell geometry node to this function, do not include the surface nodes in the list. Layout packs all islands of the shell so they do not overlap. When passing surface nodes in the list, the UVs of each surface are layouted individually and occupy maximum UV space in the specified box.
Parameters: - nodes (List[vrdGeometryNode]) – Geometry nodes
- settings (vrdUVLayoutSettings) – Settings used to layout the islands
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
optimize
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ For each geometry, reduces distortions in the UV layout. This function only works on geometries that have UVs.
Degenerate triangles are removed from the input geometry.
Parameters: - nodes (List[vrdGeometryNode]) – Geometry nodes
- settings (vrdUVOptimizeSettings) – Settings used to optimize the UVs
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
planarProjectionFitSize
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ Applies a planar projection and adjusts the projection size to the given list of nodes.
Parameters: - nodes (List[vrdGeometryNode]) – The geometry nodes
- settings (vrdUVPlanarProjectionSettings) – The planar projection settings to use.
- uvSet (vrUVTypes.UVSet) – The uv set to work on.
-
vrUVService.
readCylindricalProjectionSettings
(node, uvSet=vrUVTypes.MaterialUVSet)¶ Reads settings that have been attached to the node when applying a cylindrical projection.
Parameters: - node (vrdGeometryNode) – The node to query.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
Returns: The cylindrical projection settings.
Return type:
-
vrUVService.
readPlanarProjectionSettings
(node, uvSet=vrUVTypes.MaterialUVSet)¶ Reads settings that have been attached to the node when applying a planar projection.
Parameters: - node (vrdGeometryNode) – The node to query.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
Returns: The planar projection settings.
Return type:
-
vrUVService.
readTriplanarProjectionSettings
(node, uvSet=vrUVTypes.MaterialUVSet)¶ Reads settings that have been attached to the node when applying a triplanar projection.
Parameters: - node (vrdGeometryNode) – The node to query.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
Returns: The triplanar projection settings.
Return type:
-
vrUVService.
rotateUV
(geometryNodes, center, angleDegree, uvSet)¶ Rotate the UVs of the given nodes around the given center.
Example of rotating all material UVs 90 degrees:
geometryNodes = [vrNodeService.findNode("Box")] center = QVector2D(0.5,0.5) angle = 90 vrUVService.rotateUV(geometryNodes, center, angle, vrUVTypes.UVSet.MaterialUVSet)
Parameters: - geometryNodes (List[vrdGeometryNode]) – The list of geometry nodes
- center (QVector2D) – Center of scaling
- angleDegree (float) – Rotation angle in degree
- uvSet (vrUVTypes.UVSet) – The UV set to work on
-
vrUVService.
saveUVSnapshot
(nodes, path, width=1024, height=1024, uvSet=vrUVTypes.MaterialUVSet, style=vrUVTypes.ShowWireframe, mode=vrUVTypes.SnapshotMode.ZeroToOneSpace, customSpace=QVector4D())¶ Saves a snapshot of the UV layout as image file.
Note: If width and height are different in ZeroToOneSpace mode, then the output image will be distorted.
Example:
geometryNodes = [vrNodeService.findNode("Box")] vrUVService.saveUVSnapshot(geometryNodes, "c:/vred-snapshots/uv.png", 512, 512, vrUVTypes.UVSet.MaterialUVSet, vrUVTypes.ShowBorders | vrUVTypes.ShowWireframe)
Parameters: - nodes (List[vrdNode]) – The list of nodes to include in the snapshot.
- path (string) – The full path where the image should be saved (e.g. ‘c:/uv.png’).
- width (integer) – The width of the image in pixels (default 1024).
- height (integer) – The height of the image in pixels (default 1024).
- uvSet (vrUVTypes.UVSet) – The UV set to capture (MaterialUVSet for the material UVs or LightmapUVSet for the lightmap UVs).
- style (integer) – Defines the style of the exported snapshot, Bitmask created from vrUVTypes.SnapshotStyle.
- mode (vrUVTypes.SnapshotMode) – The snapshot mode defines the area to be included in the image. ‘ZeroToOneSpace’ captures the area from 0 to 1 in UV coordinates. ‘Boundingbox’ will capture the entire object.
- customSpace (QVector4D) – UV space to use for shapshot (min U, max U, min V, max V). Only used if mode is set to vrUVTypes::SnapshotMode::CustomSpace.
-
vrUVService.
scaleUV
(nodes, center, uScale, vScale, uvSet)¶ Scale the UVs of the given nodes using the given center.
Example of flipping all material UVs:
geometryNodes = [vrNodeService.findNode("Box")] center = QVector2D(0.5,0.5) uScale = -1 vScale = 1 vrUVService.scaleUV(geometryNodes, center, uScale, vScale, vrUVTypes.UVSet.MaterialUVSet)
Parameters: - nodes (List[vrdGeometryNode]) – The list of nodes
- center (QVector2D) – Center of scaling
- uScale (float) – Scale factor for u value
- vScale (float) – Scale factor for v value
- uvSet (vrUVTypes.UVSet) – The UV set to work on
-
vrUVService.
sewAllIslands
(nodes, onlyBordersBetweenIslands, uvSet=vrUVTypes.MaterialUVSet)¶ For each geometry, sews all islands that are adjacent in 3D.
Parameters: - nodes (List[vrdGeometryNode]) – Geometry nodes for which all islands will be sewed. The sewing will be done per node.
- onlyBordersBetweenIslands (bool) – Set to True to only sew neighboring islands, but no internal cuts within an island. Set to False to additionally sew internal cuts within an island if there are any.
- uvSet (vrUVTypes.UVSet) – The uv set to work on
-
vrUVService.
translateUV
(nodes, du, dv, uvSet)¶ Translates the UVs of the given nodes.
Example of translating all material UVs:
geometryNodes = [vrNodeService.findNode("Box")] du = 0.2 dv = 0.2 vrUVService.translateUV(geometryNodes, du, dv, vrUVTypes.UVSet.MaterialUVSet)
Parameters: - nodes (List[vrdGeometryNode]) – The list of nodes
- du (float) – Translation along u
- dv (float) – Translation along v
- uvSet (vrUVTypes.UVSet) – The UV set to work on
-
vrUVService.
triplanarProjectionFitSize
(nodes, settings, uvSet=vrUVTypes.MaterialUVSet)¶ Applies a triplanar projection and adjusts the projection size to the given list of nodes.
Parameters: - nodes (List[vrdGeometryNode]) – The geometry nodes
- settings (vrdUVTriplanarProjectionSettings) – The triplanar projection settings to use.
- uvSet (vrUVTypes.UVSet) – The uv set to work on.
-
vrUVService.
unfold
(nodes, unfoldSettings, layoutSettings, uvSet=vrUVTypes.MaterialUVSet)¶ Compute unfolded UV coordinates for the given geometry nodes.
For each geometry, its coordinates are unfolded and packed into UV space according to the provided layout settings. Unfolding is done with Unfold3D. Any existing UV coordinates are overwritten. The input geometry does not need to have UVs. UVs are created from scratch based on the 3D data of the geometry. Degenerate triangles are removed from the input geometry.
To run unfold on a shell geometry, pass the shell geometry node to this function, do not include the surface nodes in the list. When passing surface nodes to unfold, the surfaces are unfolded individually.
Parameters: - nodes (List[vrdGeometryNode]) – Geometry nodes
- unfoldSettings (vrdUVUnfoldSettings) – Settings used to unfold the UVs
- layoutSettings (vrdUVLayoutSettings) – Settings used to pack the unfolded UV islands into UV space.
- uvSet (vrUVTypes.UVSet) – The uv set to work on