C
C#2mo ago
Ghost

Spline Mesh

I basically have a hermite curve which I have verified is correct. I have a mesh which I am trying to stretch along the mesh with no avail. If somebody cld help me understand how can I stretch it using openTk that wld be helpful.
var splineParams = splineMesh.SplineParams;
var curve = new HermiteCurve(splineParams.StartPos, splineParams.EndPos, splineParams.StartTangent, splineParams.EndTangent);

Vertices = new float[lod.NumVerts * VertexSize];
for (int i = 0; i < lod.Verts.Length; i++)
{
var count = 0;
var baseIndex = i * VertexSize;
var vert = lod.Verts[i];

var t = (float) i / (lod.Verts.Length - 1);
var point = curve.CalculatePoint(t);

Vertices[baseIndex + count++] = i;
Vertices[baseIndex + count++] = point.X * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = point.Z * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = point.Y * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = vert.Normal.X;
Vertices[baseIndex + count++] = vert.Normal.Z;
Vertices[baseIndex + count++] = vert.Normal.Y;
Vertices[baseIndex + count++] = vert.Tangent.X;
Vertices[baseIndex + count++] = vert.Tangent.Z;
Vertices[baseIndex + count++] = vert.Tangent.Y;
Vertices[baseIndex + count++] = vert.UV.U;
Vertices[baseIndex + count++] = vert.UV.V;
Vertices[baseIndex + count++] = .5f;
}
var splineParams = splineMesh.SplineParams;
var curve = new HermiteCurve(splineParams.StartPos, splineParams.EndPos, splineParams.StartTangent, splineParams.EndTangent);

Vertices = new float[lod.NumVerts * VertexSize];
for (int i = 0; i < lod.Verts.Length; i++)
{
var count = 0;
var baseIndex = i * VertexSize;
var vert = lod.Verts[i];

var t = (float) i / (lod.Verts.Length - 1);
var point = curve.CalculatePoint(t);

Vertices[baseIndex + count++] = i;
Vertices[baseIndex + count++] = point.X * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = point.Z * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = point.Y * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = vert.Normal.X;
Vertices[baseIndex + count++] = vert.Normal.Z;
Vertices[baseIndex + count++] = vert.Normal.Y;
Vertices[baseIndex + count++] = vert.Tangent.X;
Vertices[baseIndex + count++] = vert.Tangent.Z;
Vertices[baseIndex + count++] = vert.Tangent.Y;
Vertices[baseIndex + count++] = vert.UV.U;
Vertices[baseIndex + count++] = vert.UV.V;
Vertices[baseIndex + count++] = .5f;
}
No description
No description
35 Replies
Anton
Anton2mo ago
what is the original mesh? can you send a screenshot too?
Ghost
GhostOP2mo ago
sure
Ghost
GhostOP2mo ago
@Anton
No description
Ghost
GhostOP2mo ago
The first screenshot is what I tried and the second is the curve
Anton
Anton2mo ago
and what output do you expect? what does it mean to stretch a mesh along a mesh (you probably meant mesh along a curve or vice versa)
Ghost
GhostOP2mo ago
yes the mesh along a curve
Anton
Anton2mo ago
what does that mean?
Ghost
GhostOP2mo ago
my english aint that good So i am try my best to explain it
Ghost
GhostOP2mo ago
So basically I want the mesh to follow the curve without compressing or expanding
No description
Anton
Anton2mo ago
i mean you could also draw what you expect in paint or something
Ghost
GhostOP2mo ago
sure
Ghost
GhostOP2mo ago
so basially the black line represents the curve while the pruple line represents the mesh which I want to follow the curve
No description
Anton
Anton2mo ago
ok got it so you have a mesh that represents a slice and you want to repeat this slice mesh at a few points along the curve connecting consecutive slices between each other to form the outside of this "tunnel" do I got it right?
Ghost
GhostOP2mo ago
ye
Anton
Anton2mo ago
well whatever you're doing, first thing I'd recommend is laying out your vertices in memory you need a struct that represents the layout of a vertex
Ghost
GhostOP2mo ago
got it
Anton
Anton2mo ago
so you can't accidentally write one of the values at an incorrect index
Ghost
GhostOP2mo ago
I see
Anton
Anton2mo ago
this will make later discussions way easier doing some helper methods to set the values is ok too like, you could take a Span<float> of the current vertex data and have a method like MyVertex.PositionX(...) that sets the position that is pretty much equivalent to a struct with explicit layout
Ghost
GhostOP2mo ago
ok how do I actually deform the curve so that the mesh actually follows the curve
Anton
Anton2mo ago
have you done the vertex thing?
Ghost
GhostOP2mo ago
yes i saw that i have to do smething with Frenet–Serret formulas
Anton
Anton2mo ago
I don't know what that is well basically the idea is to make triangles between consecutive layers also you'll need to rotate your mesh in the direction of the splines tangent
Ghost
GhostOP2mo ago
how do I do that
Ghost
GhostOP2mo ago
Anton
Anton2mo ago
No description
Anton
Anton2mo ago
Here's an example of connecting two adjacent copies of a mesh (a triangle) the blue lines denote the triangles you need to add to the final mesh It depends how you do it on the way you're going to draw it but in its simplest form (no index buffer, no triangle strip draw call) you'd have to make a quad out of 2 pairs of vertices one pair per cosecutive mesh pair to make a quad you make 2 triangles that make it up just apply the transformation to the positions of the vertices multiply by a rotation matrix the rotation matrix that brings the general normal of you mesh (normally the up vector) to the spline's tangent it's some form of rotation around an axis
Ghost
GhostOP2mo ago
bro istg I am losing brain cells trying to deform this mesh
Anton
Anton2mo ago
do you know what a linear transformation is?
Ghost
GhostOP2mo ago
not really this is my first time messing with this stuff
Anton
Anton2mo ago
YouTube
Essence of linear algebra
A free course offering the core concept of linear algebra with a visuals-first approach.
From An unknown user
From An unknown user
Anton
Anton2mo ago
You might also want to learn the basics of homogenous coordinates, though probably not necessary for this problem
Ghost
GhostOP2mo ago
I just finished the linear transformaton topic so i think I am a bit familiar with it now
Anton
Anton2mo ago
Mathematics Stack Exchange
Calculate Rotation Matrix to align Vector $A$ to Vector $B$ in $3D$?
I have one triangle in $3D$ space that I am tracking in a simulation. Between time steps I have the previous normal of the triangle and the current normal of the triangle along with both the curren...
Anton
Anton2mo ago
this is the solution you need to move the normal to the tangent of the curve do that for each step, and you'll get the consecutive copies of the mesh aligned correctly at points of the curve you may want to try and generate that as your mesh first to see if you got it right and then do this between the consecutive slices

Did you find this page helpful?