public virtual void CreateMeshData(MeshPoints points, List <int> connections) { if (_points.Count <= 2) { return; } //Add dummy tangent at the beginning and end _tangents.Add(Vector3.zero); for (int i = 1; i < _points.Count - 1; i++) { Vector3 a = _points[i - 1].Position; Vector3 b = _points[i].Position; Vector3 c = _points[i + 1].Position; Vector3 dir = _hasNormals ? _points[i].Normal : c - a; Vector3 tangent = Vector3.Cross(dir, c - b); _tangents.Add(tangent.normalized); } _tangents.Add(Vector3.zero); //End tangents are the same as their neighbors _tangents[0] = _tangents[1]; _tangents[_tangents.Count - 1] = _tangents[_tangents.Count - 2]; for (int i = 0; i < _points.Count; i++) { Vector3 t = _tangents[i] * _radii[i]; MeshPoint p0 = new MeshPoint(_points[i].Position + t); p0.Uv = new Vector3(0, i / (_points.Count - 1.0f)); p0.Color = _points[i].Color; points.Add(p0); MeshPoint p1 = new MeshPoint(_points[i].Position - t); p1.Uv = new Vector3(1, i / (_points.Count - 1.0f)); p1.Color = _points[i].Color; points.Add(p1); } _tangents.Clear(); for (int i = 0; i < _points.Count - 1; i++) { int offset = i * 2; connections.Add(offset + 0); connections.Add(offset + 1); connections.Add(offset + 2); connections.Add(offset + 1); connections.Add(offset + 3); connections.Add(offset + 2); } }
public void CreateMeshData(MeshPoints points, List <int> connections) { if (_points.Count <= 1) { return; } _points.CopyTo(points); for (int i = 0; i < _points.Count - 1; i++) { connections.Add(i); connections.Add(i + 1); } }
public void CreateMeshData(MeshPoints points, List <int> connections) { if (_radius == 0F || _radialSubdivisons < 2) { return; } // MeshPoints for (int i = 0; i < RadialSubdivisions; i++) { Vector3 radiusPoint = Quaternion.AngleAxis(i * (360F / RadialSubdivisions), Vector3.up) * Vector3.right * Radius; Vector3 radiusDirection = radiusPoint.normalized; MeshPoint p0 = new MeshPoint(radiusPoint - ((Quaternion.AngleAxis(_tangentAngle, Vector3.Cross(radiusDirection, Vector3.up)) * radiusDirection) * RibbonThickness / 2F)); p0.Uv = new Vector3(i / (float)RadialSubdivisions, 0F); p0.Color = Color.white; points.Add(p0); MeshPoint p1 = new MeshPoint(radiusPoint + ((Quaternion.AngleAxis(_tangentAngle, Vector3.Cross(radiusDirection, Vector3.up)) * radiusDirection) * RibbonThickness / 2F)); p1.Uv = new Vector3(i / (float)RadialSubdivisions, 1F); p1.Color = Color.white; points.Add(p1); } // Connections for (int i = 0; i < RadialSubdivisions - 1; i++) { int vertexOffset = i * 2; connections.Add(vertexOffset + 0); connections.Add(vertexOffset + 1); connections.Add(vertexOffset + 2); connections.Add(vertexOffset + 1); connections.Add(vertexOffset + 3); connections.Add(vertexOffset + 2); } // Complete the circle connections.Add((RadialSubdivisions * 2) - 2); connections.Add((RadialSubdivisions * 2) - 1); connections.Add(0); connections.Add((RadialSubdivisions * 2) - 1); connections.Add(1); connections.Add(0); }
public void CreateMeshData(MeshPoints points, List <int> connections) { if (_points.Count <= 2) { return; } //Add dummy tangent at the begining and end _tangents.Add(Vector3.zero); for (int i = 1; i < _points.Count - 1; i++) { Vector3 a = _points[i - 1].Position; Vector3 b = _points[i].Position; Vector3 c = _points[i + 1].Position; Vector3 dir = c - a; Vector3 tangent = Vector3.Cross(dir, c - b); _tangents.Add(tangent.normalized); } _tangents.Add(Vector3.zero); //End tangents are the same as their neighbors _tangents[0] = _tangents[1]; _tangents[_tangents.Count - 1] = _tangents[_tangents.Count - 2]; for (int i = 0; i < _points.Count; i++) { Vector3 t = _tangents[i]; Vector3 direction; if (i == 0) { direction = (_points[i + 1].Position - _points[i].Position).normalized; } else if (i == _points.Count - 1) { direction = (_points[i].Position - _points[i - 1].Position).normalized; } else { direction = (_points[i + 1].Position - _points[i - 1].Position).normalized; } MeshPoint centerPoint = _points[i]; float radius = _radii[i]; for (int j = 0; j < _resolution; j++) { float angle = j * 360.0f / _resolution; Quaternion rotation = Quaternion.AngleAxis(angle, direction); Vector3 spoke = rotation * t * radius; MeshPoint p = new MeshPoint(centerPoint.Position + spoke); p.Color = centerPoint.Color; p.Uv = new Vector2(j / (float)_resolution, i / (_points.Count - 1.0f)); points.Add(p); } } _tangents.Clear(); for (int i = 0; i < _points.Count - 1; i++) { int offset = i * _resolution; for (int j = 0; j < _resolution; j++) { int i0 = (j + 0) % _resolution + offset; int i1 = (j + 1) % _resolution + offset; int i2 = (j + 0) % _resolution + offset + _resolution; int i3 = (j + 1) % _resolution + offset + _resolution; connections.Add(i0); connections.Add(i1); connections.Add(i2); connections.Add(i1); connections.Add(i3); connections.Add(i2); } } }
public abstract void CreateMeshData(MeshPoints points, List <int> connections);
public void CopyTo(MeshPoints other) { other._points.AddRange(_points); other._hasNormalsDefined = _hasNormalsDefined; }