The routine would be pretty much the same as in this example:
-
You start with 4 corner vertices which are connected through the border edges
-
You have to calculate the overall length of each border edge. This is the sum of the lengths of all edges between two corner vertices.
-
Each vertice on the border edges has eighter a U or a V coordinate which is proportional to the vertice’s position relative to the overall edge length.
-
All other vertices get their uv coordinates from the distance to the next 2 vertices on the border edges. Distance is the actual length of all edges between the points (in 3d space).
This is how I would write the script. Unfortunately I don’t have much time to figure out how it can be done in MaxScript…
3 first ones are exactly what already makes my script.
The fourth point is different…
To my opinion, the results will be wrong with this method except with very regular forms.
To compare the position of the other vertices with edges will create errors in uv. There are cases where the most close 2 points are not the right choice…
Yes, your right. This would only work on regular geometry…
How does your script calculates the uv coordinates of the interior vertices? How does the texture of the last object look like after mapped with you script?
I create a grid. You can show this grid and you will understand my method : replace the option ‘show corners (marker)’ by ‘show grid (shape)’ under group ‘morphMap’
The grid will appear and is used to calculate the uvs. (Except vertices on the border edges)
Seems that your method only recognizes the the alignment of the border edges. For example, if I modify your object by moving the border vertices, it creates a grid that perfectly fits the border edges. But when I move only the interior vertices, the grid will still have the same shape.
Maybe the solution would be to create a grid for each polygon like you do for the borders. Try to go recursively through all edges in the selection and change the grid so it would follow the shape of the object.
I found another method to map complex geometry here: http://www.nesnausk.org/inoutside/Technology.php#tech_tex
They say that they “project tileable stone textures onto the model’s surface from several angles; and weight the results according to the orientation of the surface (surface’s normal).”
I guess that this method would give the same result as aligning your grid to each polygon.
What do you think?
Indeed, only edges are used to generate the grid. For points going away from the grid, the script makes a projection. It is very similar to a planar mapping but the shape does not need to be rectangular.
You give several interesting propositions.
To begin let us speak about the first idea:
When I have created morphMap, I thought at first of realizing the mapping ‘by propagation’, like this:
1- at first apply a face mapping
2- unify the directions
3- recalculate the uvs by using the edges length
But this algorithm is very dependent on the regularity of the mesh. The weakness is situated at the point 2. There are cases where to unify the direction is not possible.
For example this one:
And calculate the uvs of an irregular poly isn’t obvious.
Maybe there are a solution there but I do not see at the moment.
Nevertheless to use the size of edges seems interesting…
I think we are on the right way to solve our problem
But I still have serious problems to imagine the process to flatten the surface.
I created a pyramid with: width = height = depth = 100.0m, then cut off the upper part and extruded the cap polygon 20m inside the object. This object is pretty much the same as in your example, but it has 2 edges which are orthografically aligned to the orientation of the mapping plane. The egdes B and B’ in the picture would have a length of 0 when projected into uv space.
So my approach would be to calculate the uv coordinates from the distance between each vertice relative to the distance to the corresponding edge points. I demonstrate it using the profile at the center of the object (the red edges in the picture). The edges have the following lengths:
A = A’ = 56m
B = B’ = 20m
C = 50m
The overall distance is 56 + 56 + 20 + 20 + 50 = 202m. Corresponding to this length each line section would have the following lengths in uv space:
A = 27.7% = 0.277
B = 9.9% = 0.099
C = 24.7% = 0.247
This is only works in 2d space, thats why I used only the profile at the center of the object. I cannot imagine how it could work in 3d space, that means for all the other edges of the object. Maybe you have to construct a profile in u and in v direction for each vertice, then calculating the overall length of the profiles then the u and v coordinate of the vertice. But I still don’t have an answer how the orientientation of the profiles could be calculated. I guess this involves some serious vector and algebra equations…
The method by propagation of faces is not possible. I thought about it and when the geometry is not regular there are too many problems. For example if faces are hexagonal.
There is another solution : I have to project my grid on the object.
As any projection I need an axis. I think that we can find this axis with the normal of the outline. Of course it is an approximation but that should work in quite a lot of case. Later I revalue the grid according to the distances.
It will not work with the perpendicular surfaces in the axis of projection…
Other solution is to cut the object with this axis as you propose it. But that is probably time consuming.
I found another solution: I project vertices on the grid and I store their height.
With this algorithm that will function for vertical surfaces, without needing to cut out the object. I will give more explanations in one or two days.
Hi
Here is the method
- a first grid is created with the outline vertices. (It’s the current morphMap grid.)
- the vertices of the object are projected on this grid. The axis of projection is the normal vector of the outline.
- for each impact point there are a coordinate. The elevation is the distance between the point and the impact point.
- by using an interpolation, the UV of the new points are calculated : a division is added to the outline at this position.
- a second grid is created with new divisions and by using the elevations.
- the right UV is calculated with the new grid. (by using the length of the segments of the grid)
The method accept vertical surfaces because several points are created at the same place but with an other elevation.
Unfortunately, I see now that there are a problem: if the axis is bad, a points can be projected outside the grid… How to calculate the division in this case?
It is pity because the method could calculate a lot of volumes.
Maybe that inpire an idea to somebody ?
- a second grid is created with new divisions and by using the elevations.
- the right UV is calculated with the new grid. (by using the length of the segments of the grid)
Are you using Max’s “relax uv’s” function to do this? Or your own similar function?
Unfortunately, I see now that there are a problem: if the axis is bad, a points can be projected outside the grid… How to calculate the division in this case?
No need to actually make a grid the first time around. Just consider the equation for an infinite plane that is defined by the average normal of the selected vertices
Nothing so complex. I create the first grid as a morphing from an edge to the other one.
Here is the reason of the script name: morphMap (morphing mapping)
It is just an interpolation of vertices position. For example if i have to create an element at position U=0.2, the points of left edge are mixed by the right edge : 0.8 for the left edge and 0.2 for the right edge.
This interpolation is a bit modified (move, scale, rotation) to follow the 2 other edges (they are a kind of guide).
I obtain the grid.
For the second grid it is the same but I will add a deplacement: the elevation.
Unfortunally the first grid exist to evaluate the position in the UV space and it’s not always planar.
And I don’t work with an regular space. Nothing can be outside 0-1.
But There is certainly a solution.
That becomes every day clearer.
Today i realize that I do not need a projection…