sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Help with loading performance using Sketchup C SDK.

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 474 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kian123
      last edited by

      Hello,

      Not sure if this is the right place to ask this but I'm seeing that SUMeshHelperCreateWithTextureWriter is quite expensive performance wise when loading/decoding an skp file.

      Previously, when encountering simple/complex faces I'm using the above function to get the vertex & index buffers. What I was seeing is that it took 13 secs to load a small 4 mb sketchup file ( not allow to post this file). Using naive simple face implementation below, I was seeing only 4 secs. I'm interested to get the simple face that is found in the WriteFace function of the skp_to_xml sample going using
      SUFaceGetOuterLoop, SULoopGetVertices. Was wondering if there is a reference implementation of converting the points to vertex/index buffers when the num_loops == 1.

      // This block of code would be the one based upon the WriteFace function found in skp_to_xml sample:

          SULoopRef outer_loop = SU_INVALID;
          SU_CALL(SUFaceGetOuterLoop(face, &outer_loop));
          size_t num_vertices;
          SU_CALL(SULoopGetNumVertices(outer_loop, &num_vertices));
          if (num_vertices > 0) {
      
            std;;vector<SUVertexRef> vertices(num_vertices);
            SU_CALL(SULoopGetVertices(outer_loop, num_vertices, &vertices[0],
                                      &num_vertices));
      
            for (size_t i = 0; i < num_vertices; i++) {
              XmlFaceVertex vertex_infoFront;
      		XmlFaceVertex vertex_infoBack;
      
              // vertex position
              SUPoint3D su_point;
              SUVertexRef vertex_ref = vertices[i];
              SU_CALL(SUVertexGetPosition(vertex_ref, &su_point));
              vertex_infoFront.vertex_ = CPoint3d(su_point);
      		vertex_infoBack.vertex_ = CPoint3d(su_point);
      
              // texture coordinates
      		if (pFrontMat->m_bHasTexture ) {
                SUUVQ uvq;
                if (SUUVHelperGetFrontUVQ(uv_helper, &su_point, &uvq) ==
                    SU_ERROR_NONE) {
                  vertex_infoFront.front_texture_coord_ = CPoint3d(uvq.u, uvq.v, 0);
                }
              }
      
      		if (pBackMat->m_bHasTexture) {
                SUUVQ uvq;
                if (SUUVHelperGetBackUVQ(uv_helper, &su_point, &uvq) ==
                    SU_ERROR_NONE) { 
                  vertex_infoBack.back_texture_coord_ = CPoint3d(uvq.u, uvq.v, 0);
                }
              }
              pFrontMat->vertices_.push_back(vertex_infoFront);
      		pBackMat->vertices_.push_back(vertex_infoBack);
            }
              
      	  // Here is my naive implementation using triangle fan based upon the return vertices.
      	  // Will need to figure out how to handle concave/convex polygon.
      	  
      	  	size_t dwNumTrisFan = num_vertices - 2;
      		num_indices = dwNumTrisFan * 3;
      		pvIndicesToUseFront = new std;;vector<size_t>(num_indices);
      		pvIndicesToUseBack = new std;;vector<size_t>(num_indices);
      		for ( size_t i = 0; i < dwNumTrisFan; i++ )
      		{
      			size_t dwIndexCurr = i * 3;
      
      			(*pvIndicesToUseFront)[dwIndexCurr] = 0;
      			(*pvIndicesToUseFront)[dwIndexCurr+1] = i + 1;
      			(*pvIndicesToUseFront)[dwIndexCurr+2] = i + 2;
      
      			(*pvIndicesToUseBack)[dwIndexCurr] = 0;
      			(*pvIndicesToUseBack)[dwIndexCurr+1] = i + 2;
      			(*pvIndicesToUseBack)[dwIndexCurr+2] = i + 1;
      
      			XmlFaceVertex &F0 = pFrontMat->vertices_[(*pvIndicesToUseFront)[dwIndexCurr]];
      			XmlFaceVertex &F1 = pFrontMat->vertices_[(*pvIndicesToUseFront)[dwIndexCurr+1]];
      			XmlFaceVertex &F2 = pFrontMat->vertices_[(*pvIndicesToUseFront)[dwIndexCurr+2]];
      			
      			
      			XmlGeomUtils;;CPoint3d & v0 = F0.vertex_;
      			XmlGeomUtils;;CPoint3d & v1 = F1.vertex_;
      			XmlGeomUtils;;CPoint3d & v2 = F2.vertex_;
      
      			Vector vV0 = { (f32)v0.x(), (f32)v0.y(), (f32)v0.z(), 0.f };
      			Vector vV1 = { (f32)v1.x(), (f32)v1.y(), (f32)v1.z(), 0.f };
      			Vector vV2 = { (f32)v2.x(), (f32)v2.y(), (f32)v2.z(), 0.f };
      			Vector vE0E1 = { vV1.x - vV0.x, vV1.y - vV0.y, vV1.z - vV0.z, 0.f };
      			Vector vE0E2 = { vV2.x - vV0.x, vV2.y - vV0.y, vV2.z - vV0.z, 0.f };
      			Vector vNorm;
      			Vector_Cross ( &vNorm, &vE0E1, &vE0E2 );
      			Vector_Normalize ( &vNorm, &vNorm );
      			F0.normal_.SetDirection ( vNorm.x, vNorm.y, vNorm.z );
      			F1.normal_.SetDirection ( vNorm.x, vNorm.y, vNorm.z );
      			F2.normal_.SetDirection ( vNorm.x, vNorm.y, vNorm.z );
      		
      			XmlFaceVertex &F0Back = pBackMat->vertices_[(*pvIndicesToUseBack)[dwIndexCurr]];
      			XmlFaceVertex &F1Back = pBackMat->vertices_[(*pvIndicesToUseBack)[dwIndexCurr+1]];
      			XmlFaceVertex &F2Back = pBackMat->vertices_[(*pvIndicesToUseBack)[dwIndexCurr+2]];
      			
      			Vector vNormNeg;
      			Vector_Scale ( &vNormNeg, -1.f, &vNorm );
      			F0Back.normal_.SetDirection ( vNormNeg.x, vNormNeg.y, vNormNeg.z );
      			F1Back.normal_.SetDirection ( vNormNeg.x, vNormNeg.y, vNormNeg.z );
      			F2Back.normal_.SetDirection ( vNormNeg.x, vNormNeg.y, vNormNeg.z );
      			
      		}
          }
      

      Thanks in advance,
      Ian

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        You can also ask your question at:
        http://forums.sketchup.com/c/developers/sketchup-sdk

        The SketchUp Team members are more likely to answer, more quickly.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement