*/}}
Prechádzať zdrojové kódy

Batch thickness, fix make from 2v issue.

YimingWu 1 rok pred
rodič
commit
ab1d92ea39
3 zmenil súbory, kde vykonal 18 pridanie a 5 odobranie
  1. 3 1
      la_tns.h
  2. 9 1
      la_tns_kernel.c
  3. 6 3
      resources/la_modelling.c

+ 3 - 1
la_tns.h

@@ -749,10 +749,11 @@ STRUCTURE(tnsBatchCommand){
     GLuint EBO; //elem
     u32bit ElementCount;
     GLenum DrawAs;
-    int UseUniformColor; real UniformColor[4];
     GLuint CBO; int ColorDimension; int OverrideColorArray;
     int Dimension;
     int HiddenByDefault;
+    int UseUniformColor; real UniformColor[4];
+    real Width;
 };
 STRUCTURE(tnsBatch){
     laListItem Item;
@@ -977,6 +978,7 @@ void tnsShadeMode(GLenum ShadeMode);
 
 tnsBatch *tnsCreateBatch(u32bit NumVert, int Dimension, float *Data, int NormalDimension, float *Normal, int ColorDimension, float *Colors);
 tnsBatch *tnsCreateBatchi(u32bit NumVert, int Dimension, int *Data);
+void tnsCommandUseWidth(tnsBatchCommand*c, real width);
 void tnsCommandUseUniformColor(tnsBatchCommand*c,real* color);
 void tnsCommandOverrideColorArray(tnsBatchCommand*c, int VertCount, int ColorDimension, float* colors);
 tnsBatchCommand *tnsCreateCommand(tnsBatch *b, const char* name, u32bit ElementCount, int Dimension, GLenum DrawAs, u32bit *Elements, int HiddenByDefault);

+ 9 - 1
la_tns_kernel.c

@@ -1515,6 +1515,9 @@ void tnsCommandUseUniformColor(tnsBatchCommand*c, real* color){
     tnsVectorCopy4d(color, c->UniformColor);
     c->UseUniformColor=1;
 }
+void tnsCommandUseWidth(tnsBatchCommand*c, real width){
+    c->Width=width;
+}
 void tnsCommandOverrideColorArray(tnsBatchCommand*c, int VertCount, int ColorDimension, float* colors){
     if(!colors) return;
     c->OverrideColorArray=1; 
@@ -1581,7 +1584,7 @@ void tnsDrawBatch(tnsBatch* batch, const char* OverrideCommand, real* OverrideUn
         }
     }
 
-    int IsOverrideColor=0;
+    int IsOverrideColor=0; int PointSizeChanged=0,LineWidthChanged=0;
 	for (tnsBatchCommand* bc = batch->Branches.pFirst; bc; bc = bc->Item.pNext) {
         if(OverrideCommand && !strSame(OverrideCommand, bc->name)){ continue; }
         if(!OverrideCommand && bc->HiddenByDefault){ continue; }
@@ -1599,11 +1602,16 @@ void tnsDrawBatch(tnsBatch* batch, const char* OverrideCommand, real* OverrideUn
                 else glVertexAttrib4f(cs->iColor,LA_COLOR4(bc->UniformColor)); 
             }
         }
+        if(bc->DrawAs == GL_POINTS && bc->Width>1e-5){ glPointSize(bc->Width); PointSizeChanged=1; }
+        if((bc->DrawAs == GL_LINE_STRIP||bc->DrawAs == GL_LINES||bc->DrawAs == GL_LINE_LOOP) && bc->Width>1e-5){
+            glLineWidth(bc->Width); LineWidthChanged=1;
+        }
         int DrawElements=OverrideAsArray?0:bc->DrawElements;
         if(DrawElements){
             glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bc->EBO);
             glDrawElements(bc->DrawAs, bc->ElementCount*bc->Dimension, GL_UNSIGNED_INT, 0);
         }else{ glDrawArrays(bc->DrawAs,0,bc->ElementCount); }
+        if(PointSizeChanged){ glPointSize(1); } if(LineWidthChanged){ glLineWidth(1); }
 	}
 
 	//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

+ 6 - 3
resources/la_modelling.c

@@ -152,7 +152,7 @@ void la_PopulateSelectDataPrimitives(MSelectData* sd, tnsMeshObject* mo, tnsCame
     glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
     glEnable(GL_DEPTH_TEST);
     tnsPushMatrix(); tnsApplyObjectMatrix(mo);
-    if(Knife){ glPointSize(10); }
+    if(Knife){ glPointSize(5); }
     if(DoEdges || Knife){ tnsDrawBatch(mo->Batch, "edges_select",0,0); }
     if(DoVerts || Knife){ tnsDrawBatch(mo->Batch, "verts_select",0,0); }
     if(Knife){ glPointSize(1); }
@@ -1073,8 +1073,9 @@ tnsMFace* la_MakeFacesFrom2Verts(tnsMeshObject* mo, tnsMVert* mv1, tnsMVert* mv2
     if(!oe1||!oe2) return 0;
     ov1=tnsMMeshEdgeAnotherVert(oe1,mv1); ov2=tnsMMeshEdgeAnotherVert(oe2,mv2);
     ov1->flags|=TNS_MESH_FLAG_SELECTED;ov2->flags|=TNS_MESH_FLAG_SELECTED; mv1->flags&=(~TNS_MESH_FLAG_SELECTED);mv2->flags&=(~TNS_MESH_FLAG_SELECTED);
-    laListHandle vl={0}; lstAppendPointer(&vl,ov1); lstAppendPointer(&vl,mv1); lstAppendPointer(&vl,mv2); lstAppendPointer(&vl,ov2);
-    tnsMFace* f=tnsMMeshMakeFaceN(mo, 4, &vl, 0); tnsMMeshEnsureSelectionFromVerts(mo);
+    laListHandle vl={0}; int vcount=3;
+    lstAppendPointer(&vl,ov1); lstAppendPointer(&vl,mv1); lstAppendPointer(&vl,mv2); if(ov2!=ov1){ lstAppendPointer(&vl,ov2); vcount=4; }
+    tnsMFace* f=tnsMMeshMakeFaceN(mo, vcount, &vl, 0); tnsMMeshEnsureSelectionFromVerts(mo);
     while(lstPopPointer(&vl)); return f;
 }
 int la_IsEndingVert(tnsMVert* mv){
@@ -1323,8 +1324,10 @@ void la_KnifeUpdateToolBatch(MSelectExtra* se,tnsObject* o){
     if(count){
         c=tnsCreateCommand(batch, "edges", count+1, 3, GL_LINE_STRIP, 0, 0);
         tnsCommandUseUniformColor(c,laAccentColor(LA_BT_NORMAL));
+        tnsCommandUseWidth(c, 2);
         c=tnsCreateCommand(batch, "points", count+1, 3, GL_POINTS, 0, 0);
         tnsCommandUseUniformColor(c,laAccentColor(LA_BT_NORMAL));
+        tnsCommandUseWidth(c, 6);
     }
     se->root->ExtraBatch=batch;
     free(points);