Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge into my branch #43

Merged
merged 52 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b626d5a
Merge pull request #30 from Xlinka/frozenreflex
Xlinka May 1, 2024
2ea3ad0
Update IsUserInSeatedMode.cs
Xlinka May 1, 2024
82e6bcf
performance thing that froox does all the time
art0007i May 3, 2024
f429843
Merge pull request #31 from art0007i/main
Xlinka May 3, 2024
f8e497b
refactor and imunode based on component
Xlinka May 4, 2024
dcf5e3e
Delete CreateEmptySlot.cs
Xlinka May 8, 2024
a5c335b
Create Factorial Node Reference #1688
Xlinka Jun 25, 2024
047d1f1
Eulerstoient node and IsPrimeNumber
Xlinka Jun 25, 2024
9ee49fe
Create FibonacciNode.cs
Xlinka Jun 25, 2024
95ace26
Create AsyncHttpRequestNode.cs
Xlinka Jun 25, 2024
bb283a0
Planet Procedural Mesh Generator
Xlinka Jun 25, 2024
c2fd29d
fixes
Xlinka Jun 26, 2024
b85b400
fix fib
Xlinka Jun 26, 2024
34deeba
fix hmac and normals for planet mesh generation
Xlinka Jun 26, 2024
d209609
Add ComponentsDataFeed and ComponentDataItemInterface
Nytra Jun 27, 2024
e52006b
Merge branch 'Xlinka:main' into main
Nytra Jun 27, 2024
2282548
Throw if component data already existed for that component
Nytra Jun 27, 2024
6f82e7a
Merge branch 'main' of https://github.com/Nytra/Project-Obsidian
Nytra Jun 27, 2024
70992da
code uploads
paradoxical-autumn Jun 27, 2024
f747cf8
my silly stuff works now :D
paradoxical-autumn Jun 27, 2024
8cad7c5
Update ProjectObsidian/ProtoFlux/Users/UserFromUserRef.cs
paradoxical-autumn Jun 27, 2024
75cf56c
mvp
paradoxical-autumn Jun 27, 2024
ff19e61
While nodes with iteration
paradoxical-autumn Jun 27, 2024
f583ecc
oops i started indexing at 1 LMAO
paradoxical-autumn Jun 27, 2024
400e755
Filter out local elements
Nytra Jun 27, 2024
c295ef4
Add comment
Nytra Jun 27, 2024
1f4adea
Fix arithmetic driver generic types group
Nytra Jun 27, 2024
1437c0e
Merge pull request #35 from Nytra/FixArithmeticDriver
Xlinka Jun 28, 2024
5b15c61
Merge pull request #34 from Nytra/main
Xlinka Jun 28, 2024
8cfe19b
Merge branch 'Xlinka:main' into main
paradoxical-autumn Jun 28, 2024
ab4e6c9
Make component data feed able to enumerate types from the component a…
Nytra Jun 28, 2024
d16571c
Add category items
Nytra Jun 28, 2024
4192136
Add ButtonAttachComponent, rename some stuff, add comments
Nytra Jul 1, 2024
51fb4ee
Merge pull request #36 from Nytra/main
Xlinka Jul 1, 2024
2432189
Merge branch 'main' into main
Xlinka Jul 1, 2024
fb8fe73
Merge pull request #32 from paradoxical-autumn/main
Xlinka Jul 1, 2024
410076d
Call base.OnAttach in OnAttach, use full typename in logs instead of …
Nytra Jul 2, 2024
ddf172b
Merge pull request #37 from Nytra/main
Xlinka Jul 2, 2024
5b6102e
Create AsyncWait.cs
Xlinka Jul 2, 2024
9c111fe
fix asyncawait and add ispaused and isstopped
Xlinka Jul 2, 2024
c83ed60
gonna slip this in
Xlinka Jul 2, 2024
cfb9ef5
Update Injection.cs
Xlinka Jul 2, 2024
8217491
Update ProjectObsidian.csproj
Xlinka Jul 2, 2024
538e480
Create ObsidianTestShader.shader
Xlinka Jul 2, 2024
640439b
Add TypeFeedItem and TypeItemInterface, and rework components feed to…
Nytra Jul 2, 2024
141eaa3
fix crashing
paradoxical-autumn Jul 3, 2024
5f74d34
Merge pull request #39 from paradoxical-autumn/main
Xlinka Jul 3, 2024
8d842fb
Merge branch 'Xlinka:main' into main
Nytra Jul 11, 2024
36c4005
Change OnAwake to OnStart, add IsValidGenericTypeDriver and StringToT…
Nytra Jul 11, 2024
09f5737
Merge pull request #40 from Nytra/main
Xlinka Jul 11, 2024
84d16df
Update for Type Management
Nytra Jul 12, 2024
54fc756
Merge pull request #41 from Nytra/main
Xlinka Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using FrooxEngine;
using FrooxEngine.Undo;

