Giter Site home page Giter Site logo

Comments (8)

DavidArayan avatar DavidArayan commented on July 3, 2024

This is a great idea. Having the ability to select a region from the same material would also provide significant performance increases when rendering, especially on mobiles.

I believe that maintaining the sub-mesh method still has benefits for cases when you'd like to add a completely different shader/effect on the cross section.

Adding this feature is not too difficult. The difficulty would come in for users who wish to use the tool at runtime without any pre-setups etc.. I'd like to provide a clean interface for calculating the UV offsets from the original material.

As an additional to this idea, I'd like to add automatic batching between multiple slices. So instead of spamming the Mesh with multiple sub-meshes, the slicer can re-use sub-meshes and batch multiple cuts if it detects that the materials used in consecutive cuts is the same. This could be added right now without any changes to the main interfaces.

So in summary, these are the things I'd like to add. Let me know if you agree.

  1. Ability to select a sub-region of the main material for the cross section to avoid creating a submesh
  2. Smart internal batching, to reuse sub-meshes between consecutive slices which would avoid creating additional sub-meshes if the materials used do not get changed.

from ezy-slice.

PotatoBo avatar PotatoBo commented on July 3, 2024

That's pretty much exactly was I was thinking. It would be great for performance.

from ezy-slice.

DavidArayan avatar DavidArayan commented on July 3, 2024

Greetings,

I've added a separate issue under "enhancements" for point No.2 for smarter internal batching. It's likely that I'll work on that first before adding the UV offset method for single Materials.

The new issue can be found sub-mesh enhancement

from ezy-slice.

PotatoBo avatar PotatoBo commented on July 3, 2024

Hi, I recently made modifications so that only a single submesh is generated on cuts (so I can have one material for the whole mesh), and the UV's on the cut face sample from the bottom left quadrant of the texture (so that the cutface can have its "own" texture from the same material). It works for the most part, but sometimes the texturing is overly-tiled on certain cuts (which ends up looking bad with an atlas texture). I was wondering if you could point me in the right direction as to properly set the UV's so it samples from the bottom left quadrant, since (apparently) I don't fully understand what I'm doing. I figured dividing the UVs by 2 would shrink the samplespace from the entire 0-1 range into the 0-0.5 bottom left quadrant, but there appears to be a problem with that sometimes as the texture gets tiled more than it should on certain cuts (I haven't figured out the case where this happens). Here's what I have now for the UV's (modified Monotone() function):

`// generate both the vertices and uv's in this loop
for (int i = 0; i < triCount; i += 3)
{
// the Vertices in our triangle
Mapped2D posA = hulls[0];
Mapped2D posB = hulls[indexCount];
Mapped2D posC = hulls[indexCount + 1];

            // generate UV Maps
            Vector2 uvA = posA.mappedValue;
            Vector2 uvB = posB.mappedValue;
            Vector2 uvC = posC.mappedValue;

            float off = 0.0f;
            uvA.x = (uvA.x/2 / maxDiv + off) * 0.5f;
            uvA.y = (uvA.y/2 / maxDiv + off) * 0.5f ;

            uvB.x = (uvB.x/2 / maxDiv + off) * 0.5f;
            uvB.y = (uvB.y/2 / maxDiv + off) * 0.5f;

            uvC.x = (uvC.x/2 / maxDiv + off) * 0.5f;
            uvC.y = (uvC.y/2 / maxDiv + off) * 0.5f;

            Triangle newTriangle = new Triangle(posA.originalValue, posB.originalValue, posC.originalValue);

            newTriangle.SetUV(uvA, uvB, uvC);

            // the normals is the same for all vertices since the final mesh is completly flat
            newTriangle.SetNormal(normal, normal, normal);
            newTriangle.ComputeTangents();

            tri.Add(newTriangle);

            indexCount++;
        }`

from ezy-slice.

DavidArayan avatar DavidArayan commented on July 3, 2024

Greetings,

Apologies for the delayed response. I've got an experimental code which will allow you to specify via a new TextureRegion object to compute/use custom UV coordinates for the cross section. The Texture Region will essentially be a box with an x,y starting coordinate and width/height for the size, so it should be quite straightforward to use. I'm just fixing some bugs and doing some final tests before I perform a push. Should be a few more days before I push that through.

Thanks for the patience!

from ezy-slice.

PotatoBo avatar PotatoBo commented on July 3, 2024

Cool! By the way, I have figured out and fixed the problem that I posted in the previous comment. It turned out to be a bug in the UV code for the cut-faces. When computing maxDivX and maxDivY, you were looping and taking the max of the current value (which was initialized at 0) and the vertex position, when it should be the abs() value of the vertex position. The failure case was when the mesh had vertices only in negative coordinates (which happens after slicing it a lot), so the max was not computed properly.

It should be:

maxDivX = Mathf.Max(maxDivX, Mathf.Abs(mapVal.x));
maxDivY = Mathf.Max(maxDivY, Mathf.Abs(mapVal.y));

from ezy-slice.

DavidArayan avatar DavidArayan commented on July 3, 2024

Excellent fix, thank you!

I'll include it in the next push.

from ezy-slice.

DavidArayan avatar DavidArayan commented on July 3, 2024

Greetings,

I've added the above fix in the recent commit fbb271f. There is also a new API via TextureRegion (samples provided in the README) which allows single material usage and the ability to generate UV coordinates for a selected part of the texture. Let me know if any problems persist with the new API. I will close this issue for now.

from ezy-slice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.