Commits

filipkunc committed 1c8c85c

Triangle and Quad Connect modes.

Comments (0)

Files changed (8)

 EnumClass VertexWindowMode
 {
     Add = 0,
-    Connect = 1,
+    TriangleConnect = 1,
+    QuadConnect = 2,
 };
 
     // make
     
     VertexNode *addVertex(const Vector3D &position);
-    TriangleNode *connectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector);
+    void quadVertexNodesNearPosition(const Vector3D &position, const Vector3D &eyeVector, vector<VertexNode *> &vertices);
+    TriangleNode *quadConnectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector);
+    void triangleVertexNodesNearPosition(const Vector3D &position, const Vector3D &eyeVector, vector<VertexNode *> &vertices);
+    TriangleNode *triangleConnectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector);
     VertexNode *findNearestVertex(const Vector3D &position, const vector<VertexNode *> &skipVertices) const;
 
     TriangleNode *addTriangle(VertexNode *v0, VertexNode *v1, VertexNode *v2);

Classes/Mesh2.make.cpp

     return _vertices.add(position);
 }
 
-TriangleNode *Mesh2::connectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector)
+void Mesh2::quadVertexNodesNearPosition(const Vector3D &position, const Vector3D &eyeVector, vector<VertexNode *> &vertices)
 {
-    vector<VertexNode *> vertices;
     Vector3D center = Vector3D();
     
     for (uint i = 0; i < 4; i++)
         }
     }
     
-    TriangleNode *quad = NULL;
-    
     switch (oppositeIndex_v0)
     {
         case 1:
-            quad = addQuad(vertices[0], vertices[3], vertices[1], vertices[2]);
+            swap(vertices[1], vertices[3]);
+            swap(vertices[2], vertices[3]);
             break;
         case 3:
-            quad = addQuad(vertices[0], vertices[1], vertices[3], vertices[2]);
-            break;
-        case 2:
-            quad = addQuad(vertices[0], vertices[1], vertices[2], vertices[3]);
+            swap(vertices[2], vertices[3]);
             break;
     }
     
-    if (quad)
+    Vector3D u, v;
+    u = vertices[0]->data().position - vertices[1]->data().position;
+    v = vertices[1]->data().position - vertices[2]->data().position;
+    Vector3D vertexNormal = u.Cross(v);
+    
+    if (vertexNormal.Dot(eyeVector) > 0.0f)
+        swap(vertices[0], vertices[2]);
+}
+
+TriangleNode *Mesh2::quadConnectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector)
+{
+    vector<VertexNode *> vertices;
+    quadVertexNodesNearPosition(position, eyeVector, vertices);
+    
+    TriangleNode *quad = addQuad(vertices[0], vertices[1], vertices[2], vertices[3]);
+    
+    makeEdges();
+    setSelectionMode(_selectionMode);
+    
+    return quad;
+}
+
+void Mesh2::triangleVertexNodesNearPosition(const Vector3D &position, const Vector3D &eyeVector, vector<VertexNode *> &vertices)
+{
+    for (uint i = 0; i < 3; i++)
     {
-        quad->data().computeNormalsIfNeeded();
-        if (quad->data().vertexNormal.Dot(eyeVector) > 0.0f)
-            quad->data().flip();
+        VertexNode *nearestVertex = findNearestVertex(position, vertices);
+        vertices.push_back(nearestVertex);
     }
     
-    makeEdges();
+    Vector3D u, v;
+    u = vertices[0]->data().position - vertices[1]->data().position;
+    v = vertices[1]->data().position - vertices[2]->data().position;
+    Vector3D vertexNormal = u.Cross(v);
+    
+    if (vertexNormal.Dot(eyeVector) > 0.0f)
+        swap(vertices[0], vertices[2]);
+}
+
+TriangleNode *Mesh2::triangleConnectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector)
+{
+    vector<VertexNode *> vertices;
+    triangleVertexNodesNearPosition(position, eyeVector, vertices);
     
+    TriangleNode *triangle = addTriangle(vertices[0], vertices[1], vertices[2]);
+    
+    makeEdges();
     setSelectionMode(_selectionMode);
     
-    return quad;
+    return triangle;
 }
 
 VertexNode *Mesh2::findNearestVertex(const Vector3D &position, const vector<VertexNode *> &skipVertices) const

Classes/MyDocument.cpp

             case VertexWindowMode::Add:
                 mesh->addVertex(position);
                 break;
