Skip to content

Commit

Permalink
fix hmac and normals for planet mesh generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlinka committed Jun 26, 2024
1 parent b85b400 commit 34deeba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
36 changes: 16 additions & 20 deletions ProjectObsidian/Components/Mesh/Planet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@ private void GeneratePlanet(MeshX mesh, int subdivisions, float radius, float no
// Apply noise to vertices
ApplyPerlinNoise(vertices, radius, noiseScale, noiseStrength);

// Assign vertices and triangles to the mesh
// Assign vertices, normals, and triangles to the mesh
mesh.SetVertexCount(vertices.Count);
for (int i = 0; i < vertices.Count; i++)
{
mesh.SetVertex(i, vertices[i]);
mesh.SetNormal(i, vertices[i].Normalized); // Set normals directly
}

for (int i = 0; i < triangles.Count; i += 3)
{
mesh.AddTriangle(triangles[i], triangles[i + 1], triangles[i + 2]);
}

// mesh.RecalculateNormals(AllTriangles);
}

private void CreateIcosahedron(List<float3> vertices, List<int> triangles)
{
float t = (1.0f + MathX.Sqrt(5.0f)) / 2.0f;

vertices.Add(new float3(-1, t, 0));
vertices.Add(new float3(1, t, 0));
vertices.Add(new float3(-1, -t, 0));
vertices.Add(new float3(1, -t, 0));
vertices.Add(new float3(-1, t, 0).Normalized);
vertices.Add(new float3(1, t, 0).Normalized);
vertices.Add(new float3(-1, -t, 0).Normalized);
vertices.Add(new float3(1, -t, 0).Normalized);

vertices.Add(new float3(0, -1, t));
vertices.Add(new float3(0, 1, t));
vertices.Add(new float3(0, -1, -t));
vertices.Add(new float3(0, 1, -t));
vertices.Add(new float3(0, -1, t).Normalized);
vertices.Add(new float3(0, 1, t).Normalized);
vertices.Add(new float3(0, -1, -t).Normalized);
vertices.Add(new float3(0, 1, -t).Normalized);

vertices.Add(new float3(t, 0, -1));
vertices.Add(new float3(t, 0, 1));
vertices.Add(new float3(-t, 0, -1));
vertices.Add(new float3(-t, 0, 1));
vertices.Add(new float3(t, 0, -1).Normalized);
vertices.Add(new float3(t, 0, 1).Normalized);
vertices.Add(new float3(-t, 0, -1).Normalized);
vertices.Add(new float3(-t, 0, 1).Normalized);

triangles.AddRange(new int[] {
0, 11, 5,
Expand Down Expand Up @@ -136,14 +136,10 @@ private int GetMidpoint(Dictionary<long, int> midpointCache, List<float3> vertic

float3 p1 = vertices[v1];
float3 p2 = vertices[v2];
float3 middle = new float3(
(p1.x + p2.x) / 2.0f,
(p1.y + p2.y) / 2.0f,
(p1.z + p2.z) / 2.0f
);
float3 middle = (p1 + p2) / 2.0f;

midpoint = vertices.Count;
vertices.Add(middle);
vertices.Add(middle.Normalized);

midpointCache[key] = midpoint;
return midpoint;
Expand Down
4 changes: 2 additions & 2 deletions ProjectObsidian/ProtoFlux/Math/FibonacciNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ private int Fibonacci(int n)
{
if (n < 0)
{
UniLog.Log("Negative numbers are not allowed.");
return -1; // Special error value
//UniLog.Log("Negative numbers are not allowed.");
return -1;
}
if (n == 0)
return 0;
Expand Down
13 changes: 7 additions & 6 deletions ProjectObsidian/ProtoFlux/Strings/HMAC.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Security.Cryptography;
using System.Text;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.ProtoFlux;
using ProtoFlux.Core;
Expand All @@ -20,18 +21,18 @@ public enum HashFunction
[NodeCategory("Obsidian/String")]
public class HMACNode : ObjectFunctionNode<FrooxEngineContext, string>
{
public readonly ObjectInput<string> Message;
public readonly ObjectInput<string> Key;
public readonly ObjectInput<HashFunction> HashAlgorithm;
public ObjectInput<string> Message;
public ObjectInput<string> Key;
public ValueInput<HashFunction> HashAlgorithm;

protected override string Compute(FrooxEngineContext context)
{
string message = Message.Evaluate(context);
string key = Key.Evaluate(context);
string message = Message.Evaluate(context) ?? string.Empty;
string key = Key.Evaluate(context) ?? string.Empty;
HashFunction hashFunction = HashAlgorithm.Evaluate(context);

if (string.IsNullOrEmpty(message) || string.IsNullOrEmpty(key))
return "";
return string.Empty;

byte[] keyBytes = Encoding.UTF8.GetBytes(key);
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
Expand Down

0 comments on commit 34deeba

Please sign in to comment.