This commit is contained in:
2025-05-13 03:19:28 +03:00
parent e2847b060d
commit 762dcf4524
784 changed files with 542617 additions and 2 deletions
+9
View File
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f6450f5cd845be54a9c2e94ced271b8a
folderAsset: yes
timeCreated: 1454099509
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,19 @@
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(Plot3D))]
public class Plot3DEditor : Editor
{
public override void OnInspectorGUI()
{
var plot = (Plot3D) target;
base.OnInspectorGUI();
if(GUILayout.Button("Rebuild"))
{
plot.UpdateMesh();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cadea4c4d596d36478f93d5465e7e5f1
timeCreated: 1454099501
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
public class OscilloscopeAdapter : MonoBehaviour
{
public Plot2D plot;
public uint channel;
public uint samplesCount = 500;
// Use this for initialization
private void Awake() {
if (plot != null) {
plot.channels[0].ResizeBuffers((int)samplesCount);
}
}
// Update is called once per frame
void Update () {
}
public void PushSample(float x, float y)
{
plot.channels[channel].PushSample(x, y);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 44cc266d60292df4580478196f3ee773
timeCreated: 1454229132
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
using UnityEngine;
using System.Collections;
public class OscilloscopeFunctionSampler : MonoBehaviour
{
public OscilloscopeAdapter oscilloscope;
public Plot2DFunction function;
public bool fixedUpdate;
public bool update;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (update) {
if (oscilloscope != null && function != null) {
oscilloscope.PushSample(Time.time, function.f(Time.time));
}
}
}
void FixedUpdate()
{
if (fixedUpdate)
{
if (oscilloscope != null && function != null)
{
oscilloscope.PushSample(Time.time, function.f(Time.time));
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8fe052c51e1e16d40917a55b482a07fa
timeCreated: 1454229407
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+43
View File
@@ -0,0 +1,43 @@
Shader "Custom/Plot2" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows alpha:blend
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 4.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0f09a546a0c0f34469076b367e9e2e85
timeCreated: 1454540251
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections;
public class Plot2DFunction : MonoBehaviour {
public virtual float f(float x)
{
return Mathf.Sin(Time.realtimeSinceStartup);
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d69fb25fdb71fd4449b961325c9dcd41
timeCreated: 1454229266
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+294
View File
@@ -0,0 +1,294 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections;
using System;
[Serializable]
public struct UInt3 {
public uint x;
public uint y;
public uint z;
}
[Serializable]
public class AxisSuffix3D
{
public string X;
public string Y;
public string Z;
public string this[int index] {
get {
if (index == 0) {
return X;
}
if (index == 1) {
return Y;
} else {
return Z;
}
}
}
}
[Serializable]
public class Plot3DSurface {
public string Title;
public AxisSuffix3D Suffix;
public bool Visible = true;
public Vector3 axisBegin = Vector3.zero;
public Vector3 axisEnd = Vector3.one;
public Plot3DFunction function;
}
public class Plot3D : MonoBehaviour {
public UInt3 sectionsCount = new UInt3() { x = 10, y = 10, z = 10 };
public Mesh plotMesh;
public int tessArg0 = 10;
public int tessArg1 = 10;
public Plot3DSurface[] surfaces;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
private void ValidateView() {
var mr = GetComponent<MeshRenderer>();
if (mr == null) {
mr = gameObject.AddComponent<MeshRenderer>();
}
var mf = GetComponent<MeshFilter>();
if (mf == null) {
mf = gameObject.AddComponent<MeshFilter>();
}
}
public void UpdateMesh() {
ValidateView();
if (tessArg0 < 1) {
tessArg0 = 1;
}
if (tessArg1 < 1) {
tessArg1 = 1;
}
if (plotMesh == null) {
plotMesh = new Mesh();
}
//build vertices
var surfaceVertexCount = (tessArg0 + 1) * (tessArg1 + 1);
Vector3[] vertices = new Vector3[surfaceVertexCount * surfaces.Length];
var ptsX = tessArg0 + 1;
var ptsZ = tessArg1 + 1;
for (int z = 0; z < ptsZ; ++z) {
for (int x = 0; x < ptsX; ++x) {
float u = (1.0f / (ptsX - 1)) * x;
float v = (1.0f / (ptsZ - 1)) * z;
//for each surface generate vertex
for (int i = 0; i < surfaces.Length; ++i) {
float y = 0;
var surf = surfaces[i];
if (surf.Visible) {
var function = surf.function;
if (function != null) {
y = function.f(Mathf.Lerp(surf.axisBegin[0], surf.axisEnd[0], u), Mathf.Lerp(surf.axisBegin[2], surf.axisEnd[2], v));
if (surf.axisEnd[1] - surf.axisBegin[1] < 0.000001f) {
y = 0;
} else {
y = (y - surf.axisBegin[1]) / (surf.axisEnd[1] - surf.axisBegin[1]);
}
}
vertices[z * ptsX + x + surfaceVertexCount * i] = new Vector3(u, y, v);
} else {
vertices[z * ptsX + x + surfaceVertexCount * i] = Vector3.zero;
}
}
}
}
//build indices
int[] indices_source = new int[tessArg0 * tessArg1 * 6];
int index_id = 0;
for (int z = 0; z < tessArg1; ++z) {
var lineOff0 = z * ptsX;
var lineOff1 = (z + 1) * ptsX;
for (int x = 0; x < tessArg0; ++x) {
//plotMesh.vertices
indices_source[index_id++] = lineOff0 + x;
indices_source[index_id++] = lineOff1 + x + 1;
indices_source[index_id++] = lineOff0 + x + 1;
indices_source[index_id++] = lineOff0 + x;
indices_source[index_id++] = lineOff1 + x;
indices_source[index_id++] = lineOff1 + x + 1;
}
}
var indices = new int[indices_source.Length * surfaces.Length];
//instantiate indices
for (int i = 0; i < surfaces.Length; ++i) {
for (int j = 0; j < indices_source.Length; ++j) {
indices[j + indices_source.Length * i] = indices_source[j] + surfaceVertexCount * i;
}
}
Vector3[] normals = new Vector3[vertices.Length];
//build normals
for (int i = 0; i < indices.Length; i += 3) {
var v0 = vertices[indices[i + 0]];
var v1 = vertices[indices[i + 1]];
var v2 = vertices[indices[i + 2]];
var d0 = v1 - v0;
var d1 = v2 - v1;
var normal = Vector3.Cross(d0, d1).normalized;
normals[indices[i + 0]] = normal;
normals[indices[i + 1]] = normal;
normals[indices[i + 2]] = normal;
}
plotMesh.Clear();
plotMesh.subMeshCount = surfaces.Length;
plotMesh.vertices = vertices;
plotMesh.normals = normals;
for (int i = 0; i < surfaces.Length; ++i) {
var slice_indices = new int[indices_source.Length];
Array.Copy(indices, indices_source.Length * i, slice_indices, 0, indices_source.Length);
plotMesh.SetTriangles(slice_indices, i);
}
plotMesh.RecalculateBounds();
plotMesh.RecalculateNormals();
GetComponent<MeshFilter>().mesh = plotMesh;
var mr = GetComponent<MeshRenderer>();
if (mr.sharedMaterials.Length != surfaces.Length) {
var mats = mr.sharedMaterials;
Array.Resize(ref mats, surfaces.Length);
mr.sharedMaterials = mats;
}
}
private static Vector3[] cubeVertices = new Vector3[]
{
Vector3.zero, Vector3.forward, Vector3.right + Vector3.forward, Vector3.right,
Vector3.zero + Vector3.up, Vector3.forward + Vector3.up, Vector3.right + Vector3.forward + Vector3.up, Vector3.right + Vector3.up,
};
static Color[] axisColor = new Color[] { Color.red, Color.green, Color.blue };
void DrawAxisLabels(int axis, bool begin, Vector3 worldPoint, Vector2 offset)
{
GUIStyle style = new GUIStyle();
Vector3 screenPoint = Camera.current.WorldToScreenPoint(worldPoint);
if (screenPoint.z < 0)
{
return;
}
screenPoint.x += offset.x;
screenPoint.y += offset.y;
for (int j = 0; j < surfaces.Length; ++j)
{
style.normal.textColor = axisColor[axis];
var pos = Camera.current.ScreenToWorldPoint(screenPoint);
var val = begin ? surfaces[j].axisBegin[axis] : surfaces[j].axisEnd[axis];
Handles.Label(pos, val.ToString() + " " + surfaces[j].Suffix[axis], style);
screenPoint.y -= 12;
}
}
void OnDrawGizmos() {
Gizmos.matrix = transform.localToWorldMatrix;
//Draw colored axis
Gizmos.color = axisColor[0];
Gizmos.DrawLine(cubeVertices[0], cubeVertices[3]);
Gizmos.color = axisColor[1];
Gizmos.DrawLine(cubeVertices[0], cubeVertices[4]);
Gizmos.color = axisColor[2];
Gizmos.DrawLine(cubeVertices[0], cubeVertices[1]);
//Draw cube gizmo
Gizmos.color = new Color(1, 1, 1, 0.2f);
//Bottom cap
Gizmos.DrawLine(cubeVertices[1], cubeVertices[2]);
Gizmos.DrawLine(cubeVertices[2], cubeVertices[3]);
//top cap
Gizmos.DrawLine(cubeVertices[4], cubeVertices[5]);
Gizmos.DrawLine(cubeVertices[5], cubeVertices[6]);
Gizmos.DrawLine(cubeVertices[6], cubeVertices[7]);
Gizmos.DrawLine(cubeVertices[7], cubeVertices[4]);
//vertical
Gizmos.DrawLine(cubeVertices[0], cubeVertices[4]);
Gizmos.DrawLine(cubeVertices[1], cubeVertices[5]);
Gizmos.DrawLine(cubeVertices[2], cubeVertices[6]);
Gizmos.DrawLine(cubeVertices[3], cubeVertices[7]);
//draw sections
if (sectionsCount.x < 1) {
sectionsCount.x = 1;
}
if (sectionsCount.y < 1) {
sectionsCount.y = 1;
}
if (sectionsCount.z < 1) {
sectionsCount.z = 1;
}
Gizmos.color = Color.red;
for (int x = 0; x <= sectionsCount.x; ++x) {
Vector3 pt = Vector3.right * ((1.0f / sectionsCount.x) * x);
Gizmos.DrawLine(pt, pt - Vector3.forward * 0.025f);
}
Gizmos.color = Color.green;
for (int x = 0; x <= sectionsCount.y; ++x) {
Vector3 pt = Vector3.up * ((1.0f / sectionsCount.y) * x);
Gizmos.DrawLine(pt, pt - Vector3.right * 0.025f);
}
Gizmos.color = Color.blue;
for (int x = 0; x <= sectionsCount.z; ++x) {
Vector3 pt = Vector3.forward * ((1.0f / sectionsCount.z) * x);
Gizmos.DrawLine(pt, pt - Vector3.right * 0.025f);
}
//Draw labels
Gizmos.matrix = Matrix4x4.identity;
#if UNITY_EDITOR
DrawAxisLabels(0, true, transform.TransformPoint(cubeVertices[0]), Vector2.zero);
DrawAxisLabels(0, false, transform.TransformPoint(cubeVertices[3]), Vector2.zero);
DrawAxisLabels(1, true, transform.TransformPoint(cubeVertices[0]), new Vector2(0, -14 * surfaces.Length));
DrawAxisLabels(1, false, transform.TransformPoint(cubeVertices[4]), new Vector2(0, 14 * surfaces.Length));
DrawAxisLabels(2, true, transform.TransformPoint(cubeVertices[0]), new Vector2(0, -14 * surfaces.Length * 2));
DrawAxisLabels(2, false, transform.TransformPoint(cubeVertices[1]), new Vector2(0, 0));
#endif
}
}
+12
View File
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 85a9fde1c6f855f489bf84464c49ce22
timeCreated: 1454095444
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
using UnityEngine;
using System.Collections;
public class Plot3DFunction : MonoBehaviour {
public virtual float f(float x, float y)
{
return 0;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3f802a2896ad0024bae20429ed69f7d3
timeCreated: 1454096548
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e02eae4e3bf8d744c8028ae73a295913
timeCreated: 1454101062
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using UnityEngine;
using System.Collections;
public class Plot3DMotorFunc : Plot3DFunction
{
public CarEngine engine;
public bool power;
public Car car;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public override float f(float x, float y)
{
if (engine == null)
{
return 0;
}
var t= (float)engine.GetTorque(Mathf.Clamp01(car.throlleCurve.Evaluate(y)), x);
if (!power)
{
return t;
}
return (float)MathEx.Power(t, MathEx.RpmToRadS * x) / 1000;
//return (x*x*y*y)*1000;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 54e5e049d75cce34b840d74b48f78d66
timeCreated: 1454096679
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ecba2cf0ec3e5e41a55ef0b78274adc
timeCreated: 1454165186
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,46 @@
Shader "Custom/Plot3DSLice" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Transparent" "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
//Cull Off
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows alpha:blend
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 5.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2e77cd4fcd0ccd044a3b442b2c9565d2
timeCreated: 1454159297
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8569d2dc7e849e642bda6e0138a7d98f
timeCreated: 1454146480
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 97b9a27ed14ff934099352953d2fa2ea
timeCreated: 1454165194
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class Plot3DUpdater : MonoBehaviour {
public Plot3D target;
public bool on_update;
public bool on_editor_update;
public bool on_fixedUpdate;
public int on_frame = 1;
private int frame = 0;
void Start()
{
frame = 0;
}
void DoUpdate(bool skip_frame = true) {
if (on_frame < 1){
on_frame = 1;
}
if (!skip_frame || (frame%on_frame) == 0){
if (target != null) {
target.UpdateMesh();
}
}
frame++;
}
void Update() {
if (on_update) {
DoUpdate();
}else if (on_editor_update && !Application.isPlaying)
{
DoUpdate(false);
}
}
void FixedUpdate() {
if (on_fixedUpdate) {
DoUpdate();
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5b9777757085fe140b773d1fb467a1c0
timeCreated: 1454102790
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,58 @@
Shader "Unlit/PlotDefaultShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: bcc0a53d653aa15428ae08d3b6eb071c
timeCreated: 1454100540
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
Shader "Custom/PlotLitShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
Cull Off
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows vertex:vert
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float3 localPos;
};
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
o.localPos = v.vertex.xyz;
}
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
float3 p = IN.localPos * 10;
p = abs(abs(frac(p)) - 0.5f) / 0.5f;
p = pow(p +0.04f, 40) ;
o.Albedo = c.rgb * (1 - (p.x + p.y + p.z) / 3.0f);
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b2ede5323c0524843a6276f44a9516fe
timeCreated: 1454107026
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c60dfc3ef7b60a4988be7987d960285
timeCreated: 1454100521
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 19d067a4fa2f1834b9d0e28792b5c9d2
timeCreated: 1454540228
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant: