mirror of
https://github.com/PashaBibko/The-Mobius-Line.git
synced 2026-04-04 09:59:04 +00:00
ghfghgfhgf
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Plexus Line Material
|
||||
m_Shader: {fileID: 4800000, guid: f92fef4e8869e674b8dbc8fb64db23cd, type: 3}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 1
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs: []
|
||||
m_Floats:
|
||||
- _Cull: 0
|
||||
m_Colors:
|
||||
- _BoxDims: {r: 5, g: 4, b: 5, a: 1}
|
||||
- _Color: {r: 0, g: 1, b: 0, a: 1}
|
||||
- _Emission1: {r: 2.56, g: 0, b: 0, a: 1}
|
||||
- _Emission2: {r: 0, g: 1.95, b: 2.52, a: 1}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 046739a9e8dbba24e8183a7a3cdfbb9a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
██████╗░██╗░░░░░███████╗██╗░░██╗██╗░░░██╗░██████╗ ██╗░░░░░██╗███╗░░██╗███████╗
|
||||
██╔══██╗██║░░░░░██╔════╝╚██╗██╔╝██║░░░██║██╔════╝ ██║░░░░░██║████╗░██║██╔════╝
|
||||
██████╔╝██║░░░░░█████╗░░░╚███╔╝░██║░░░██║╚█████╗░ ██║░░░░░██║██╔██╗██║█████╗░░
|
||||
██╔═══╝░██║░░░░░██╔══╝░░░██╔██╗░██║░░░██║░╚═══██╗ ██║░░░░░██║██║╚████║██╔══╝░░
|
||||
██║░░░░░███████╗███████╗██╔╝╚██╗╚██████╔╝██████╔╝ ███████╗██║██║░╚███║███████╗
|
||||
╚═╝░░░░░╚══════╝╚══════╝╚═╝░░╚═╝░╚═════╝░╚═════╝░ ╚══════╝╚═╝╚═╝░░╚══╝╚══════╝
|
||||
|
||||
░██████╗██╗░░██╗░█████╗░██████╗░███████╗██████╗░
|
||||
██╔════╝██║░░██║██╔══██╗██╔══██╗██╔════╝██╔══██╗
|
||||
╚█████╗░███████║███████║██║░░██║█████╗░░██████╔╝
|
||||
░╚═══██╗██╔══██║██╔══██║██║░░██║██╔══╝░░██╔══██╗
|
||||
██████╔╝██║░░██║██║░░██║██████╔╝███████╗██║░░██║
|
||||
╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚══════╝╚═╝░░╚═╝
|
||||
█▀▀▄ █──█ ▀▀█▀▀ █──█ █▀▀ ░█▀▀▄ █▀▀ ▀█─█▀ █▀▀ █── █▀▀█ █▀▀█ █▀▀ █▀▀█
|
||||
█▀▀▄ █▄▄█ ─░█── █▀▀█ █▀▀ ░█─░█ █▀▀ ─█▄█─ █▀▀ █── █──█ █──█ █▀▀ █▄▄▀
|
||||
▀▀▀─ ▄▄▄█ ─░█── ▀──▀ ▀▀▀ ░█▄▄▀ ▀▀▀ ──▀── ▀▀▀ ▀▀▀ ▀▀▀▀ █▀▀▀ ▀▀▀ ▀─▀▀
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
|
||||
▄▀█ █▀ █▀ █▀▀ ▀█▀ ▀ █░█ █░░ ▀█▀ █ █▀▄▀█ ▄▀█ ▀█▀ █▀▀ ▄█ █▀█ ▄█▄ █▀ █░█ ▄▀█ █▀▄ █▀▀ █▀█ █▀
|
||||
█▀█ ▄█ ▄█ ██▄ ░█░ ▄ █▄█ █▄▄ ░█░ █ █░▀░█ █▀█ ░█░ ██▄ ░█ █▄█ ░▀░ ▄█ █▀█ █▀█ █▄▀ ██▄ █▀▄ ▄█
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
License:
|
||||
The license is ATTRIBUTION 3.0
|
||||
|
||||
More license info here:
|
||||
https://creativecommons.org/licenses/by/3.0/
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
This shader has NOT been tested on any other PC configuration except the following:
|
||||
CPU: Intel Core i5-6400
|
||||
GPU: NVidia GTX 750Ti
|
||||
RAM: 16GB
|
||||
Windows: 10 x64
|
||||
DirectX: 11
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
Shader "Ultimate 10+ Shaders/Plexus Line"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Color ("Color", Color) = (0, 1, 0, 1)
|
||||
[HDR] _Emission1 ("Emission1", Color) = (2.56, 0, 0, 1)
|
||||
[HDR] _Emission2 ("Emission2", Color) = (0, 1.95, 2.52, 1)
|
||||
_BoxDims ("Box Dimensions", float) = (5, 5, 5, 1) // Controlled by Plexus.cs
|
||||
|
||||
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull", Float) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
Cull [_Cull]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 col : TEXCOORD0;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
fixed4 _Emission1, _Emission2;
|
||||
half4 _BoxDims;
|
||||
|
||||
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
|
||||
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
|
||||
// #pragma instancing_options assumeuniformscaling
|
||||
UNITY_INSTANCING_BUFFER_START(Props)
|
||||
// put more per-instance properties here
|
||||
UNITY_INSTANCING_BUFFER_END(Props)
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.col = fixed4((clamp(o.vertex.xyz/_BoxDims.xyz, -1, 1) + 1.0) / 2.0, 1);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 pixel;
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
pixel = _Color + lerp(_Emission1, _Emission2, i.col);
|
||||
|
||||
return pixel;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f92fef4e8869e674b8dbc8fb64db23cd
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
██████╗░██╗░░░░░███████╗██╗░░██╗██╗░░░██╗░██████╗ ░█████╗░░█████╗░███╗░░░███╗██████╗░██╗░░░██╗████████╗███████╗
|
||||
██╔══██╗██║░░░░░██╔════╝╚██╗██╔╝██║░░░██║██╔════╝ ██╔══██╗██╔══██╗████╗░████║██╔══██╗██║░░░██║╚══██╔══╝██╔════╝
|
||||
██████╔╝██║░░░░░█████╗░░░╚███╔╝░██║░░░██║╚█████╗░ ██║░░╚═╝██║░░██║██╔████╔██║██████╔╝██║░░░██║░░░██║░░░█████╗░░
|
||||
██╔═══╝░██║░░░░░██╔══╝░░░██╔██╗░██║░░░██║░╚═══██╗ ██║░░██╗██║░░██║██║╚██╔╝██║██╔═══╝░██║░░░██║░░░██║░░░██╔══╝░░
|
||||
██║░░░░░███████╗███████╗██╔╝╚██╗╚██████╔╝██████╔╝ ╚█████╔╝╚█████╔╝██║░╚═╝░██║██║░░░░░╚██████╔╝░░░██║░░░███████╗
|
||||
╚═╝░░░░░╚══════╝╚══════╝╚═╝░░╚═╝░╚═════╝░╚═════╝░ ░╚════╝░░╚════╝░╚═╝░░░░░╚═╝╚═╝░░░░░░╚═════╝░░░░╚═╝░░░╚══════╝
|
||||
|
||||
░██████╗██╗░░██╗░█████╗░██████╗░███████╗██████╗░
|
||||
██╔════╝██║░░██║██╔══██╗██╔══██╗██╔════╝██╔══██╗
|
||||
╚█████╗░███████║███████║██║░░██║█████╗░░██████╔╝
|
||||
░╚═══██╗██╔══██║██╔══██║██║░░██║██╔══╝░░██╔══██╗
|
||||
██████╔╝██║░░██║██║░░██║██████╔╝███████╗██║░░██║
|
||||
╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚══════╝╚═╝░░╚═╝
|
||||
█▀▀▄ █──█ ▀▀█▀▀ █──█ █▀▀ ░█▀▀▄ █▀▀ ▀█─█▀ █▀▀ █── █▀▀█ █▀▀█ █▀▀ █▀▀█
|
||||
█▀▀▄ █▄▄█ ─░█── █▀▀█ █▀▀ ░█─░█ █▀▀ ─█▄█─ █▀▀ █── █──█ █──█ █▀▀ █▄▄▀
|
||||
▀▀▀─ ▄▄▄█ ─░█── ▀──▀ ▀▀▀ ░█▄▄▀ ▀▀▀ ──▀── ▀▀▀ ▀▀▀ ▀▀▀▀ █▀▀▀ ▀▀▀ ▀─▀▀
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
|
||||
▄▀█ █▀ █▀ █▀▀ ▀█▀ ▀ █░█ █░░ ▀█▀ █ █▀▄▀█ ▄▀█ ▀█▀ █▀▀ ▄█ █▀█ ▄█▄ █▀ █░█ ▄▀█ █▀▄ █▀▀ █▀█ █▀
|
||||
█▀█ ▄█ ▄█ ██▄ ░█░ ▄ █▄█ █▄▄ ░█░ █ █░▀░█ █▀█ ░█░ ██▄ ░█ █▄█ ░▀░ ▄█ █▀█ █▀█ █▄▀ ██▄ █▀▄ ▄█
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
License:
|
||||
The license is ATTRIBUTION 3.0
|
||||
|
||||
More license info here:
|
||||
https://creativecommons.org/licenses/by/3.0/
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
This shader has NOT been tested on any other PC configuration except the following:
|
||||
CPU: Intel Core i5-6400
|
||||
GPU: NVidia GTX 750Ti
|
||||
RAM: 16GB
|
||||
Windows: 10 x64
|
||||
DirectX: 11
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#pragma kernel MoveParticels
|
||||
|
||||
RWStructuredBuffer<float3> positions;
|
||||
RWStructuredBuffer<float3> defaultPositions;
|
||||
RWStructuredBuffer<float3> velocities;
|
||||
|
||||
float deltaTime;
|
||||
float elapsedTime;
|
||||
float particleSpeed;
|
||||
|
||||
// really rounded
|
||||
#define PI 3.14
|
||||
#define PI_M_2 6.28
|
||||
#define PI_D_2 1.57
|
||||
|
||||
// Sine from Taylor series
|
||||
half ta_sin(half theta) {
|
||||
half a = theta + PI_D_2;
|
||||
theta = ((a>0) ? a - PI_M_2*((int)(a / PI_M_2)) : (-a + PI_M_2*((int)(a / PI_M_2)))) - PI_D_2;
|
||||
|
||||
if (theta > PI_D_2)
|
||||
theta = PI - theta;
|
||||
|
||||
half x3 = theta * theta * theta;
|
||||
|
||||
return theta - (x3 / 6.0) + (x3 * theta * theta) / 120.0;
|
||||
}
|
||||
|
||||
half ta_cos(half theta) {
|
||||
return ta_sin(90.0 - theta);
|
||||
}
|
||||
|
||||
float distSqr(half3 p1, half3 p2)
|
||||
{
|
||||
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z);
|
||||
}
|
||||
|
||||
half3 randomMovement(uint3 id) {
|
||||
return
|
||||
half3(frac(sin(id.x + ta_sin(id.x + ta_cos(elapsedTime))) * particleSpeed) - .5,
|
||||
frac(cos(id.x + ta_sin(id.x + ta_sin(elapsedTime))) * particleSpeed) - .5,
|
||||
frac(sin(id.x + ta_sin(id.x) * ta_cos(elapsedTime)) * particleSpeed) - .5
|
||||
);
|
||||
}
|
||||
|
||||
[numthreads(1,1,1)]
|
||||
void MoveParticels(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
// id.x
|
||||
|
||||
velocities[id.x] += randomMovement(id.x) * .1;
|
||||
velocities[id.x] += (defaultPositions[id.x] - positions[id.x]) * distSqr(positions[id.x], defaultPositions[id.x]) * .1;
|
||||
|
||||
velocities[id.x] = normalize(velocities[id.x]);
|
||||
|
||||
positions[id.x] += velocities[id.x] * particleSpeed * deltaTime;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0396ae06a645dc94696336944bc11f1f
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
currentAPIMask: 4
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
237
Assets/Ultimate 10 Plus Shaders/Shaders/Plexus/Plexus.cs
Normal file
237
Assets/Ultimate 10 Plus Shaders/Shaders/Plexus/Plexus.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
██████╗░██╗░░░░░███████╗██╗░░██╗██╗░░░██╗░██████╗
|
||||
██╔══██╗██║░░░░░██╔════╝╚██╗██╔╝██║░░░██║██╔════╝
|
||||
██████╔╝██║░░░░░█████╗░░░╚███╔╝░██║░░░██║╚█████╗░
|
||||
██╔═══╝░██║░░░░░██╔══╝░░░██╔██╗░██║░░░██║░╚═══██╗
|
||||
██║░░░░░███████╗███████╗██╔╝╚██╗╚██████╔╝██████╔╝
|
||||
╚═╝░░░░░╚══════╝╚══════╝╚═╝░░╚═╝░╚═════╝░╚═════╝░
|
||||
|
||||
█▀▀▄ █──█ ▀▀█▀▀ █──█ █▀▀ ░█▀▀▄ █▀▀ ▀█─█▀ █▀▀ █── █▀▀█ █▀▀█ █▀▀ █▀▀█
|
||||
█▀▀▄ █▄▄█ ─░█── █▀▀█ █▀▀ ░█─░█ █▀▀ ─█▄█─ █▀▀ █── █──█ █──█ █▀▀ █▄▄▀
|
||||
▀▀▀─ ▄▄▄█ ─░█── ▀──▀ ▀▀▀ ░█▄▄▀ ▀▀▀ ──▀── ▀▀▀ ▀▀▀ ▀▀▀▀ █▀▀▀ ▀▀▀ ▀─▀▀
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
|
||||
▄▀█ █▀ █▀ █▀▀ ▀█▀ ▀ █░█ █░░ ▀█▀ █ █▀▄▀█ ▄▀█ ▀█▀ █▀▀ ▄█ █▀█ ▄█▄ █▀ █░█ ▄▀█ █▀▄ █▀▀ █▀█ █▀
|
||||
█▀█ ▄█ ▄█ ██▄ ░█░ ▄ █▄█ █▄▄ ░█░ █ █░▀░█ █▀█ ░█░ ██▄ ░█ █▄█ ░▀░ ▄█ █▀█ █▀█ █▄▀ ██▄ █▀▄ ▄█
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
License:
|
||||
The license is ATTRIBUTION 3.0
|
||||
|
||||
More license info here:
|
||||
https://creativecommons.org/licenses/by/3.0/
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
This shader has NOT been tested on any other PC configuration except the following:
|
||||
CPU: Intel Core i5-6400
|
||||
GPU: NVidia GTX 750Ti
|
||||
RAM: 16GB
|
||||
Windows: 10 x64
|
||||
DirectX: 11
|
||||
____________________________________________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//[ExecuteAlways]
|
||||
public class Plexus : MonoBehaviour
|
||||
{
|
||||
public ComputeShader plexus;
|
||||
|
||||
public int amountOfPoints = 100;
|
||||
public int PPPS = 2; // Processed Points Per Second
|
||||
public float lineWidth = 0.02f;
|
||||
public Material lineMaterial;
|
||||
|
||||
public Vector3 box = new Vector3(4, 4, 4);
|
||||
|
||||
public float particleSpeed = 1.0f;
|
||||
public float maxConnDistance = 3.0f; // The maximum distance for two points to connect
|
||||
private float maxConnDistanceSqr;
|
||||
|
||||
private Vector3[] defaultPositions;
|
||||
private Vector3[] velocities;
|
||||
private Vector3[] positions;
|
||||
|
||||
private Mesh lineMesh;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
lineMaterial.SetVector("_BoxDims", new Vector4(box.x, box.y, box.z, 1));
|
||||
|
||||
positions = new Vector3[amountOfPoints];
|
||||
defaultPositions = new Vector3[amountOfPoints];
|
||||
for (int i = 0; i < amountOfPoints; ++i)
|
||||
{
|
||||
positions[i] = new Vector3(
|
||||
Random.Range(-box.x, box.x),
|
||||
Random.Range(-box.y, box.y),
|
||||
Random.Range(-box.z, box.z));
|
||||
|
||||
defaultPositions[i] = positions[i];
|
||||
}
|
||||
|
||||
lineMesh = new Mesh();
|
||||
|
||||
int[] trigs = new int[6];
|
||||
|
||||
trigs[0] = 0;
|
||||
trigs[1] = 1;
|
||||
trigs[2] = 2;
|
||||
|
||||
trigs[3] = 3;
|
||||
trigs[4] = 2;
|
||||
trigs[5] = 1;
|
||||
|
||||
lineMesh.vertices = verts;
|
||||
lineMesh.triangles = trigs;
|
||||
|
||||
velocities = new Vector3[amountOfPoints];
|
||||
StartCoroutine(ConnectDots());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
MovePoints();
|
||||
RenderLines();
|
||||
}
|
||||
|
||||
private void MovePoints()
|
||||
{
|
||||
int kernelIndex = plexus.FindKernel("MoveParticels");
|
||||
|
||||
// sizeof(float3) == 12
|
||||
ComputeBuffer positionsBuffer = new ComputeBuffer(positions.Length, 12);
|
||||
positionsBuffer.SetData(positions);
|
||||
plexus.SetBuffer(kernelIndex, "positions", positionsBuffer);
|
||||
|
||||
// sizeof(float3) == 12
|
||||
ComputeBuffer defaultPositionsBuffer = new ComputeBuffer(defaultPositions.Length, 12);
|
||||
defaultPositionsBuffer.SetData(defaultPositions);
|
||||
plexus.SetBuffer(kernelIndex, "defaultPositions", defaultPositionsBuffer);
|
||||
|
||||
// sizeof(float3) == 12
|
||||
ComputeBuffer velocitiesBuffer = new ComputeBuffer(velocities.Length, 12);
|
||||
velocitiesBuffer.SetData(velocities);
|
||||
plexus.SetBuffer(kernelIndex, "velocities", velocitiesBuffer);
|
||||
|
||||
|
||||
plexus.SetFloat("deltaTime", Time.deltaTime);
|
||||
plexus.SetFloat("elapsedTime", Time.time);
|
||||
plexus.SetFloat("particleSpeed", particleSpeed);
|
||||
|
||||
plexus.Dispatch(kernelIndex, positions.Length, 1, 1);
|
||||
|
||||
positionsBuffer.GetData(positions);
|
||||
|
||||
positionsBuffer.Release();
|
||||
defaultPositionsBuffer.Release();
|
||||
velocitiesBuffer.Release();
|
||||
}
|
||||
|
||||
private static float DistanceSqr(Vector3 p1, Vector3 p2)
|
||||
{
|
||||
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z);
|
||||
}
|
||||
|
||||
Vector3 normal, side, p1, p2;
|
||||
int startingVerticesIndex = 0;
|
||||
List<int> lineTrigs = new List<int>();
|
||||
List<Vector3> lineVerts = new List<Vector3>();
|
||||
Vector3[] verts = new Vector3[4];
|
||||
int[] trigs = new int[6];
|
||||
private void RenderLines()
|
||||
{
|
||||
lineMesh = new Mesh();
|
||||
for (int i = 0; i < connected.Count; ++i)
|
||||
{
|
||||
// DrawLine(positions[connected[i].Key], positions[connected[i].Value]);
|
||||
//transform.position - positions[connected[i].Key], // local to world space
|
||||
//transform.position - positions[connected[i].Value]); // local to world space
|
||||
|
||||
p1 = positions[connected[i].Key];
|
||||
p2 = positions[connected[i].Value];
|
||||
|
||||
normal = Vector3.Cross(p1, p2);
|
||||
side = Vector3.Cross(normal, p2 - p1);
|
||||
side.Normalize();
|
||||
|
||||
|
||||
startingVerticesIndex = lineVerts.Count;
|
||||
|
||||
|
||||
verts[0] = p1 + side * (lineWidth / 2);
|
||||
verts[1] = p1 + side * (lineWidth / -2);
|
||||
verts[2] = p2 + side * (lineWidth / 2);
|
||||
verts[3] = p2 + side * (lineWidth / -2);
|
||||
|
||||
|
||||
trigs[0] = startingVerticesIndex;
|
||||
trigs[1] = trigs[5] = startingVerticesIndex + 1;
|
||||
trigs[2] = trigs[4] = startingVerticesIndex + 2;
|
||||
trigs[3] = startingVerticesIndex + 3;
|
||||
|
||||
|
||||
lineVerts.AddRange(verts);
|
||||
lineTrigs.AddRange(trigs);
|
||||
}
|
||||
|
||||
lineMesh.vertices = lineVerts.ToArray();
|
||||
lineMesh.triangles = lineTrigs.ToArray();
|
||||
|
||||
// Drawing the mesh
|
||||
lineMesh.RecalculateBounds();
|
||||
Graphics.DrawMesh(lineMesh, transform.localToWorldMatrix, lineMaterial, 0);
|
||||
|
||||
// Emptying the memory
|
||||
lineTrigs.Clear();
|
||||
lineVerts.Clear();
|
||||
}
|
||||
|
||||
[HideInInspector]
|
||||
public bool isEnabled = false;
|
||||
List<KeyValuePair<int, int>> connected = new List<KeyValuePair<int, int>>();
|
||||
HashSet<KeyValuePair<int, int>> connectedHashSet = new HashSet<KeyValuePair<int, int>>();
|
||||
|
||||
private IEnumerator ConnectDots()
|
||||
{
|
||||
// the idea behind this code is to extend the connection of dots in time
|
||||
// not to do it each frame for all points but instead of doing it each frame for
|
||||
// N points
|
||||
|
||||
WaitForEndOfFrame wfeof = new WaitForEndOfFrame();
|
||||
int indx = 0, i = 0, j = 0;
|
||||
Vector3 currentPos;
|
||||
|
||||
maxConnDistanceSqr = maxConnDistance * maxConnDistance;
|
||||
|
||||
do
|
||||
{
|
||||
yield return wfeof;
|
||||
for (j = 0; j < PPPS; ++j)
|
||||
{
|
||||
currentPos = positions[indx];
|
||||
|
||||
connected.RemoveAll(x => x.Key == indx || x.Value == indx);
|
||||
connectedHashSet.RemoveWhere(x => x.Key == indx || x.Value == indx);
|
||||
|
||||
for (i = 0; i < amountOfPoints; ++i)
|
||||
{
|
||||
if (i == indx)
|
||||
continue;
|
||||
|
||||
if (DistanceSqr(currentPos, positions[i]) < maxConnDistanceSqr)
|
||||
{
|
||||
KeyValuePair<int, int> k = new KeyValuePair<int, int>(indx, i);
|
||||
if(connectedHashSet.Add(k))
|
||||
connected.Add(new KeyValuePair<int, int>(indx, i));
|
||||
}
|
||||
}
|
||||
|
||||
++indx;
|
||||
if (indx >= amountOfPoints)
|
||||
indx = 0;
|
||||
}
|
||||
} while (!isEnabled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66bd5c73cd1c467458a55f95ff648743
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user