ObjFile not properl...

Clear all

1 Posts
1 Users
0 Likes
0 Views
Illustrious Member
Joined: 4 months ago
Posts: 57388
Topic starter

i am losing my mind. I am trying to create an obj parser has a way to learn opengl but i have ran into a brick wall. with DMGregory help i got the textures to work i think but know the mesh just looks like a blob

--Result--

--Obj parser code--

``````using OpenTK.Mathematics;
using System.Runtime.InteropServices;

using Core.Common.Objects;

namespace Core.Common
{
{
public (vertex[] vertices, int[] indices) LoadObj(string path)
{
List<Vector3> Positions = new List<Vector3>();
List<Vector2> texCoords = new List<Vector2>();

List<int> position_Indices = new List<int>();
List<int> texture_Indices = new List<int>();

int[] indicesArray = null;
vertex[] vertices = null;

Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.ResetColor();

foreach (string line in lines)
{
string[] parts = line.Split(' ');

switch (parts[0])
{
case "v":
Vector3 pos = new Vector3(Convert.ToSingle(parts[1]), Convert.ToSingle(parts[2]), Convert.ToSingle(parts[3]));
break;

case "vt":
Vector2 texture = new Vector2(float.Parse(parts[1]), float.Parse(parts[2]));
break;

case "f":
string[] vertex1 = parts[1].Split('/');
string[] vertex2 = parts[2].Split('/');
string[] vertex3 = parts[3].Split('/');

int index1 = int.Parse(vertex1[0]) - 1;
int index2 = int.Parse(vertex2[0]) - 1;
int index3 = int.Parse(vertex3[0]) - 1;

int texIndex1 = Int32.Parse(vertex1[1]) - 1;
int texIndex2 = Int32.Parse(vertex2[1]) - 1;
int texIndex3 = Int32.Parse(vertex3[1]) - 1;

break;
}
}

// bellow is modified\

indicesArray = new int[position_Indices.Count];
vertices = new vertex[position_Indices.Count];

for (int i = 0; i < vertices.Length; i++)
{
vertices[i].pos = Positions[position_Indices[i]];
vertices[i].tex = texCoords[texture_Indices[i]];
}

for (int i = 0; i < position_Indices.Count; i++)
{
indicesArray[i] = i;
}

foreach (var item in vertices)
{
Console.WriteLine(item.pos);
}

return (vertices, indicesArray); //return modeldata and faces
}

}
}
``````

--Rendering code--

``````using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using System.Runtime.InteropServices;

using Core.Common.Objects;
using Core.Render;

