/// <summary> /// Add data for the stroke object to the LivePolyMeshObject. Later, when the stroke /// is modified, we'll use its modified callback to update the stroke data keyed by /// this stroke - see onStrokeModified. /// </summary> private void addStrokePolygonData(KeyedPolyMeshObject polyMeshObj, StrokeObject strokeObj, List <Vector3> strokeMeshPositions, List <Polygon> strokeMeshPolygons, List <Edge> strokeSmoothEdges, List <Color> strokeColors) { polyMeshObj.AddDataFor(strokeObj, strokeMeshPositions, strokeMeshPolygons, strokeSmoothEdges, strokeColors); // TODO: This counting is hacky and not-robust :( foreach (var polygon in strokeMeshPolygons) { addedTriangleCount += (polygon.Count - 2) * 2; // double-sided means twice as // many triangles. } }
void LateUpdate() { var strokesToAdd = Pool <List <StrokeObject> > .Spawn(); strokesToAdd.Clear(); try { foreach (var child in this.transform.GetChildren()) { var strokeObj = child.GetComponent <StrokeObject>(); if (strokeObj != null) { strokesToAdd.Add(strokeObj); } } if (_curPolyMeshObj == null) { _curPolyMeshObj = createNewPolyMeshObj(); } foreach (var stroke in strokesToAdd) { stroke.transform.parent = _curPolyMeshObj.transform; var strokeMeshPolygons = Pool <List <Polygon> > .Spawn(); strokeMeshPolygons.Clear(); var strokeMeshPositions = Pool <List <Vector3> > .Spawn(); strokeMeshPositions.Clear(); var strokeSmoothEdges = Pool <List <Edge> > .Spawn(); strokeSmoothEdges.Clear(); var strokeColors = Pool <List <Color> > .Spawn(); strokeColors.Clear(); try { polyMesher.FillPolyMeshData(stroke, strokeMeshPositions, strokeMeshPolygons, strokeSmoothEdges, strokeColors); // If the current one is full, create a new LivePolyMeshObject for this // stroke's polygon data. if (_curPolyMeshObj.PolygonCount + strokeMeshPolygons.Count > maxPolygonsPerPolyMesh) { _livePolyMeshObjs.Add(_curPolyMeshObj); _pendingPolyMeshObjs.Add(_curPolyMeshObj); _curPolyMeshObj = createNewPolyMeshObj(); } addStrokePolygonData(_curPolyMeshObj, stroke, strokeMeshPositions, strokeMeshPolygons, strokeSmoothEdges, strokeColors); _strokeMeshes[stroke] = _curPolyMeshObj; List <StrokeObject> strokes; if (_meshStrokes.TryGetValue(_curPolyMeshObj, out strokes)) { strokes.Add(stroke); } else { // TODO not sure what to do here } stroke.OnStrokeModified += onStrokeModified; } finally { strokeMeshPolygons.Clear(); Pool <List <Polygon> > .Recycle(strokeMeshPolygons); strokeMeshPositions.Clear(); Pool <List <Vector3> > .Recycle(strokeMeshPositions); strokeSmoothEdges.Clear(); Pool <List <Edge> > .Recycle(strokeSmoothEdges); strokeColors.Clear(); Pool <List <Color> > .Recycle(strokeColors); } // Fire the temporary stroke-added callback. Temp_OnNewStrokeAdded(); } } finally { strokesToAdd.Clear(); Pool <List <StrokeObject> > .Recycle(strokesToAdd); } }