/*public void ApplyBones(ref ChunkMesh chunkMesh, ref ChunkMeshAnimation chunkMeshAnimation, int vertsCount, Skeleton skeleton) * { * //float3[] originalBonePositions = new float3[skeleton.boneIndexes.Length]; * float3[] bonePositions = new float3[skeleton.bones.Length]; * quaternion[] boneRotations = new quaternion[skeleton.bones.Length]; * for (int i = 0; i < skeleton.bones.Length; i++) * { * var boneEntity = skeleton.bones[i]; * //originalBonePositions[i] = World.EntityManager.GetComponentData<Bone>(boneEntity).position; * //bonePositions[i] = World.EntityManager.GetComponentData<Translation>(boneEntity).Value; * boneRotations[i] = World.EntityManager.GetComponentData<Rotation>(boneEntity).Value; * bonePositions[i] = World.EntityManager.GetComponentData<Translation>(boneEntity).Value - World.EntityManager.GetComponentData<Bone>(boneEntity).position; * //Debug.LogError(i + " - Bone Position: " + bonePositions[i]); * } * //NativeArray<ZoxelVertex> outputVerts = new NativeArray<ZoxelVertex>(verts.Length, Allocator.Temp); * var verticesA = chunkMesh.vertices.ToArray(); * var boneIndexes = skeleton.boneIndexes.ToArray(); * float timeBegun = UnityEngine.Time.realtimeSinceStartup; * for (int i = 0; i < vertsCount; i++) * { * // get bone difference of position * //var boneEntity = skeleton.bones[boneIndex]; * //var bone = World.EntityManager.GetComponentData<Bone>(boneEntity); * // get difference of positions * //float3 bonePosition = bonePositions[boneIndex]; // World.EntityManager.GetComponentData<Translation>(boneEntity).Value; * //Matrix4x4 boneMatrix = World.EntityManager.GetComponentData<LocalToWorld>(boneEntity).Value; * //Vector3 bonePositionV = boneMatrix.GetColumn(3); * //float3 bonePosition = bonePositionV; * //var difference = bonePosition - originalBonePositions[boneIndex]; * var vert = verticesA[i]; * //var vert = new ZoxelVertex { * // position = new float3(verto.position.x, verto.position.y, verto.position.z), * // uv = verto.uv, * // color = verto.color * //}; * var position = vert.position; * int bonesCount = skeleton.bones.Length;//math.min(skeleton.bones.Length, 3); * int boneIndex = boneIndexes[i]; * quaternion boneRotation = boneRotations[boneIndex]; // World.EntityManager.GetComponentData<Rotation>(boneEntity).Value; * position += bonePositions[boneIndex]; * //vert.position = math.rotate(boneRotation, position); * vert.position = position; * if (Bootstrap.instance.isDebugWeightColours) * { * var color = vert.color; * color = weightColours[boneIndex]; * vert.color = color; * } * chunkMeshAnimation.vertices[i] = vert; * } * float timeEnded = UnityEngine.Time.realtimeSinceStartup; * Debug.LogError("Time taking to process verts: " + vertsCount + ":" + 1000 * (timeEnded - timeBegun) + "ms"); * }*/ public NativeArray <ZoxelVertex> ApplySimplexNoise(NativeArray <ZoxelVertex> verts) { float noiseAmplitude = 0.02f; float noiseValue = 0.5f; NativeArray <ZoxelVertex> outputVerts = new NativeArray <ZoxelVertex>(verts.Length, Allocator.Temp); for (int i = 0; i < verts.Length; i++) { var verto = verts[i]; var vert = new ZoxelVertex { position = new float3(verto.position.x, verto.position.y, verto.position.z), uv = verto.uv, color = verto.color }; var position = vert.position; // applies 3600 verts - this mathematics var time = UnityEngine.Time.time; float noiseA = noise.snoise(new float3(position.x, position.y + time, position.z - time) * noiseValue); //float noiseX = noise.snoise(new float2(position.x, UnityEngine.Time.time) * noiseValue); //float noiseY = noise.snoise(new float2(position.y, UnityEngine.Time.time) * noiseValue); //float noiseZ = noise.snoise(new float2(position.z, UnityEngine.Time.time) * noiseValue); position += noiseAmplitude * (new float3(noiseA, noiseA, noiseA)); vert.position = position; outputVerts[i] = vert; } return(outputVerts); }
public NativeArray <ZoxelVertex> ApplyRandomNoise(NativeArray <ZoxelVertex> verts) { float noiseAmplitude = 0.02f; float noiseValue = 0.5f; NativeArray <ZoxelVertex> outputVerts = new NativeArray <ZoxelVertex>(verts.Length, Allocator.Temp); for (int i = 0; i < verts.Length; i++) { var verto = verts[i]; var vert = new ZoxelVertex { position = new float3(verto.position.x, verto.position.y, verto.position.z), uv = verto.uv, color = verto.color }; var position = vert.position; position += noiseAmplitude * (new float3( UnityEngine.Random.Range(-1, 1), UnityEngine.Random.Range(-1, 1), UnityEngine.Random.Range(-1, 1))); vert.position = position; outputVerts[i] = vert; } return(outputVerts); }