namespace Core.Common
{
{
private List<int> vbos = new List<int>();
private List<int> vaos = new List<int>();

public RawModel loadModel(vertex[] verts, int[] indices, string texPath)
{
int vao = createVAO();
bindIndicesBuffer(indices);
storeDataInPosAttribList(0, 3, verts, vertex.Stride);
storeDataInTexAttribList(1, 2, verts, vertex.Stride);
unbindVAO();
return new RawModel(vao, indices.Length);
}

private int createVAO()
{
int vao = GL.GenVertexArray();
GL.BindVertexArray(vao);
return vao;
}

{
Texture texture;
texture.Use(TextureUnit.Texture0);
}

private void storeDataInPosAttribList(int attribNum, int size, vertex[]  verts, int stride)
{
int vbo = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
// bellow is modified\
GL.BufferData(BufferTarget.ArrayBuffer, stride * Vector3.SizeInBytes, ref verts[0].pos, BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(attribNum, size, VertexAttribPointerType.Float, false, 0, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
}

private void storeDataInTexAttribList(int attribNum, int size, vertex[] tex, int stride)
{
int vbo = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
// bellow is modified\
GL.BufferData(BufferTarget.ArrayBuffer, stride * Vector2.SizeInBytes, ref tex[0].tex, BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(attribNum, size, VertexAttribPointerType.Float, false, 0, 0);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
}

private void unbindVAO()
{
GL.BindVertexArray(0);
}

private void bindIndicesBuffer(int[] indices)
{
int vbo = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo);
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(int), indices, BufferUsageHint.StaticDraw);
}

public void cleanUP()
{
foreach (var item in vaos)
{
GL.DeleteVertexArray(item);
}

foreach (var item in vbos)
{
GL.DeleteBuffer(item);
}

}

}
}
``````

## Pushout in the category of commutative unital \$C^{ast}\$-algebras

What is the pushout in the category of commutative unital $$C^{ast}$$-algebras? Is it the tensor product? Is it the same as in the category of noncommutative unital $$C^{ast}$$-algebras?

## Bounds on the maximum real root of a polynomial with coefficients \$-1,0,1\$

Suppose I have a polynomial that is given a form
$$f(x)=x^n – a_{n-1}x^{n-1} – ldots – a_1x – 1$$

where each $$a_k$$ can be either $$0,1$$.

I’ve tried a bunch of examples and found that the maximum real root seems to be between $$1,2$$, but as for specifics of a polynomial of this structure I am not aware.

Using IVT, we can see pretty simply that $$f(1)leq0$$ and $$f(2)> 0$$ so there has to be a root on this interval, but thats a pretty wide range was wondering if this was previously studied

## What are active deformable particles?

Could anyone please clarify to me what active particles, in particular active deformable particles are? I have never heard of them, and I am quite curious

## Autoequivalences of \$operatorname{Coh}(X)\$

Let $$X$$ be a smooth projective variety over an algebraically closed field $$k$$ of characteristic zero.

Is there a description of $$operatorname{Aut}(operatorname{Coh}(X))$$, i.e. the autoequivalences of the category $$operatorname{Coh}(X)$$?

Clearly it contains $$operatorname{Aut}(X)ltimesoperatorname{Pic}(X)$$ as a subgroup.

## What exactly does the Remainder Estimate for Integral Test actually mean? \$R_n le int_{n}^{infty}f(x)dx\$

$$int_{n+1}^{infty}f(x)dx le R_n le int_{n}^{infty}f(x)dx$$

What does this actually mean?

Let’s use n=5.

The $$R_5$$ is the error of the partial sum $$S_5$$

That error is less than the sum of the remaining terms from 5 to $$infty$$ ?

Why is that?

Also, why is it greater than sum of the remaining terms from 6 to $$infty$$ ?

## Simple proof for a congruence relation connecting the \$p\$-adic order of a positive integer and a sum of binomial coefficients

Let $$n$$ be a positive integer and $$p$$ be a prime. Let $$v_p(n)$$ be the $$p$$-adic order of $$n$$, i.e., the exponent of the highest power of $$p$$ that divides $$n$$. I would like to know if there is a quick and simple proof for the following congruence relation.
$$sum_{j=1}^{lfloor log_{p} n rfloor} {n-1 choose p^j-1} equiv v_p(n) ;mbox{(mod }pmbox{)}.$$

Key ideas involved in a ‘not so simple proof’ can be found in http://math.colgate.edu/~integers/w61/w61.pdf

Best wishes.

## Continuity of the fractional Laplacian operator

Considering $$(-Delta)^s: H^s(Omega) to L^2(Omega)$$, is it possible to show that this operator is closed (continuous)?
For instance, taking a sequence $$(u_n) subset H^s(Omega)$$ with $$u_n to u$$ in $$H^s(Omega)$$, we need to show that $$(-Delta)^su_n to (-Delta)^su$$ in $$L^2(Omega)$$.

Attempt:

Consider
$$lim_{n to +infty}int_Omega |(-Delta^s)u_n(x)|^2 dx = lim_{n to +infty} int_Omega Big(int_Omega frac{u_n(x) – u_n(y)}{|x – y|^{N + 2s}} dyBig)^2 dx.$$

So my idea would be to use some inequality (perhaps something similar to the Poincaré inequality) to obtain the norm of $$u_n$$ in $$H^s(Omega)$$ on the right side. But, I don’t know how to get rid of this one on the right side of the expression above.

## How to make associated ribbon surface?

I am studying ribbon graphs on surfaces. I am reading this paper (page 5).

But I have confused about how to make surfaces using the ribbon graphs. Actually, we call this surfaces as associated ribbon surfaces.

The definition of ribbon graph is given in definition 1.5 of the above mentioned paper.

Consider the following ribbon graph

To get its associated ribbon surface, first we do its edge refinement by adding each edge a degree two vertex. Then consider the half edges incident to each vertices of the graph.

Then replace the half edges with thin strips with the orientation on boundaries (this orientation of the boundaries follows the orientation of each vertex), which is as follows:

My question is how we connect the strips corresponding to the two half edges following the orientation of their boundaries to form ribbons?

## Characterization of the Poisson distribution

Let $$Z$$ be a $$[0, infty)$$-valued random variable satisfying $$lambda E[g(Z+1)] = E[Zg(Z)]$$ for all indicator functions $$g$$ of Borel subsets of $$[0, infty)$$.

Prove that $$mathcal{L}(Z) = Poisson(lambda)$$.

Hint: Consider $$1_{(n,n+1)}$$ for $$n in mathbb{N}_0$$.

Proof:

Let $$n in mathbb{N}_0$$ and g = 1_{(n,n+1)}, then holds:
begin{align*} lambda E[g(Z+1)] = lambda P[Z+1 in (n,n+1)] = lambda (P[Z+1 = n+1] – P[Z+1 = n]) = lambda P[Z = n] – lambda P[Z = n-1]). end{align*}
But what is
begin{align*} E[Zg(Z)] = E[Z cdot 1_{(n,n+1)}(Z)] = ? end{align*}

Have I got everything right so far? If so, how should I proceed now?

Thanks for the help!

## What is a sufficient and necessary condition for a system of linear equations to have a unique integer solution?

Bézout’s theorem states that a linear diophantine equation $$ax+by=c$$ has integer solutions if and only if $$gcd(a,b)|c$$. Then is there a theorem regarding the existence of a unique integer solution for a system of two linear equations $$ax+by=c$$ and $$px+qy=m$$, where $$a,b,c,p,q,m$$ are positive integers?

Additionally, can the theorem be generalized to the condition where there are more than two unknowns?

Share: