#Unity Dots creating entity assigning a
1 messages · Page 1 of 1 (latest)
using UnityEngine;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine.Rendering;
using Unity.Rendering;
public struct WorldVertexLayout
{
public float3 Position;
public float3 normal;
public float2 uv;
}
public unsafe class CpuWorldGen
{
private EntityManager entityManager;
public CpuWorldGen()
{
// Create a new ECS world
World world = new World("CpuWorld");
entityManager = world.EntityManager;
}
~CpuWorldGen()
{
// Dispose the world and EntityManager when the CpuWorldGen instance is destroyed
if (entityManager != null)
{
World world = entityManager.World;
world.Dispose();
}
}
float Noise(double3 position)
{
return Mathf.PerlinNoise((float)position.x, (float)position.z);
}
private const int resolution = 255;
void CreatePlane(Node* node, int3 forward, int3 right)
{
// creatuion of the buffers
Mesh mesh = new Mesh();
mesh.SetVertexBufferParams(vertices.Length,
new UnityEngine.Rendering.VertexAttributeDescriptor(UnityEngine.Rendering.VertexAttribute.Position, UnityEngine.Rendering.VertexAttributeFormat.Float32, 3),
new UnityEngine.Rendering.VertexAttributeDescriptor(UnityEngine.Rendering.VertexAttribute.Normal, UnityEngine.Rendering.VertexAttributeFormat.Float32, 3),
new UnityEngine.Rendering.VertexAttributeDescriptor(UnityEngine.Rendering.VertexAttribute.TexCoord0, UnityEngine.Rendering.VertexAttributeFormat.Float32, 2));
mesh.SetVertexBufferData(vertices.AsArray(), 0, 0, vertices.Length);
mesh.SetIndexBufferParams(indices.Length, UnityEngine.Rendering.IndexFormat.UInt16);
mesh.SetIndexBufferData(indices.AsArray(), 0, 0, indices.Length);
mesh.subMeshCount = 1;
mesh.SetSubMesh(0, new SubMeshDescriptor(0, indices.Length));
vertices.Dispose();
indices.Dispose();
//create entity, assign mesh to it and render it
}
}