namespace Obsidian;

[Category(new string[] { "Obsidian/Common UI/Button Interactions" })]
public class ButtonAttachComponent : Component, IButtonPressReceiver, IComponent, IComponentBase, IDestroyable, IWorker, IWorldElement, IUpdatable, IChangeable, IAudioUpdatable, IInitializable, ILinkable
{
public readonly SyncRef<Slot> TargetSlot;

public readonly SyncType ComponentType;

public readonly Sync<bool> Undoable;

protected override void OnAttach()
{
base.OnAttach();
Undoable.Value = true;
}

public void Pressed(IButton button, ButtonEventData eventData)
{
Slot target = TargetSlot.Target;
Type componentType = ComponentType.Value;
if (target != null && componentType != null && componentType.ContainsGenericParameters == false)
{
var comp = target.AttachComponent(componentType);
if (Undoable)
{
comp.CreateSpawnUndoPoint();
}
}
}

public void Pressing(IButton button, ButtonEventData eventData)
{
}

public void Released(IButton button, ButtonEventData eventData)
{
}
}
165 changes: 165 additions & 0 deletions ProjectObsidian/Components/Mesh/Planet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using Elements.Assets;
using Elements.Core;
using System;
using System.Collections.Generic;

namespace Obsidian
{
public class Planet : MeshXShape
{
public int Subdivisions;
public float Radius;
public float NoiseScale;
public float NoiseStrength;

public Planet(MeshX mesh, int subdivisions, float radius, float noiseScale, float noiseStrength) : base(mesh)
{
Subdivisions = subdivisions;
Radius = radius;
NoiseScale = noiseScale;
NoiseStrength = noiseStrength;
mesh.Clear();
GeneratePlanet(mesh, Subdivisions, Radius, NoiseScale, NoiseStrength);
}

private void GeneratePlanet(MeshX mesh, int subdivisions, float radius, float noiseScale, float noiseStrength)
{
List<float3> vertices = new List<float3>();
List<int> triangles = new List<int>();

// Generate initial icosahedron
CreateIcosahedron(vertices, triangles);

// Subdivide icosahedron
for (int i = 0; i < subdivisions; i++)
{
Subdivide(vertices, triangles);
}

// Apply noise to vertices
ApplyPerlinNoise(vertices, radius, noiseScale, noiseStrength);

// 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]);
}

}

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).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).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).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,
0, 5, 1,
0, 1, 7,
0, 7, 10,
0, 10, 11,

1, 5, 9,
5, 11, 4,
11, 10, 2,
10, 7, 6,
7, 1, 8,

3, 9, 4,
3, 4, 2,
3, 2, 6,
3, 6, 8,
3, 8, 9,

4, 9, 5,
2, 4, 11,
6, 2, 10,
8, 6, 7,
9, 8, 1
});
}

