Commit 679e5a38 authored by Chae Ho Shin's avatar Chae Ho Shin

Add primitive model(WIP)

parent 75bf378f
fileFormatVersion: 2
guid: 72bedc2e0e8f1544eacdf96354b6baf0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: fc3c1c0130c1071448cf816e88b7ac8f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4300000
userData:
assetBundleName:
assetBundleVariant:
This source diff could not be displayed because it is too large. You can view the blob instead.
fileFormatVersion: 2
guid: ad5e268098f7fc745acab47fc446ad82
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4300000
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEditor;
using System.Collections;
// an Editor method to create a cone primitive (so far no end caps)
// the top center is placed at (0/0/0)
// the bottom center is placed at (0/0/length)
// if either one of the radii is 0, the result will be a cone, otherwise a truncated cone
// note you will get inevitable breaks in the smooth shading at cone tips
// note the resulting mesh will be created as an asset in Assets/Editor
// Author: Wolfram Kresse
public class CreateCone : ScriptableWizard
{
public int numVertices = 10;
public float radiusTop = 0f;
public float radiusBottom = 1f;
public float length = 1f;
public float openingAngle = 0f; // if >0, create a cone with this angle by setting radiusTop to 0, and adjust radiusBottom according to length;
public bool outside = true;
public bool inside = false;
public bool addCollider = false;
[MenuItem("GameObject/Create Other/Cone")]
static void CreateWizard()
{
ScriptableWizard.DisplayWizard("Create Cone", typeof(CreateCone));
}
void OnWizardCreate()
{
GameObject newCone = new GameObject("Cone");
if (openingAngle > 0 && openingAngle < 180)
{
radiusTop = 0;
radiusBottom = length * Mathf.Tan(openingAngle * Mathf.Deg2Rad / 2);
}
string meshName = newCone.name + numVertices + "v" + radiusTop + "t" + radiusBottom + "b" + length + "l" + length + (outside ? "o" : "") + (inside ? "i" : "");
string meshPrefabPath = "Assets/Editor/" + meshName + ".asset";
Mesh mesh = (Mesh)AssetDatabase.LoadAssetAtPath(meshPrefabPath, typeof(Mesh));
if (mesh == null)
{
mesh = new Mesh();
mesh.name = meshName;
// can't access Camera.current
//newCone.transform.position = Camera.current.transform.position + Camera.current.transform.forward * 5.0f;
int multiplier = (outside ? 1 : 0) + (inside ? 1 : 0);
int offset = (outside && inside ? 2 * numVertices : 0);
Vector3[] vertices = new Vector3[2 * multiplier * numVertices]; // 0..n-1: top, n..2n-1: bottom
Vector3[] normals = new Vector3[2 * multiplier * numVertices];
Vector2[] uvs = new Vector2[2 * multiplier * numVertices];
int[] tris;
float slope = Mathf.Atan((radiusBottom - radiusTop) / length); // (rad difference)/height
float slopeSin = Mathf.Sin(slope);
float slopeCos = Mathf.Cos(slope);
int i;
for (i = 0; i < numVertices; i++)
{
float angle = 2 * Mathf.PI * i / numVertices;
float angleSin = Mathf.Sin(angle);
float angleCos = Mathf.Cos(angle);
float angleHalf = 2 * Mathf.PI * (i + 0.5f) / numVertices; // for degenerated normals at cone tips
float angleHalfSin = Mathf.Sin(angleHalf);
float angleHalfCos = Mathf.Cos(angleHalf);
vertices[i] = new Vector3(radiusTop * angleCos, radiusTop * angleSin, 0);
vertices[i + numVertices] = new Vector3(radiusBottom * angleCos, radiusBottom * angleSin, length);
if (radiusTop == 0)
normals[i] = new Vector3(angleHalfCos * slopeCos, angleHalfSin * slopeCos, -slopeSin);
else
normals[i] = new Vector3(angleCos * slopeCos, angleSin * slopeCos, -slopeSin);
if (radiusBottom == 0)
normals[i + numVertices] = new Vector3(angleHalfCos * slopeCos, angleHalfSin * slopeCos, -slopeSin);
else
normals[i + numVertices] = new Vector3(angleCos * slopeCos, angleSin * slopeCos, -slopeSin);
uvs[i] = new Vector2(1.0f * i / numVertices, 1);
uvs[i + numVertices] = new Vector2(1.0f * i / numVertices, 0);
if (outside && inside)
{
// vertices and uvs are identical on inside and outside, so just copy
vertices[i + 2 * numVertices] = vertices[i];
vertices[i + 3 * numVertices] = vertices[i + numVertices];
uvs[i + 2 * numVertices] = uvs[i];
uvs[i + 3 * numVertices] = uvs[i + numVertices];
}
if (inside)
{
// invert normals
normals[i + offset] = -normals[i];
normals[i + numVertices + offset] = -normals[i + numVertices];
}
}
mesh.vertices = vertices;
mesh.normals = normals;
mesh.uv = uvs;
// create triangles
// here we need to take care of point order, depending on inside and outside
int cnt = 0;
if (radiusTop == 0)
{
// top cone
tris = new int[numVertices * 3 * multiplier];
if (outside)
for (i = 0; i < numVertices; i++)
{
tris[cnt++] = i + numVertices;
tris[cnt++] = i;
if (i == numVertices - 1)
tris[cnt++] = numVertices;
else
tris[cnt++] = i + 1 + numVertices;
}
if (inside)
for (i = offset; i < numVertices + offset; i++)
{
tris[cnt++] = i;
tris[cnt++] = i + numVertices;
if (i == numVertices - 1 + offset)
tris[cnt++] = numVertices + offset;
else
tris[cnt++] = i + 1 + numVertices;
}
}
else if (radiusBottom == 0)
{
// bottom cone
tris = new int[numVertices * 3 * multiplier];
if (outside)
for (i = 0; i < numVertices; i++)
{
tris[cnt++] = i;
if (i == numVertices - 1)
tris[cnt++] = 0;
else
tris[cnt++] = i + 1;
tris[cnt++] = i + numVertices;
}
if (inside)
for (i = offset; i < numVertices + offset; i++)
{
if (i == numVertices - 1 + offset)
tris[cnt++] = offset;
else
tris[cnt++] = i + 1;
tris[cnt++] = i;
tris[cnt++] = i + numVertices;
}
}
else
{
// truncated cone
tris = new int[numVertices * 6 * multiplier];
if (outside)
for (i = 0; i < numVertices; i++)
{
int ip1 = i + 1;
if (ip1 == numVertices)
ip1 = 0;
tris[cnt++] = i;
tris[cnt++] = ip1;
tris[cnt++] = i + numVertices;
tris[cnt++] = ip1 + numVertices;
tris[cnt++] = i + numVertices;
tris[cnt++] = ip1;
}
if (inside)
for (i = offset; i < numVertices + offset; i++)
{
int ip1 = i + 1;
if (ip1 == numVertices + offset)
ip1 = offset;
tris[cnt++] = ip1;
tris[cnt++] = i;
tris[cnt++] = i + numVertices;
tris[cnt++] = i + numVertices;
tris[cnt++] = ip1 + numVertices;
tris[cnt++] = ip1;
}
}
mesh.triangles = tris;
AssetDatabase.CreateAsset(mesh, meshPrefabPath);
AssetDatabase.SaveAssets();
}
MeshFilter mf = newCone.AddComponent<MeshFilter>();
mf.mesh = mesh;
newCone.AddComponent<MeshRenderer>();
if (addCollider)
{
MeshCollider mc = newCone.AddComponent<MeshCollider>();
mc.sharedMesh = mf.sharedMesh;
}
Selection.activeObject = newCone;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 6760a4fe2ef03cc41af2290c3ce5fe61
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 8cbfe427209aa654ba0e23dceacc84cc
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
[ExecuteInEditMode]
public class AllowDepthCamera : MonoBehaviour
{
private Camera cam;
void Start()
{
cam = GetComponent<Camera>();
cam.depthTextureMode = DepthTextureMode.Depth;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: c0b86a4dd82ff144bb8a45e287c78169
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.up * Time.deltaTime, Space.World);
}
}
fileFormatVersion: 2
guid: cbe88b4b9f484734bb13537c3b8f454b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class ExtrudedMesh : MonoBehaviour
{
// Update is called once per frame
void Update()
{
}
// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
// Do test the code! You usually need to change a few small bits.
// Generates an extrusion trail from the attached mesh
// Uses the MeshExtrusion algorithm in MeshExtrusion.cs to generate and preprocess the mesh.
double time = 30.0f;
bool autoCalculateOrientation = true;
double minDistance = 0.05f;
bool invertFaces = false;
private Mesh srcMesh;
private MeshExtrusion.Edge[] precomputedEdges;
public class ExtrudedTrailSection
{
public Vector3 point;
public Matrix4x4 matrix;
public float time;
}
void Start()
{
srcMesh = GetComponent<MeshFilter>().sharedMesh;
precomputedEdges = MeshExtrusion.BuildManifoldEdges(srcMesh);
}
List<ExtrudedTrailSection> sections = new List<ExtrudedTrailSection>();
void LateUpdate()
{
var position = transform.position;
var now = Time.time;
// Remove old sections
while (sections.Count > 0 && now > sections[sections.Count - 1].time + time)
{
sections.RemoveAt(sections.Count - 1);
}
// Add a new trail section to beginning of array
if (sections.Count == 0 || (sections[0].point - position).sqrMagnitude > minDistance * minDistance)
{
var section = new ExtrudedTrailSection();
section.point = position;
section.matrix = transform.localToWorldMatrix;
section.time = now;
sections.Insert(0,section);
}
// We need at least 2 sections to create the line
if (sections.Count < 2)
return;
var worldToLocal = transform.worldToLocalMatrix;
var finalSections = new Matrix4x4[sections.Count];
Quaternion previousRotation = Quaternion.LookRotation(sections[0].point - sections[1].point, Vector3.up);
for (var i = 0; i < sections.Count; i++)
{
/*if (autoCalculateOrientation)
{
if (i == 0)
{
var direction = sections[0].point - sections[1].point;
var rotation = Quaternion.LookRotation(direction, Vector3.up);
previousRotation = rotation;
finalSections[i] = worldToLocal * Matrix4x4.TRS(position, rotation, Vector3.one);
}
// all elements get the direction by looking up the next section
else if (i != sections.Count - 1)
{
var direction = sections[i].point - sections[i + 1].point;
var rotation = Quaternion.LookRotation(direction, Vector3.up);
// When the angle of the rotation compared to the last segment is too high
// smooth the rotation a little bit. Optimally we would smooth the entire sections array.
if (Quaternion.Angle(previousRotation, rotation) > 20)
rotation = Quaternion.Slerp(previousRotation, rotation, 0.5f);
previousRotation = rotation;
finalSections[i] = worldToLocal * Matrix4x4.TRS(sections[i].point, rotation, Vector3.one);
}
// except the last one, which just copies the previous one
else
{
finalSections[i] = finalSections[i - 1];
}
}
else
{*/
if (i == 0)
{
finalSections[i] = Matrix4x4.identity;
}
else
{
finalSections[i] = worldToLocal * sections[i].matrix;
}
//}
}
// Rebuild the extrusion mesh
MeshExtrusion.ExtrudeMesh(srcMesh, GetComponent<MeshFilter>().mesh, finalSections, precomputedEdges, invertFaces);
}
}
fileFormatVersion: 2
guid: d99664edeab700d4ca972d282f99515b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
%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: FlatlandMaterial
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _FadeLength: 2
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 1
- _HighlightThresholdMax: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _GlowColor: {r: 1, g: 0, b: 0, a: 1}
- _HighlightColor: {r: 1, g: 1, b: 1, a: 1}
- _RegularColor: {r: 0, g: 0, b: 0, a: 1}
fileFormatVersion: 2
guid: c5298fefcfd9aa945b24d682f943ffdd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
%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: Lightcone
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DepthFactor: 1
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _FadeLength: 0.27
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 0
- _HighlightThresholdMax: 1
- _IntersectionDamper: 1
- _IntersectionMax: 0.01
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 0
- _SrcBlend: 1
- _StencilMask: 255
- _UVSec: 0
- _ZBias: 2.5
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _CrossColor: {r: 1, g: 1, b: 1, a: 1}
- _EdgeColor: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _GlowColor: {r: 1, g: 0, b: 0, a: 1}
- _HighlightColor: {r: 1, g: 1, b: 1, a: 0.5}
- _IntersectionColor: {r: 1, g: 0, b: 0, a: 1}
- _MainColor: {r: 0, g: 0, b: 0, a: 1}
- _PlaneNormal: {r: 0, g: 1, b: 0, a: 0}
- _PlanePosition: {r: 0, g: 0, b: 0, a: 1}
- _RegularColor: {r: 0, g: 0, b: 0, a: 1}
fileFormatVersion: 2
guid: c586755a7c8d6af4bb1944882f90197c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
/*
* An algorithm to extrude an arbitrary mesh along a number of sections.
The mesh extrusion has 2 steps:
1. Extracting an edge representation from an arbitrary mesh
- A general edge extraction algorithm is employed. (Same algorithm as traditionally used for stencil shadows) Once all unique edges are found, all edges that connect to only one triangle are extracted.
Thus we end up with the outline of the mesh.
2. extruding the mesh from the edge representation.
We simply generate a segments joining the edges
*/
public class MeshExtrusion
{
public class Edge
{
// The indiex to each vertex
public int[] vertexIndex = new int[2];
// The index into the face.
// (faceindex[0] == faceindex[1] means the edge connects to only one triangle)
public int[] faceIndex = new int[2];
}
public static void ExtrudeMesh (Mesh srcMesh, Mesh extrudedMesh, Matrix4x4[] extrusion, bool invertFaces)
{
Edge[] edges = BuildManifoldEdges(srcMesh);
ExtrudeMesh(srcMesh, extrudedMesh, extrusion, edges, invertFaces);
}
public static void ExtrudeMesh (Mesh srcMesh, Mesh extrudedMesh, Matrix4x4[] extrusion, Edge[] edges, bool invertFaces)
{
int extrudedVertexCount = edges.Length * 2 * extrusion.Length;
int triIndicesPerStep = edges.Length * 6;
int extrudedTriIndexCount = triIndicesPerStep * (extrusion.Length -1);
Vector3[] inputVertices = srcMesh.vertices;
Vector2[] inputUV = srcMesh.uv;
int[] inputTriangles = srcMesh.triangles;
Vector3[] vertices = new Vector3[extrudedVertexCount + srcMesh.vertexCount * 2];
Vector2[] uvs = new Vector2[vertices.Length];
int[] triangles = new int[extrudedTriIndexCount + inputTriangles.Length * 2];
// Build extruded vertices
int v = 0;
for (int i=0;i<extrusion.Length;i++)
{
Matrix4x4 matrix = extrusion[i];
float vcoord = (float)i / (extrusion.Length -1);
foreach (Edge e in edges)
{
vertices[v+0] = matrix.MultiplyPoint(inputVertices[e.vertexIndex[0]]);
vertices[v+1] = matrix.MultiplyPoint(inputVertices[e.vertexIndex[1]]);
uvs[v+0] = new Vector2 (inputUV[e.vertexIndex[0]].x, vcoord);
uvs[v+1] = new Vector2 (inputUV[e.vertexIndex[1]].x, vcoord);
v += 2;
}
}
// Build cap vertices
// * The bottom mesh we scale along it's negative extrusion direction. This way extruding a half sphere results in a capsule.
for (int c=0;c<2;c++)
{
Matrix4x4 matrix = extrusion[c == 0 ? 0 : extrusion.Length-1];
int firstCapVertex = c == 0 ? extrudedVertexCount : extrudedVertexCount + inputVertices.Length;
for (int i=0;i<inputVertices.Length;i++)
{
vertices[firstCapVertex + i] = matrix.MultiplyPoint(inputVertices[i]);
uvs[firstCapVertex + i] = inputUV[i];
}
}
// Build extruded triangles
for (int i=0;i<extrusion.Length-1;i++)
{
int baseVertexIndex = (edges.Length * 2) * i;
int nextVertexIndex = (edges.Length * 2) * (i+1);
for (int e=0;e<edges.Length;e++)
{
int triIndex = i * triIndicesPerStep + e * 6;
triangles[triIndex + 0] = baseVertexIndex + e * 2;
triangles[triIndex + 1] = nextVertexIndex + e * 2;
triangles[triIndex + 2] = baseVertexIndex + e * 2 + 1;
triangles[triIndex + 3] = nextVertexIndex + e * 2;
triangles[triIndex + 4] = nextVertexIndex + e * 2 + 1;
triangles[triIndex + 5] = baseVertexIndex + e * 2 + 1;
}
}
// build cap triangles
int triCount = inputTriangles.Length / 3;
// Top
{
int firstCapVertex = extrudedVertexCount;
int firstCapTriIndex = extrudedTriIndexCount;
for (int i=0;i<triCount;i++)
{
triangles[i*3 + firstCapTriIndex + 0] = inputTriangles[i * 3 + 1] + firstCapVertex;
triangles[i*3 + firstCapTriIndex + 1] = inputTriangles[i * 3 + 2] + firstCapVertex;
triangles[i*3 + firstCapTriIndex + 2] = inputTriangles[i * 3 + 0] + firstCapVertex;
}
}
// Bottom
{
int firstCapVertex = extrudedVertexCount + inputVertices.Length;
int firstCapTriIndex = extrudedTriIndexCount + inputTriangles.Length;
for (int i=0;i<triCount;i++)
{
triangles[i*3 + firstCapTriIndex + 0] = inputTriangles[i * 3 + 0] + firstCapVertex;
triangles[i*3 + firstCapTriIndex + 1] = inputTriangles[i * 3 + 2] + firstCapVertex;
triangles[i*3 + firstCapTriIndex + 2] = inputTriangles[i * 3 + 1] + firstCapVertex;
}
}
if (invertFaces)
{
for (int i=0;i<triangles.Length/3;i++)
{
int temp = triangles[i*3 + 0];
triangles[i*3 + 0] = triangles[i*3 + 1];
triangles[i*3 + 1] = temp;
}
}
extrudedMesh.Clear();
extrudedMesh.name= "extruded";
extrudedMesh.vertices = vertices;
extrudedMesh.uv = uvs;
extrudedMesh.triangles = triangles;
extrudedMesh.RecalculateNormals();
}
/// Builds an array of edges that connect to only one triangle.
/// In other words, the outline of the mesh
public static Edge[] BuildManifoldEdges (Mesh mesh)
{
// Build a edge list for all unique edges in the mesh
Edge[] edges = BuildEdges(mesh.vertexCount, mesh.triangles);
// We only want edges that connect to a single triangle
ArrayList culledEdges = new ArrayList();
foreach (Edge edge in edges)
{
if (edge.faceIndex[0] == edge.faceIndex[1])
{
culledEdges.Add(edge);
}
}
return culledEdges.ToArray(typeof(Edge)) as Edge[];
}
/// Builds an array of unique edges
/// This requires that your mesh has all vertices welded. However on import, Unity has to split
/// vertices at uv seams and normal seams. Thus for a mesh with seams in your mesh you
/// will get two edges adjoining one triangle.
/// Often this is not a problem but you can fix it by welding vertices
/// and passing in the triangle array of the welded vertices.
public static Edge[] BuildEdges(int vertexCount, int[] triangleArray)
{
int maxEdgeCount = triangleArray.Length;
int[] firstEdge = new int[vertexCount + maxEdgeCount];
int nextEdge = vertexCount;
int triangleCount = triangleArray.Length / 3;
for (int a = 0; a < vertexCount; a++)
firstEdge[a] = -1;
// First pass over all triangles. This finds all the edges satisfying the
// condition that the first vertex index is less than the second vertex index
// when the direction from the first vertex to the second vertex represents
// a counterclockwise winding around the triangle to which the edge belongs.
// For each edge found, the edge index is stored in a linked list of edges
// belonging to the lower-numbered vertex index i. This allows us to quickly
// find an edge in the second pass whose higher-numbered vertex index is i.
Edge[] edgeArray = new Edge[maxEdgeCount];
int edgeCount = 0;
for (int a = 0; a < triangleCount; a++)
{
int i1 = triangleArray[a*3 + 2];
for (int b = 0; b < 3; b++)
{
int i2 = triangleArray[a*3 + b];
if (i1 < i2)
{
Edge newEdge = new Edge();
newEdge.vertexIndex[0] = i1;
newEdge.vertexIndex[1] = i2;
newEdge.faceIndex[0] = a;
newEdge.faceIndex[1] = a;
edgeArray[edgeCount] = newEdge;
int edgeIndex = firstEdge[i1];
if (edgeIndex == -1)
{
firstEdge[i1] = edgeCount;
}
else
{
while (true)
{
int index = firstEdge[nextEdge + edgeIndex];
if (index == -1)
{
firstEdge[nextEdge + edgeIndex] = edgeCount;
break;
}
edgeIndex = index;
}
}
firstEdge[nextEdge + edgeCount] = -1;
edgeCount++;
}
i1 = i2;
}
}
// Second pass over all triangles. This finds all the edges satisfying the
// condition that the first vertex index is greater than the second vertex index
// when the direction from the first vertex to the second vertex represents
// a counterclockwise winding around the triangle to which the edge belongs.
// For each of these edges, the same edge should have already been found in
// the first pass for a different triangle. Of course we might have edges with only one triangle
// in that case we just add the edge here
// So we search the list of edges
// for the higher-numbered vertex index for the matching edge and fill in the
// second triangle index. The maximum number of comparisons in this search for
// any vertex is the number of edges having that vertex as an endpoint.
for (int a = 0; a < triangleCount; a++)
{
int i1 = triangleArray[a*3+2];
for (int b = 0; b < 3; b++)
{
int i2 = triangleArray[a*3+b];
if (i1 > i2)
{
bool foundEdge = false;
for (int edgeIndex = firstEdge[i2]; edgeIndex != -1;edgeIndex = firstEdge[nextEdge + edgeIndex])
{
Edge edge = edgeArray[edgeIndex];
if ((edge.vertexIndex[1] == i1) && (edge.faceIndex[0] == edge.faceIndex[1]))
{
edgeArray[edgeIndex].faceIndex[1] = a;
foundEdge = true;
break;
}
}
if (!foundEdge)
{
Edge newEdge = new Edge();
newEdge.vertexIndex[0] = i1;
newEdge.vertexIndex[1] = i2;
newEdge.faceIndex[0] = a;
newEdge.faceIndex[1] = a;
edgeArray[edgeCount] = newEdge;
edgeCount++;
}
}
i1 = i2;
}
}
Edge[] compactedEdges = new Edge[edgeCount];
for (int e=0;e<edgeCount;e++)
compactedEdges[e] = edgeArray[e];
return compactedEdges;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: a1ba8b570528ec14d8f44dd0969a46f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Shader "Custom/NewSurfaceShader"
{
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
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// 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)
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"
}
fileFormatVersion: 2
guid: 6bfcb77263fb33f47bc7bef6d539448b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
Shader "Custom/PastLightConeShader" {
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
_GlowColor("Glow Color", Color) = (1, 1, 1, 1)
_FadeLength("Fade Length", Range(0, 5)) = 1
}
SubShader{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On
Tags
{
"RenderType" = "Transparent"
"Queue" = "Transparent"
}
CGPROGRAM
#pragma surface surf Standard fullforwardshadows alpha:fade vertex:vert
#pragma target 4.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float4 screenPos;
float eyeDepth;
};
half _Glossiness;
half _Metallic;
sampler2D _CameraDepthTexture;
fixed4 _Color;
fixed4 _GlowColor;
float _FadeLength;
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
COMPUTE_EYEDEPTH(o.eyeDepth);
}
void surf(Input IN, inout SurfaceOutputStandard o) {
float rawZ = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos));
float sceneZ = rawZ;
float partZ = IN.eyeDepth;
float diff = (sceneZ - partZ);
float intersect = 1 - saturate(diff / _FadeLength);
fixed4 col = fixed4(lerp(tex2D(_MainTex, IN.uv_MainTex) * _Color, _GlowColor, pow(intersect, 4)));
o.Albedo = col.rgb;
o.Alpha = col.a;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
}
ENDCG
}
FallBack "Diffuse"
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2da57e514d4219540ab22cc16d497ddd
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Planemovement : MonoBehaviour
{
//bool toggle = true;
int cnt = 0;
double beta = 0.5f; // v/c
// Start is called before the first frame update
public GameObject theobject;
void Start()
{
Renderer r = theobject.GetComponent<Renderer>();
//Color materialColor = r.material.color;
r.material.color = Color.blue;
}
// Update is called once per frame
// For physics calcs
void FixedUpdate()
{
var prevup = transform.up;
var prevfor = transform.forward;
transform.Translate(Vector3.up * Time.fixedDeltaTime, Space.World); // move up by 1 second
cnt++;
if (cnt % 480 == 0)
{
cnt = 0;
}
//transform.Translate(Vector3.forward * Time.fixedDeltaTime, Space.World);
//transform.Translate(0.5f*Vector3.forward * Mathf.Cos(2*Mathf.PI*cnt/480) * Time.fixedDeltaTime, Space.World);
//transform.Translate(0.5f*Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480) * Time.fixedDeltaTime, Space.World);
var v = (float)beta * Vector3.forward * Mathf.Cos(2 * Mathf.PI * cnt / 480) + (float)beta * Vector3.left * Mathf.Sin(2 * Mathf.PI * cnt / 480);
double gamma = 1.0f / Mathf.Sqrt(1.0f - (float)(beta*beta));
transform.Translate(v * Time.fixedDeltaTime, Space.World);
var vt = v + Vector3.up;
vt.x = -vt.x;
vt.z = -vt.z;
vt.Normalize();
//transform.up = vt;
//theobject.transform.up = vt;
//Quaternion rotation = Quaternion.LookRotation(Vector3.forward, vt);
//transform.rotation = rotation;
transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // release child to change x'-axis scale
theobject.transform.up = vt;
theobject.transform.parent = null;
Vector3 newforward = new Vector3(vt.y * (v.x/v.magnitude),Mathf.Sqrt(vt.x * vt.x + vt.z *vt.z), vt.y * (v.z / v.magnitude));
transform.rotation = Quaternion.LookRotation(newforward, vt);
//Quaternion forwardrotation = Quaternion.FromToRotation(prevfor, newforward);
//transform.forward = newforward;
theobject.transform.parent = transform;
transform.localScale = new Vector3(1.0f, 1.0f, (float)gamma); // scale x' axis
}
}
fileFormatVersion: 2
guid: 0bf826b8a4774ba4b9c6a1cff6925667
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using UnityEngine;
namespace BLINDED_AM_ME
{
[ExecuteInEditMode]
public class SetDepthTextureMode : MonoBehaviour
{
public DepthTextureMode mode = DepthTextureMode.Depth;
public void Start()
{
}
// before a camera renders this
public void OnWillRenderObject()
{
if (!enabled)
return;
Camera cam = Camera.current;
if (!cam)
return;
cam.depthTextureMode = mode;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 9efff9ae03b011545a0141949e2d650e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment