// Adds a point to the line currently being drawn private void addPointToLine(Vector3 pointToAdd, bool overrideThreshold = false) { if (!overrideThreshold && (pointToAdd - prevPaintPoint).magnitude <= 0.01f) { Debug.Log("Change in distance not large enough. Start: " + prevPaintPoint + " End: " + pointToAdd); return; } if (prevPaintPoint == pointToAdd) { Debug.Log("Point to add is same as previous point: " + pointToAdd); return; } currLine.AddPoint(pointToAdd); prevPaintPoint = pointToAdd; // add to history without incrementing index int index = GetComponent <PaintController> ().drawingHistoryIndex; int layerNum = GetComponent <PaintController>().GetActiveLayerNum(); paintBrushSceneObject.GetComponent <DrawingHistoryManager> ().addDrawingCommand(index, 0, pointToAdd, currLine.GetColor(), paintLineThickness, lMat, lMat_texture, layerNum); // Make sure the trail is off if (brushTipObject.activeSelf) { brushTipObject.GetComponent <TrailRenderer>().enabled = false; } }
} // _UpdateFeature() // Starts drawing a new line with the given point private void startNewLine(Vector3 firstPoint) { Debug.Log("startNewLine()"); // Make sure we are in drawing mode if (!paintPanel.activeSelf && !snapToSurfaceBrushTipObject.activeSelf) { return; } // Create a new line object GameObject go = new GameObject(); go.transform.position = firstPoint; go.transform.parent = drawingRootSceneObject.transform; go.AddComponent <MeshFilter> (); go.AddComponent <MeshRenderer> (); int layerNum = GetComponent <PaintController>().GetActiveLayerNum(); // Keep track of this line currLine = go.AddComponent <GraphicsLineRenderer>(); currLine.SetLayerNum(layerNum); // Configure the color, etc. of the line currLine.SetPrimaryMaterial(new Material(lMat)); if (lMat_texture) { currLine.SetSecondaryMaterial(new Material(lMat_texture)); } currLine.SetWidth(paintLineThickness); currLine.SetColor(colorPicker.GetColor()); // Keep track of the last point on the line prevPaintPoint = firstPoint; // Add to history and increment index Debug.Log("Adding History 1"); int index = GetComponent <PaintController> ().drawingHistoryIndex; index++; Debug.Log("Adding History 2"); paintBrushSceneObject.GetComponent <DrawingHistoryManager> ().addDrawingCommand(index, 0, firstPoint, currLine.GetColor(), paintLineThickness, lMat, lMat_texture, layerNum); Debug.Log("Adding History 3"); GetComponent <PaintController>().drawingHistoryIndex = index; Debug.Log("Done Adding History"); // Make sure the trail is off if (brushTipObject.activeSelf) { brushTipObject.GetComponent <TrailRenderer>().enabled = false; } }