private void Subdivide(List<float3> vertices, List<int> triangles)
{
Dictionary<long, int> midpointCache = new Dictionary<long, int>();
List<int> newTriangles = new List<int>();

for (int i = 0; i < triangles.Count; i += 3)
{
int v1 = triangles[i];
int v2 = triangles[i + 1];
int v3 = triangles[i + 2];

int a = GetMidpoint(midpointCache, vertices, v1, v2);
int b = GetMidpoint(midpointCache, vertices, v2, v3);
int c = GetMidpoint(midpointCache, vertices, v3, v1);

newTriangles.AddRange(new int[] { v1, a, c });
newTriangles.AddRange(new int[] { v2, b, a });
newTriangles.AddRange(new int[] { v3, c, b });
newTriangles.AddRange(new int[] { a, b, c });
}

triangles.Clear();
triangles.AddRange(newTriangles);
}

private int GetMidpoint(Dictionary<long, int> midpointCache, List<float3> vertices, int v1, int v2)
{
long key = ((long)Math.Min(v1, v2) << 32) + Math.Max(v1, v2);

if (midpointCache.TryGetValue(key, out int midpoint))
{
return midpoint;
}

float3 p1 = vertices[v1];
float3 p2 = vertices[v2];
float3 middle = (p1 + p2) / 2.0f;

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

midpointCache[key] = midpoint;
return midpoint;
}

private void ApplyPerlinNoise(List<float3> vertices, float radius, float noiseScale, float noiseStrength)
{
for (int i = 0; i < vertices.Count; i++)
{
float3 vertex = vertices[i];
float noise = NodeExtensions.PerlinNoise(vertex.x * noiseScale, vertex.y * noiseScale, vertex.z * noiseScale);
float displacement = radius + noise * noiseStrength;
vertices[i] = vertex.Normalized * displacement;
}
}

public override void Update()
{
Mesh.RecalculateNormals(AllTriangles);
Mesh.RecalculateTangents(AllTriangles);
}
}
}
62 changes: 62 additions & 0 deletions ProjectObsidian/Components/Mesh/PlanetMesh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Elements.Assets;
using Elements.Core;
using FrooxEngine;
using System;

namespace Obsidian
{
[Category(new string[] { "Obsidian/Assets/Procedural Meshes" })]
public class PlanetMesh : ProceduralMesh
{
[Range(1, 8)] public readonly Sync<int> Subdivisions;
[Range(0.5f, 10.0f)] public readonly Sync<float> Radius;
[Range(0.1f, 10.0f)] public readonly Sync<float> NoiseScale;
[Range(0.0f, 2.0f)] public readonly Sync<float> NoiseStrength;

private Planet planet;
private int _subdivisions;
private float _radius;
private float _noiseScale;
private float _noiseStrength;

protected override void OnAwake()
{
base.OnAwake();
Subdivisions.Value = 4;
Radius.Value = 1.0f;
NoiseScale.Value = 1.0f;
NoiseStrength.Value = 0.5f;
}

protected override void PrepareAssetUpdateData()
{
_subdivisions = Subdivisions.Value;
_radius = Radius.Value;
_noiseScale = NoiseScale.Value;
_noiseStrength = NoiseStrength.Value;
}

protected override void ClearMeshData()
{
planet = null;
}

protected override void UpdateMeshData(MeshX meshx)
{
bool value = false;
if (planet == null || planet.Subdivisions != _subdivisions || planet.Radius != _radius || planet.NoiseScale != _noiseScale || planet.NoiseStrength != _noiseStrength)
{
planet?.Remove();
planet = new Planet(meshx, _subdivisions, _radius, _noiseScale, _noiseStrength);
value = true;
}

planet.Subdivisions = Subdivisions.Value;
planet.Radius = Radius.Value;
planet.NoiseScale = NoiseScale.Value;
planet.NoiseStrength = NoiseStrength.Value;
planet.Update();
uploadHint[MeshUploadHint.Flag.Geometry] = value;
}
}
}
Loading