Texture Mapping with Meshes

Texture Mapping with Meshes

wangstuff8
Explorer Explorer
724 Views
1 Reply
Message 1 of 2

Texture Mapping with Meshes

wangstuff8
Explorer
Explorer

I'm looking to apply a variable texture to a body based on the angle of the body's surface normal to a chosen plane. The best way I have found is by converting the body to a mesh, checking the normal of each triangle, and splitting into smaller meshes which each get a texture. I have gotten this to work up to changing the texture mapping for each mesh - the textures have to be projected from a plane. Here, it seems that the projection type changes successfully but the transform is ignored (I have checked that its value changes), resulting in no texture mapping being applied. The second photo shows the texture mapping window after running the script. This code works for solid bodies but not meshes.

As a sidenote, I found that the TriangleMeshCalculator.maxNormalDeviation property is treated as an angle in degrees, although it is specified to be in radians.

 

 

mat = ad.Matrix3D.create()
mat.setWithCoordinateSystem(plane.origin, plane.normal, plane.uDirection, plane.vDirection)
for i in range(2*n + 1):
    control:ad.ProjectedTextureMapControl = meshes[i].textureMapControl
    control.transform = mat
    control.projectedTextureMapType = ad.ProjectedTextureMapTypes.PlanarTextureMapProjection

 

 

wangstuff8_0-1721315901366.png

wangstuff8_0-1721318910091.png

 

0 Likes
725 Views
1 Reply
Reply (1)
Message 2 of 2

wangstuff8
Explorer
Explorer

After further testing, I've found that if a mesh already has a planar texture projection applied, changing the ProjectedTextureMapControl.transform variable successfully reorients the texture. Furthermore, changing the texture mapping type to Box functions as expected, while changing to any type other than Box does not (changing to Automatic throws an error, while changing to Planar, Spherical, or Cylindrical silently rejects the change as detailed in the first post). Interestingly, Planar, Spherical, and Cylindrical are the texture mappings which contain a "Axis" field in the texture mapping UI. This indicates that the conversion between the transformation matrix and the z-axis, although explicitly detailed in the documentation, is flawed.

Repeating this testing on a normal BRepBody gives the expected result in all cases.