-            case VertexWindowMode::Connect:
-                mesh->connectVerticesNearPosition(position, camera->GetAxisZ());
+            case VertexWindowMode::TriangleConnect:
+                mesh->triangleConnectVerticesNearPosition(position, camera->GetAxisZ());
+                mesh->resetTriangleCache();
+                break;
+            case VertexWindowMode::QuadConnect:
+                mesh->quadConnectVerticesNearPosition(position, camera->GetAxisZ());
                 mesh->resetTriangleCache();
                 break;
             default:
             case VertexWindowMode::Add:
                 vertices->push_back(position);
                 break;
-            case VertexWindowMode::Connect:
+            case VertexWindowMode::TriangleConnect:
             {
                 vector<VertexNode *> vertexNodes;
-                for (uint i = 0; i < 4; i++)
-                {
-                    VertexNode *nearestVertex = mesh->findNearestVertex(position, vertexNodes);
-                    vertexNodes.push_back(nearestVertex);
-                    vertices->push_back(nearestVertex->data().position);
-                }
-            }
-                break;
+                mesh->triangleVertexNodesNearPosition(position, camera->GetAxisZ(), vertexNodes);
+                for (uint i = 0; i < vertexNodes.size(); i++)
+                    vertices->push_back(vertexNodes[i]->data().position);
+            } break;
+            case VertexWindowMode::QuadConnect:
+            {
+                vector<VertexNode *> vertexNodes;
+                mesh->quadVertexNodesNearPosition(position, camera->GetAxisZ(), vertexNodes);
+                for (uint i = 0; i < vertexNodes.size(); i++)
+                    vertices->push_back(vertexNodes[i]->data().position);
+            } break;
             default:
                 break;
         }

Classes/OpenGLSceneViewCore.cpp

 	glEnable(GL_BLEND);
     
     glColor3f(1.0f, 0.0f, 0.0f);
+    
     glBegin(GL_POINTS);
     for (uint i = 0; i < _vertexHints.size(); i++)
     {
     }
     glEnd();
     
+    if (_vertexHints.size() > 1)
+    {
+        glBegin(GL_LINE_LOOP);
+        for (uint i = 0; i < _vertexHints.size(); i++)
+        {
+            glVertex3f(_vertexHints[i].x, _vertexHints[i].y, _vertexHints[i].z);
+        }
+        glEnd();
+    }
+    
     drawCurrentManipulator();
     
     drawOrthoDefaultManipulator();

Classes/Triangle.cpp

     }
 }
 
+Triangle2::Triangle2(const vector<VertexNode *> &vertices) :
+    selected(false),
+    visible(true),
+    _isQuad(vertices.size() == 4),
+    normalsAreValid(false)
+{
+    for (uint i = 0; i < count(); i++)
+    {
+        setVertex(i, vertices[i]);
+        setVertexEdge(i, NULL);
+        setTexCoord(i, NULL);
+        setTexCoordEdge(i, NULL);
+    }
+}
+
 const Triangle2::PackedNode &Triangle2::node(uint index) const
 {
     if (index < count())

Classes/Triangle.h

     Triangle2();
     Triangle2(VertexNode *vertices[], bool isQuad=false);
     Triangle2(VertexNode *vertices[], TexCoordNode *texCoords[], bool isQuad=false);
+    Triangle2(const vector<VertexNode *> &vertices);
 
     bool isQuad() const { return _isQuad; }
     uint count() const { return isQuad() ? 4U : 3U; }

Classes/VertexWindowController.xib

 			<object class="NSWindowTemplate" id="1005">
 				<int key="NSWindowStyleMask">19</int>
 				<int key="NSWindowBacking">2</int>
-				<string key="NSWindowRect">{{196, 240}, {134, 78}}</string>
+				<string key="NSWindowRect">{{196, 240}, {170, 98}}</string>
 				<int key="NSWTFlags">544735232</int>
 				<string key="NSWindowTitle">Vertex</string>
 				<string key="NSWindowClass">NSPanel</string>
 						<object class="NSMatrix" id="930369865">
 							<reference key="NSNextResponder" ref="1006"/>
 							<int key="NSvFlags">268</int>
-							<string key="NSFrame">{{20, 20}, {80, 38}}</string>
+							<string key="NSFrame">{{20, 20}, {130, 58}}</string>
 							<reference key="NSSuperview" ref="1006"/>
 							<reference key="NSWindow"/>
+							<reference key="NSNextKeyView"/>
 							<string key="NSReuseIdentifierKey">_NS:9</string>
 							<bool key="NSEnabled">YES</bool>
 							<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
-							<int key="NSNumRows">2</int>
+							<int key="NSNumRows">3</int>
 							<int key="NSNumCols">1</int>
 							<array class="NSMutableArray" key="NSCells">
 								<object class="NSButtonCell" id="761936036">
 									<int key="NSCellFlags">-2080374784</int>
 									<int key="NSCellFlags2">0</int>
-									<string key="NSContents">Add</string>
+									<string key="NSContents">Add Vertex</string>
 									<object class="NSFont" key="NSSupport" id="53045941">
 										<string key="NSName">LucidaGrande</string>
 										<double key="NSSize">13</double>
 								<object class="NSButtonCell" id="959563247">
 									<int key="NSCellFlags">67108864</int>
 									<int key="NSCellFlags2">0</int>
-									<string key="NSContents">Connect</string>
+									<string key="NSContents">Triangle Connect</string>
 									<reference key="NSSupport" ref="53045941"/>
 									<reference key="NSControlView" ref="930369865"/>
 									<int key="NSTag">1</int>
 									<int key="NSPeriodicDelay">400</int>
 									<int key="NSPeriodicInterval">75</int>
 								</object>
+								<object class="NSButtonCell" id="107966779">
+									<int key="NSCellFlags">67108864</int>
+									<int key="NSCellFlags2">0</int>
+									<string key="NSContents">Quad Connect</string>
+									<reference key="NSSupport" ref="53045941"/>
+									<reference key="NSControlView" ref="930369865"/>
+									<int key="NSTag">2</int>
+									<int key="NSButtonFlags">1211912448</int>
+									<int key="NSButtonFlags2">0</int>
+									<reference key="NSAlternateImage" ref="772251471"/>
+									<int key="NSPeriodicDelay">400</int>
+									<int key="NSPeriodicInterval">75</int>
+								</object>
 							</array>
-							<string key="NSCellSize">{80, 18}</string>
+							<string key="NSCellSize">{130, 18}</string>
 							<string key="NSIntercellSpacing">{4, 2}</string>
 							<int key="NSMatrixFlags">1151868928</int>
 							<string key="NSCellClass">NSActionCell</string>
 							<bool key="NSAutorecalculatesCellSize">YES</bool>
 						</object>
 					</array>
-					<string key="NSFrameSize">{134, 78}</string>
+					<string key="NSFrameSize">{170, 98}</string>
 					<reference key="NSSuperview"/>
 					<reference key="NSWindow"/>
 					<reference key="NSNextKeyView" ref="930369865"/>
 							<reference ref="1005968726"/>
 							<reference ref="761936036"/>
 							<reference ref="959563247"/>
-							<object class="IBNSLayoutConstraint" id="762697398">
-								<reference key="firstItem" ref="930369865"/>
-								<int key="firstAttribute">7</int>
-								<int key="relation">0</int>
-								<nil key="secondItem"/>
-								<int key="secondAttribute">0</int>
-								<float key="multiplier">1</float>
-								<object class="IBLayoutConstant" key="constant">
-									<double key="value">80</double>
-								</object>
-								<float key="priority">1000</float>
-								<reference key="containingView" ref="930369865"/>
-								<int key="scoringType">3</int>
-								<float key="scoringTypeFloat">9</float>
-								<int key="contentType">1</int>
-							</object>
+							<reference ref="107966779"/>
 						</array>
 						<reference key="parent" ref="1006"/>
 					</object>
 						<reference key="parent" ref="1006"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">14</int>
-						<reference key="object" ref="101225680"/>
-						<reference key="parent" ref="1006"/>
+						<int key="objectID">17</int>
+						<reference key="object" ref="107966779"/>
+						<reference key="parent" ref="930369865"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">15</int>
-						<reference key="object" ref="762697398"/>
-						<reference key="parent" ref="930369865"/>
+						<int key="objectID">19</int>
+						<reference key="object" ref="101225680"/>
+						<reference key="parent" ref="1006"/>
 					</object>
 				</array>
 			</object>
 				<string key="1.IBWindowTemplateEditedContentRect">{{357, 418}, {480, 270}}</string>
 				<integer value="1" key="1.NSWindowTemplate.visibleAtLaunch"/>
 				<string key="13.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<string key="14.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<string key="15.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+				<string key="17.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+				<string key="19.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<array class="NSMutableArray" key="2.IBNSViewMetadataConstraints">
 					<reference ref="784199954"/>
 					<reference ref="101225680"/>
 				</array>
 				<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-				<array class="NSMutableArray" key="5.IBNSViewMetadataConstraints">
-					<reference ref="762697398"/>
-				</array>
 				<boolean value="NO" key="5.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
 				<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 				<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
 			<nil key="activeLocalization"/>
 			<dictionary class="NSMutableDictionary" key="localizations"/>
 			<nil key="sourceID"/>
-			<int key="maxID">16</int>
+			<int key="maxID">19</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<array class="NSMutableArray" key="referencedPartialClassDescriptions">