PixarAnimationStudios / OpenSubdiv

An Open-Source subdivision surface library.
graphics.pixar.com/opensubdiv
Other
2.87k stars 558 forks source link

How to attach parametric UVs to uniformly subdivided mesh? #793

Closed dylanlacewell closed 8 years ago

dylanlacewell commented 8 years ago

Following far_tutorial_0, I subdivided a mesh N times uniformly. Now I'd like to attach the parametric (Ptex) linear UV values at the subdivided vertices, taking into account the triangle subfaces. I'm looking for something easy like the Far::PtexIndices utility class.

Thanks!

davidgyu commented 8 years ago

Hi Dylan,

The simplest way to do this is to use Far::PatchTable which will compute Far::PatchParam metadata for each refined face. Among other things, you can use Far::PatchParam to recover the coarse face parameterization for a refined face and its (Ptex) face index.

I've attached a modified version of far_tutorial_0 which does this.

-David

far_tutorial_0_withUV.zip

dylanlacewell commented 8 years ago

Thanks David, that works well.

On a side note, I noticed that you had to subtract nCoarseVerts here:

Far::ConstIndexArray faceVerts = patchTable->GetPatchVertices(array, patch);
printf("f");
for (int v=0; v<faceVerts.size(); ++v) {
   printf(" %d/%d", faceVerts[v]+1-nCoarseVerts, uvIndex+v);
}

Why do those indices include the offset for the coarse level? Wouldn't have expected that.

barfowl commented 8 years ago

I'll leave others to provide the history behind this indexing scheme, but in the meantime it has been noted as inconsistent and confusing (see #737) and there are plans to deal with it.

dylanlacewell commented 8 years ago

Ok, thanks Barry. Resolving this since David's solution is working fine for me. Much appreciated.

dylanlacewell commented 8 years ago

Hey David and Barry, I'm going to try to extend the method you showed me here to adaptive refinement, building off of another example of yours I found for Far: https://github.com/davidgyu/OpenSubdiv/commit/679250d1617e48c23d8ee5d05fdfd6e52a0a94b5

I need only limit position, ptex uv, and limit normal at each vertex. If there are major gotchas with this, please let me know. I'll see if the same translation method from local uv to ptex uv can be applied.

Btw, I noticed that adaptive patches have 20 vertices, vs. 4 for uniform patches. I assume uniform patches are bilinear and adaptive are bicubic (16) + 4 vertices from somewhere else?

We can take this up in the forums if that's preferable. I'm waiting on an account.

davidgyu commented 8 years ago

Hi Dylan,

Yes, the same method should work for adaptive. I updated the example a bit: https://github.com/davidgyu/OpenSubdiv/tree/cpuAdaptiveTess/tutorials/osd/tutorial_1

With OpenSubdiv 3.x an adaptive refinement can produce three kinds of patches for vertex data: Regular BSpline (16 vertices), Gregory Basis (20 vertices), Legacy Gregory (4 vertices plus adjacency and quad offset tables).

The simplest thing to do is to specify BSpline basis end cap approximation (as is done in osd_tutorial_1, then all of the resulting patches will be 16 vertex regular BSpline basis patches.

-David

On Mar 7, 2016, at 9:59 AM, Dylan Lacewell notifications@github.com wrote:

Hey David and Barry, I'm going to try to extend the method you showed me here to adaptive refinement, building off of another example of yours I found for Far: davidgyu@679250d

I need only limit position, ptex uv, and limit normal at each vertex. If there are major gotchas with this, please let me know. I'll see if the same translation method from local uv to ptex uv can be applied.

Btw, I noticed that adaptive patches have 20 vertices, vs. 4 for uniform patches. I assume uniform patches are bilinear and adaptive are bicubic (16) + 4 vertices from somewhere else?

We can take this up in the forums if that's preferable. I'm waiting on an account.

— Reply to this email directly or view it on GitHub.

dylanlacewell commented 8 years ago

Let me try and resurrect this thread. I'm still seeing seams in the normals between patches in your cpuAdaptiveTess branch, David. Any ideas what those are? They show up even on the default mesh, although when I load the resulting OBJ into Maya it seems to average out the normals. Meshlab shows the seam pretty clearly.

See latest comments I left for you here: https://github.com/davidgyu/OpenSubdiv/commit/bc4b7f036606b54622b46a6d5b427d8525ae24ca

Any insights on this would be appreciated. I can continue using uniform subdivision if nobody has time to check it.

dylanlacewell commented 8 years ago

Nevermind. The seams are a Meshlab bug, not your code. I'll try to get the adaptive tessellation pipeline going in our demo, although I may need to put a vertex merge step in there.

davidgyu commented 8 years ago

Ah, thanks for the update! I haven't had a chance to look at the Meshlab side of this. One missing piece of the adaptive tess tutorial is that while it is watertight within a patch it is not watertight between patches. That would explain some part of the behavior you have described. A vertex merge step should fix that. We are hoping to update the tutorial to demonstrate fully watertight tessellation.