## ECS multiple materials per mesh (sub-mesh)

In my toy engine I currently have a MeshComponent and a MaterialComponent.

psuedo:

struct MeshComponent {     Ptr<Mesh> Mesh; };  struct MaterialComponent {     Ptr<Texture> DiffuseTexture;     Ptr<Texture> NormalsTexture; }; 

This is fine, for when a single mesh uses a single material.

pseudo:

Entity entity = CreateEntity(); AddComponentToEntity(entity, meshComponent); AddComponentToEntity(entity, materialComponent); 

But now I want to consider the concept of "sub-meshes" (regions of a mesh that are rendered with a different material, but each sub-mesh shares the parent vertex list). I don’t want my Mesh class to know anything about materials, and vice-versa.

What good approaches are there for "joining" multiple MaterialComponent to a single MeshComponent?

I’ve considered having an entity for each sub-mesh, but that seems brittle (not to mention overkill, as I’m only interested in MaterialComponents).

pseudo:

struct MeshComponent {     Ptr<Mesh> Mesh;     std::vector<Entity> SubMeshEntities; // Would need to ensure the indices match those of the sub-meshes }; 

What other approaches are there?

## Solving PDE with prescribed rectangular mesh

Question: I want to solve a PDE using NDEigensystem. The region is a rectangle Rectangle[{0,-70}, {20, 70}]. How can I make a mesh that satisfies the following two conditions?

(1) The mesh is finer near $$y \approx 0$$.

(2) The line $$y=0$$ should be the boundary of the mesh.

Motivation: The PDE that I want to solve can be written in the following command: First, I set the mesh as below:

mesh = ToElementMesh[Rectangle[{0, -70}, {20, 70}],     MeshRefinementFunction ->     Function[{vertices, area},      Block[ {x, y}, {x, y} = Mean[vertices];       If[-10 < y < 10, area > 0.1, area > 10]]] ] 

and then write down the PDE:

NDEigensystem[{{3*psi3[x, y] - 10*psi2[x, y]*Sign[y] - Derivative[0, 1][psi2][x, y] -      I*Derivative[1, 0][psi2][x, y], 3*psi4[x, y] - 10*psi1[x, y]*Sign[y] + Derivative[0, 1][psi1][x, y] -      I*Derivative[1, 0][psi1][x, y], 3*psi1[x, y] - 10*psi4[x, y]*Sign[y] - Derivative[0, 1][psi4][x, y] -      I*Derivative[1, 0][psi4][x, y], 3*psi2[x, y] - 10*psi3[x, y]*Sign[y] + Derivative[0, 1][psi3][x, y] -      I*Derivative[1, 0][psi3][x, y]}, PeriodicBoundaryCondition[psi1[x, y], x == 0,     TransformationFunction[{{1, 0, 20}, {0, 1, 0}, {0, 0, 1}}]], PeriodicBoundaryCondition[psi2[x, y], x == 0,     TransformationFunction[{{1, 0, 20}, {0, 1, 0}, {0, 0, 1}}]], PeriodicBoundaryCondition[psi3[x, y], x == 0,     TransformationFunction[{{1, 0, 20}, {0, 1, 0}, {0, 0, 1}}]], PeriodicBoundaryCondition[psi4[x, y], x == 0,     TransformationFunction[{{1, 0, 20}, {0, 1, 0}, {0, 0, 1}}]], DirichletCondition[psi1[x, y] == 0,     0 < x < 20 && (y == 70 || y == -70)], DirichletCondition[psi2[x, y] == 0,     0 < x < 20 && (y == 70 || y == -70)], DirichletCondition[psi3[x, y] == 0,     0 < x < 20 && (y == 70 || y == -70)], DirichletCondition[psi4[x, y] == 0,     0 < x < 20 && (y == 70 || y == -70)]}, {psi1, psi2, psi3, psi4}, Element[{x, y}, mesh], 10] 

The single important fact about the PDE is that the differential operator contains $$\mathrm{sgn}(y)$$, hence it is not continuous at $$y=0$$. This is why I want the mesh boundary to include $$y=0$$. The mesh I created is visualized as follows: As wanted, the mesh is finer. However, $$y=0$$ is not the boundary of the mesh.

The result of one solution obtained by solving the PDE is plotted as below: In the above plot, the horizontal direction is the $$x$$-direction. Note that the solution is localized near $$y\approx 0$$. This is why I want to make the mesh finer near $$y\approx 0$$. I don’t believe the result is the good representation of the solution, since the graph looks jagged, which I don’t expect since the differential operator has a translation symmetry in $$x$$-direction.

Posted on Categories cheapest proxies

## Change mesh density of Graphics3D object made of Triangles

I am new to mesh discretisation on Mathematica. I have a Graphics3D object made up of Triangles, that I would like to convert into a MeshRegion object using DiscretizeGraphics (see https://reference.wolfram.com/language/ref/DiscretizeGraphics.html).

In particular, I would like to control the mesh density. The above link tells me to use the MaxCellMeasure option, but it doesn’t seem to make any difference to my graphics!

Thus,

Table[DiscretizeGraphics[g,    MaxCellMeasure -> {"Area" -> m}], {m, {0.3, 0.01, 0.001}}] 

gives: As you can see, the meshing is unchanged. It doesn’t matter if I replace "Area" by "Volume" or "Length".

Can someone please tell me how to do this properly? Is this happening because my Graphics is already made up of triangles?

Posted on Categories cheapest proxies

## How to update indices for dynamic mesh in OpenGL?

So I am making a 3D batchrenderer for my engine, and the basic concept is that we make large enough VBO and IBO to accompany all the vertex data(positions, normals, uv etc.) and update the VBO using glMapBuffer or using glbuffersubdata everyframe if we want to make any changes, but in this case the pattern of the IBO (Index Buffer) is predefined (i.e. we assume we have quads and fill it with 012230 for the entirety of the IBO size) but when using 3D models this won’t be the case the IBOs data would be different, so how do I change the IBO data if I instantiate a new model or suppose if I am generating a UV sphere and want to change it’s subdivisions? I have no idea how to deal with dynamically changing(need not be frequent) indices data when using VAOs, VBOs and Index Buffers. afaik we cannot map the ELEMENT_ARRAY_BUFFER, and glDrawElements does accept a pointer to indices data but only when we are not using VAOs and VBOs, if we are using them it takes the last argument as a pointer offset in the currently bound ELEMENT_ARRAY_BUFFER. So what’s the best way to deal with dynamic indices?

## Blender->Unity Import Animation Failing by Overlapping Mesh Objects

I’m new to both Unity and Blender. I created this penguin 3d model, rigged it up and animated it in Blender and all looked good.

When I imported it into Unity, I noticed that this idle animation did not appear to be working correctly. As the body moves, the body mesh overlaps the belly mesh and covers a portion of it. This is not the case when viewing the animation from blender 2.9. The belly uses a shrinkwrap modifier with the body as a target.

Is this a problem with Unity import, or how I modeled this penguin in Blender? Can anyone see what I have done wrong here? Any help is much appreciated!

Posted on Categories Free Proxy

## Reused Avatar moves mesh

I have a humanoid avatar and it’s animation controller. I also have two different human meshes, they’re quite similar.

When I use the generic avatar and it’s controller in the animator the meshes shot out into the sky and perform their animation correctly.

The animations run normal they just move in weird directions and don’t stay in their original locations.

How to fix it so the mesh doesn’t move far away and retain original position?

## Using fewer mesh lines, 3D graphics

    I want to make the Final use fewer mesh lines,      the ideal version will look like the second image.     Where the triangle shape is more clear and clean. Can anyone give me some advice on how to fix my code?  

ex1 = ParametricPlot3D[{(3 + Cos[v]) Cos[u], (3 + Cos[v]) Sin[u], Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, Boxed -> False, Axes -> False]

mesh = Import[Export[NotebookDirectory[] <> "ex1.stl", ex1]]

edges = MeshPrimitives[mesh, 1]

Final = Graphics3D[Map[Tube[#, .05] &, edges[[All, 1]]],Boxed -> False]  ## How do you use custom collision on a skeletal mesh in UE4?

I have a vehicle rig that is a skeletal mesh that imports fine in to unreal but I was wondering how to use a mesh for collision on it. Normally you can just name the collision mesh with UCX_ in front of the name to do it but with skeletal meshes it makes you use a system called phat and I only see cubes/spheres/capsules for collision with that.

## Remove mesh triangles in contour plot

How do I get rid of the mesh in this contour plot?

 ContourPlot[x^2 + y^2, {x, -10, 10}, {y, -10, 10},      Contours -> {1.0, 4.0, 10.5}, ContourStyle -> None,      ContourShading -> {RGBColor[1, .2, 0, .1], RGBColor[1, .2, 0, .3],      RGBColor[1, .2, 0, .5], RGBColor[1, .2, 0, .7]}] Setting the option Mesh->None doesn’t help. I’m using Mathematica 12.1.1

## Improving mesh and NDSolve solution convergence

I have developed the code below to solve two PDEs; first mu[x,y] is solved for, then the results of mu are used to solve for phi[x,y]. The code works and converges on a solution as is, however, I would like to decrease the size of a, b, and d even further. To accurately represent the physical process I am trying to simulate, a, b, and d would need to be ~100-1000x smaller. If I make them smaller, I don’t believe the solution has actually converged because the values for phi along the right boundary change significantly with a change in mesh size (i.e. if I make them smaller and the code below produces a value of phi=-0.764 at the midpoint between y2 and y3 along the right boundary, a change in size1 to 10^-17 and size2 to 10^-15, changes that value of phi to -0.763, and a change in size2 to 10^-16 changes that value again to -0.860), but I cannot make the mesh size any smaller without Mathematica crashing.

Are there any better ways to create the mesh that would be less computationally taxing and allow it to be more refined in the regions of interest? Or are there any ways to make the code in general less computationally expensive so that I can further refine the mesh?

ClearAll["Global*"] Needs["NDSolveFEM"] (* 1) Define Constants*) e = 1.60217662*10^-19; F = 96485; kb = 1.381*10^-23; sigi = 18; sigini = 0; sigeni = 2*10^6; T = 1000; n = -0.02; c = 1;  pH2 = 0.2; pH2O = 1 - pH2; pO2 = 1.52*^-19; l = 10*10^-6; a = 100*10^-7; b = 50*10^-7; d = 300*10^-7; y1 = 0.01; y2 = 0.5*y1; y3 = y2 + a; y4 = y3 + d; y5 = y4 + b; mu1 = 0; mu2 = -5.98392*^-19; phi1 = 0;  (* 2) Create mesh*) m = 0.1*l; size1 = 10^-16; size2 = 10^-15; size3 = 10^-7; mrf = With[{rmf =       RegionMember[       Region@RegionUnion[Disk[{l, y2}, m], Disk[{l, y3}, m],          Disk[{l, y4}, m], Disk[{l, y5}, m]]]},     Function[{vertices, area}, Block[{x, y}, {x, y} = Mean[vertices];      Which[rmf[{x, y}],        area > size1, (0 <= x <= l && y2 - l <= y <= y2 + l),        area > size2, (0 <= x <= l && y3 - l <= y <= y3 + l),        area > size2, (0 <= x <= l && y4 - l <= y <= y4 + l),        area > size2, (0 <= x <= l && y5 - l <= y <= y5 + l),        area > size2, True, area > size3]]]]; mesh = DiscretizeRegion[Rectangle[{0, 0}, {l, y1}],     MeshRefinementFunction -> mrf];  (* 3) Solve for mu*) bcmu = {DirichletCondition[mu[x, y] == mu1, (x == 0 && 0 < y < y1)],    DirichletCondition[     mu[x, y] ==       mu2, (x == l && y2 <=  y <=  y3) || (x == l && y4 <= y <= y5)]}; solmu = NDSolve[{Laplacian[mu[x, y], {x, y}] ==       0 + NeumannValue[0, y == 0 || y == y1 ||         (x == l && 0 <= y < y2) || (x == l &&            y3 < y < y4) || (x == l && y5 < y < y1)], bcmu},     mu, {x, y} \[Element] mesh, WorkingPrecision -> 50];  (* 4) Solve for electronic conductivity everywhere*) pO2data = Exp[(mu[x, y] /. solmu)/kb/T]; sige0 = 2.77*10^-7; sigedata = Piecewise[{{sige0*pO2data^(-1/4), 0 <= x <= l - m},     {sige0*pO2data^(-1/4), (l - m < x <= l && 0 <= y < y2)},     {(sigeni - sige0*(pO2data /. x -> l - m)^(-1/4))/m*(x - (l - m)) +        sige0*(pO2data /. x -> l - m)^(-1/4), (l - m < x <= l &&         y2 <=  y <= y3)},     {sige0*pO2data^(-1/4), (l - m < x <= l && y3 < y < y4)},     {(sigeni - sige0*(pO2data /. x -> l - m)^(-1/4))/m*(x - (l - m)) +        sige0*(pO2data /. x -> l - m)^(-1/4), (l - m < x <= l &&         y4 <= y <= y5)},     {sige0*pO2data^(-1/4), (l - m < x <= l && y5 < y <= y1)}}];  (* 5) Solve for phi*) Irxn = -(2*F)*(c*pO2^n ); A = (Irxn - sigi/(4*e)*(D[mu[x, y] /. solmu, x] /. x -> l))/(-sigi); B = sigi/(4*e)*(D[mu[x, y] /. solmu, x] /.        x -> l)/(sigi + sigedata /. x -> l - m); bcphi = DirichletCondition[phi[x, y] == phi1, (x == 0 && 0 < y < y1)]; solphi = NDSolve[{Laplacian[phi[x, y], {x, y}] ==       0 + NeumannValue[0,         y == 0 ||          y == y1 || (x == l && 0 <= y < y2) || (x == l &&            y3 < y < y4) || (x == l && y5 < y < y1)] +        NeumannValue[-A[], (x == l && y2 <= y <= y3)] +        NeumannValue[-B[], (x == l && y4 <= y <= y5)], bcphi},     phi, {x, y} \[Element] mesh, WorkingPrecision -> 50];  (* 6) Print values to check for convergence*) P[x_, y_] := phi[x, y] /. solphi; P[l, (y3 - y2)/2 + y2] P[l, (y5 - y4)/2 + y4] `
Posted on Categories cheapest proxies