1. filipkunc
  2. MeshMaker

Commits

filipkunc  committed 6c31512

Added eyeVector from camera for correct quad flip.

  • Participants
  • Parent commits 937217c
  • Branches master

Comments (0)

Files changed (7)

File Classes/Mesh2.h

View file
     // make
     
     VertexNode *addVertex(const Vector3D &position);
-    TriangleNode *connectVerticesNearPosition(const Vector3D &position);
+    TriangleNode *connectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector);
     VertexNode *findNearestVertex(const Vector3D &position, const vector<VertexNode *> &skipVertices) const;
 
     TriangleNode *addTriangle(VertexNode *v0, VertexNode *v1, VertexNode *v2);

File Classes/Mesh2.make.cpp

View file
     return _vertices.add(position);
 }
 
-TriangleNode *Mesh2::connectVerticesNearPosition(const Vector3D &position)
+TriangleNode *Mesh2::connectVerticesNearPosition(const Vector3D &position, const Vector3D &eyeVector)
 {
     vector<VertexNode *> vertices;
     Vector3D center = Vector3D();
             break;
     }
     
+    if (quad)
+    {
+        quad->data().computeNormalsIfNeeded();
+        if (quad->data().vertexNormal.Dot(eyeVector) > 0.0f)
+            quad->data().flip();
+    }
+    
     makeEdges();
     
     setSelectionMode(_selectionMode);

File Classes/MyDocument.cpp

View file
     return NO;
 }
 
-- (void)addVertex:(Vector3D)position
+- (void)addVertex:(Vector3D)position fromCamera:(Camera *)camera
 {
     if (vertexWindowController.isWindowLoaded && vertexWindowController.window.isVisible)
     {
                 mesh->addVertex(position);
                 break;
             case VertexWindowMode::Connect:
-                mesh->connectVerticesNearPosition(position);
+                mesh->connectVerticesNearPosition(position, camera->GetAxisZ());
                 mesh->resetTriangleCache();
                 break;
             default:

File Classes/OpenGLSceneView.cpp

View file
     virtual void selectionChanged() { [_sceneView.delegate selectionChangedInView:_sceneView]; }
     virtual bool texturePaintEnabled() { return [_sceneView.delegate texturePaintEnabled]; }
     virtual bool addVertexEnabled() { return [_sceneView.delegate addVertexEnabled]; }
-    virtual void addVertex(Vector3D position) { [_sceneView.delegate addVertex:position]; }
+    virtual void addVertex(Vector3D position, Camera *camera) { [_sceneView.delegate addVertex:position fromCamera:camera]; }
     virtual void makeCurrentContext() { [[_sceneView openGLContext] makeCurrentContext]; }
 };
 

File Classes/OpenGLSceneView.h

View file
 @property (readonly) BOOL texturePaintEnabled;
 @property (readonly) BOOL addVertexEnabled;
 
-- (void)addVertex:(Vector3D)position;
+- (void)addVertex:(Vector3D)position fromCamera:(Camera *)camera;
 
 @end
 

File Classes/OpenGLSceneViewCore.cpp

View file
     else if (_delegate->addVertexEnabled())
     {
         Vector3D position = addVertexPositionFromPoint(point);
-        _delegate->addVertex(position);
+        _delegate->addVertex(position, _camera);
     }
 	else if (_manipulated != NULL && _manipulated->selectedCount() > 0 && _currentManipulator->selectedIndex < UINT_MAX)
 	{

File Classes/OpenGLSceneViewCore.h

View file
     virtual void selectionChanged() = 0;
     virtual bool texturePaintEnabled() = 0;
     virtual bool addVertexEnabled() = 0;
-    virtual void addVertex(Vector3D position) = 0;
+    virtual void addVertex(Vector3D position, Camera *camera) = 0;
     virtual void makeCurrentContext() = 0;
 };