We are developing at Unity.
I draw 3D parabola with columns arranged side by side like LineRenderer.
[SerializeField] Vector3[]_positions;
SerializeField int_sides=3;
SerializeField float_radius=2;
private void GenerateMesh()
{
if(_mesh==null||_positions==null||_positions.Length<=1)
{
_mesh = new Mesh();
return;
}
varverticesLength=_sides*_positions.Length;
if(_vertices==null||_vertices.Length!=verticesLength)
{
_vertices=new Vector3 [verticesLength];
varindices=GenerateIndices();
varuvs = GenerateUVs();
if (verticesLength>_mesh.vertexCount)
{
_mesh.vertices=_vertices;
_mesh.triangles=indices;
_mesh.uv =uvs;
}
else
{
_mesh.triangles=indices;
_mesh.vertices=_vertices;
_mesh.uv =uvs;
}
}
varcurrentVertIndex=0;
for (inti=0;i<_positions.Length;i++)
{
var circle = Calculate Circle(i);
foreach (varvertex in circuit)
{
_vertices [currentVertIndex++] =vertex;
}
}
_mesh.vertices=_vertices;
_mesh.RecalculateNormals();
_mesh.RecalculateBounds();
_meshFilter.mesh=_mesh;
}
private Vector2 [ ] GenerateUVs()
{
varuvs = new Vector2 [_positions.Length*_sides];
for (int segment=0; segment<_positions.Length;segment++)
{
for ( int side = 0; side <_side; side++)
{
varvertIndex=(segment*_sides+side);
varu=side/(_sides-1f);
var v = segment /(_positions.Length-1f);
uvs [vertIndex] = new Vector2(u,v);
}
}
return uvs;
}
private int[] GenerateIndices()
{
// Twotriangles and 3vertices
varindices=new int [_positions.Length*_sides*2*3];
varcurrentIndicesIndex=0;
for (int segment=1; segment<_positions.Length;segment++)
{
for ( int side = 0; side <_side; side++)
{
varvertIndex=(segment*_sides+side);
varprevVertIndex=vertIndex-_sides;
// Triangle one
indices [currentIndicesIndex++] = prevVertIndex;
indications [currentIndicesIndex++] = (side==_sides-1) ? (vertIndex-(_sides-1) : (vertIndex+1);
indices [currentIndicesIndex++] =vertIndex;
// Triangle two
indices [currentIndicesIndex++] = (side==_sides-1) ? (prevVertIndex-(_sides-1) : (prevVertIndex+1);
indications [currentIndicesIndex++] = (side==_sides-1) ? (vertIndex-(_sides-1) : (vertIndex+1);
indices [currentIndicesIndex++] = prevVertIndex;
}
}
return indications;
}
private Vector3[] CalculateCircle(int index)
{
vardirCount = 0;
var forward = Vector3.zero;
// If not first index
if (index>0)
{
forward+=(_positions[index]-_positions[index-1]).normalized;
dirCount++;
}
// If not last index
if (index<_positions.Length-1)
{
forward+=(_positions[index+1]-_positions[index]).normalized;
dirCount++;
}
// Forward is the average of the connecting edges directions
forward=(forward/dirCount).normalized;
varside=Vector3.Cross(forward,forward+new Vector3 (.123564f, .34675f, .756892f)) .normalized;
varup=Vector3.Cross(forward,side).normalized;
var circle = new Vector 3 [_sides];
variable = 0f;
variableStep=(2*Mathf.PI)/_sides;
start = index /(_positions.Length-1f);
var radius=_radius;
for (inti=0;i<_sides;i++)
{
varx = Mathf.Cos(angle);
variable = Mathf.Sin(angle);
circuit[i]=_positions[index]+side*x*radius+up*y*radius;
angle+=angleStep;
}
return circuit;
}
However, the jaggy does not display very smoothly when you display it.
I am setting up PostProcessLayer, but it has not been resolved.
Do you know how to display 3D parabola smoothly?
Thank you for your cooperation.
unity3d
As warned, MSAA does not appear to be functioning because it is not set to Quality.
I haven't tried it, but it seems that the following settings are required.(Reference)
© 2024 OneMinuteCode. All rights reserved.