Stalkerx777 Posted August 21, 2012 Share Posted August 21, 2012 (edited) Hi. I have a little experiense in pre H12 geometry library, but i completely lost in new GA library. I'm trying to iterate over all vertices of each primitive.... here' is how my code looks like, it compiles fine, but crash, right on display flag set: . . . GA_ROAttributeRef uv_ref = gdp->findVertexAttribute("uv"); GA_ROHandleV3 uv_h(uv_ref.getAttribute()); if (! uv_h.isInvalid()) return error(); const GA_Primitive *prim; const GA_PrimitiveList &primList = gdp->getPrimitiveList(); GA_Range vtx_range; for (GA_Iterator pr_it(gdp->getPrimitiveRange()); !pr_it.atEnd(); ++pr_it) { GA_Offset prim_offset = pr_it.getOffset(); prim = primList.get(prim_offset); vtx_range = prim->getVertexRange(); for (GA_Iterator vtx_it(vtx_range.begin()); !vtx_it.atEnd(); ++vtx_it) { GA_Offset vtx_offset = vtx_it.getOffset() UT_Vector3 uv(uv_h.get(vtx_offset)); // Do something with uv....... } } . . . If i remove UT_Vector3 uv(uv_h.get(vtx_offset)), houdini doesn't crash anymore. Can you please tell me where i'm wrong. And is this a right approach for iterating over vertices? Strictly speaking, i need only one vertex from each primitive, how can i get it? Thx! Edited August 22, 2012 by Stalkerx777 Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 21, 2012 Share Posted August 21, 2012 (edited) I don't like this line. It doesn't have much sense to me. if (! uv_h.isInvalid()) return error(); Change it to: if (uv_h.isInvalid()) return error(); or put the whole code, from this line down, into if (uv_h.isValid()) { // just don't add "error()" here } Edited August 22, 2012 by mantragora Quote Link to comment Share on other sites More sharing options...
edward Posted August 21, 2012 Share Posted August 21, 2012 One can also simplify: GA_ROAttributeRef uv_ref = gdp->findVertexAttribute("uv"); GA_ROHandleV3 uv_h(uv_ref.getAttribute()); to GA_ROHandleV3 uv_h(gdp, GA_ATTRIB_VERTEX, "uv"); Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted August 22, 2012 Author Share Posted August 22, 2012 Thx for notes guys, but what about my main question? Why houdini crash on UT_Vector3 uv(uv_h.get(vtx_offset)). Is it a right way to get uv attribute given the GA_Offset? I need only vertex 0 from each primitive, can i get him without iterating over all vertices? Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 22, 2012 Share Posted August 22, 2012 Thx for notes guys, but what about my main question? Why houdini crash on UT_Vector3 uv(uv_h.get(vtx_offset)). Is it a right way to get uv attribute given the GA_Offset? I need only vertex 0 from each primitive, can i get him without iterating over all vertices? Have you tried fixing the code ? It works if you change the line I mentioned. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted August 22, 2012 Author Share Posted August 22, 2012 Have you tried fixing the code ? It works if you change the line I mentioned. Ohhhh, my mistake! For some reason i wrote ( ! isInvalid ), but it should be (! isValid ) Thx mantragora, i'll fix it when i get home. Any ideas about how to get only first vertex without iterator? Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 22, 2012 Share Posted August 22, 2012 (edited) Something like this should work: GA_Offset offset = *(prim->getVertexRange().begin()); UT_Vector3 uv(uv_h.get(offset)); cout << offset << "-(" << uv[0] << ", " << uv[1] << ", " << uv[2] << ")" << endl Edited August 22, 2012 by mantragora Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted August 22, 2012 Author Share Posted August 22, 2012 Thx mantragora! Everything works fine now. I have one more question. My SOP is assigning a couple off attributes to primitives. I think it should be possible to cook my sop only once, even if input geometry changes.For example - cached character. Topology doesn't changes, so maybe it's possible to cache it somehow.There is a duplicateChangedSource method, which takes GU_Topology as argument. I can't find any info on how to use this class.... Any ideas guys? Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted August 23, 2012 Share Posted August 23, 2012 I can't find any info on how to use this class.... Maybe because it's not a class but method ? Anyway, all those examples contains code how to use it SOP/SOP_BrushHairLen.C, SOP/SOP_CustomBrush.C, and SOP/SOP_IKSample.C. duplicateChangedSource Quote Link to comment Share on other sites More sharing options...
edward Posted August 23, 2012 Share Posted August 23, 2012 There's two duplicateChangedSource() methods, don't use the one with GU_Topology. Basically, I wouldn't recommend using GU_Topology at all. Quote Link to comment Share on other sites More sharing options...
edward Posted August 23, 2012 Share Posted August 23, 2012 I think it should be possible to cook my sop only once, even if input geometry changes. cookMySop() will always be called if it's used input changes. However, your cookMySop() may choose to return cached geometry instead. This is how the Cache SOP works, for example. Personally, I don't recommend doing this yourself because it is relatively hard to do so in a manner in which dependencies work. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted August 23, 2012 Author Share Posted August 23, 2012 cookMySop() will always be called if it's used input changes. However, your cookMySop() may choose to return cached geometry instead. This is how the Cache SOP works, for example. Personally, I don't recommend doing this yourself because it is relatively hard to do so in a manner in which dependencies work. Ok, i get it. For now, i'm pretty satisfied with performance i get. I'll try to implement multithreading, it should be more valuable in terms of execution speed. Thx guys for help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.