New example models procedural decals - #6083
Open
PanicTitan wants to merge 2 commits into
Open
Conversation
A decal example that works on the web
| // following the same clip-space projection idea used by engines' decal systems (and by | ||
| // three.js' DecalGeometry, which the technique is commonly traced back to). What's left | ||
| // after clipping becomes the decal's own small mesh, UV-mapped from its local coordinates | ||
| static Mesh GenMeshDecal(Model model, Matrix projection, float decalSize, float decalOffset) |
Comment on lines
+406
to
+474
| switch (total) | ||
| { | ||
| case 0: | ||
| // Whole triangle is inside this face, keep it as-is | ||
| AddTriangleToMeshBuilder(outMesh, inMesh->vertices[i], inMesh->vertices[i + 1], inMesh->vertices[i + 2]); | ||
| break; | ||
| case 1: | ||
| // One corner is outside; clip it off, turning the triangle into a quad | ||
| if (v1Out) | ||
| { | ||
| nV1 = inMesh->vertices[i + 1]; | ||
| nV2 = inMesh->vertices[i + 2]; | ||
| nV3 = ClipSegment(inMesh->vertices[i], nV1, planes[face], s); | ||
| nV4 = ClipSegment(inMesh->vertices[i], nV2, planes[face], s); | ||
| } | ||
|
|
||
| if (v2Out) | ||
| { | ||
| nV1 = inMesh->vertices[i]; | ||
| nV2 = inMesh->vertices[i + 2]; | ||
| nV3 = ClipSegment(inMesh->vertices[i + 1], nV1, planes[face], s); | ||
| nV4 = ClipSegment(inMesh->vertices[i + 1], nV2, planes[face], s); | ||
|
|
||
| AddTriangleToMeshBuilder(outMesh, nV3, nV2, nV1); | ||
| AddTriangleToMeshBuilder(outMesh, nV2, nV3, nV4); | ||
| break; | ||
| } | ||
|
|
||
| if (v3Out) | ||
| { | ||
| nV1 = inMesh->vertices[i]; | ||
| nV2 = inMesh->vertices[i + 1]; | ||
| nV3 = ClipSegment(inMesh->vertices[i + 2], nV1, planes[face], s); | ||
| nV4 = ClipSegment(inMesh->vertices[i + 2], nV2, planes[face], s); | ||
| } | ||
|
|
||
| AddTriangleToMeshBuilder(outMesh, nV1, nV2, nV3); | ||
| AddTriangleToMeshBuilder(outMesh, nV4, nV3, nV2); | ||
| break; | ||
| case 2: | ||
| // Two corners are outside; only the small corner near the surviving vertex remains | ||
| if (!v1Out) | ||
| { | ||
| nV1 = inMesh->vertices[i]; | ||
| nV2 = ClipSegment(nV1, inMesh->vertices[i + 1], planes[face], s); | ||
| nV3 = ClipSegment(nV1, inMesh->vertices[i + 2], planes[face], s); | ||
| AddTriangleToMeshBuilder(outMesh, nV1, nV2, nV3); | ||
| } | ||
|
|
||
| if (!v2Out) | ||
| { | ||
| nV1 = inMesh->vertices[i + 1]; | ||
| nV2 = ClipSegment(nV1, inMesh->vertices[i + 2], planes[face], s); | ||
| nV3 = ClipSegment(nV1, inMesh->vertices[i], planes[face], s); | ||
| AddTriangleToMeshBuilder(outMesh, nV1, nV2, nV3); | ||
| } | ||
|
|
||
| if (!v3Out) | ||
| { | ||
| nV1 = inMesh->vertices[i + 2]; | ||
| nV2 = ClipSegment(nV1, inMesh->vertices[i], planes[face], s); | ||
| nV3 = ClipSegment(nV1, inMesh->vertices[i + 1], planes[face], s); | ||
| AddTriangleToMeshBuilder(outMesh, nV1, nV2, nV3); | ||
| } | ||
| break; | ||
| default: | ||
| // All 3 corners are outside this face, the triangle is fully clipped away | ||
| break; | ||
| } |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Example of decals that works on the web