added basic coriolis effect, needs to be replaceddevelop
size 304950 |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 6014d8143b6d2814cb80384d116a39a4 | |||
folderAsset: yes | |||
DefaultImporter: | |||
externalObjects: {} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,99 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using UnityEngine; | |||
public class MeshCurver : MonoBehaviour | |||
{ | |||
[Header("References")] | |||
[SerializeField] | |||
private RotationController m_pivot; | |||
[Header("Settings")] | |||
[SerializeField] | |||
private bool m_ApplyAtStart = true; | |||
[SerializeField] | |||
private bool m_UpdateCollider = true; | |||
[Header("Debug")] | |||
[SerializeField] | |||
private bool m_CalculateEachUpdate = false; | |||
private Mesh m_startMesh; | |||
private MeshFilter m_meshFilter; | |||
private MeshCollider m_meshCollider; | |||
private void Start() | |||
{ | |||
m_meshFilter = GetComponent<MeshFilter>(); | |||
m_meshCollider = GetComponent<MeshCollider>(); | |||
m_startMesh = m_meshFilter.mesh; | |||
if (m_ApplyAtStart) | |||
UpdateMesh(); | |||
} | |||
private void Update() | |||
{ | |||
if (m_CalculateEachUpdate) | |||
UpdateMesh(); | |||
} | |||
[ContextMenu("Update Mesh")] | |||
public void UpdateMesh() | |||
{ | |||
Mesh newMesh = UpdateMesh(m_pivot.Position, m_startMesh, m_pivot.RotationAxis, transform); | |||
m_meshFilter.mesh = newMesh; | |||
if (m_meshCollider != null && m_UpdateCollider) | |||
m_meshCollider.sharedMesh = newMesh; | |||
} | |||
public Mesh UpdateMesh(Vector3 centre, Mesh mesh, Vector3 Axis, Transform origin) | |||
{ | |||
List<Vector3> transformedVertices = new List<Vector3>(); | |||
Vector3[] vertices = mesh.vertices; | |||
Vector3 closestPoint = origin.TransformPoint(vertices.OrderBy(p => Vector3.Distance(centre, origin.TransformPoint(p))).First()); | |||
Vector3 direction = closestPoint - centre; | |||
Vector3 perpendicular = Vector3.Cross(Axis, direction).normalized; | |||
Debug.DrawLine(centre, closestPoint, Color.red); | |||
float radius = direction.magnitude; | |||
foreach (Vector3 vertex in vertices) | |||
{ | |||
Vector3 worldPosition = origin.TransformPoint(vertex); | |||
Vector3 directionFromStartPoint = Vector3.ProjectOnPlane(worldPosition - closestPoint, Axis); | |||
Vector3 planeOffset = Vector3.Project(worldPosition - closestPoint, Axis); | |||
float heightOffset = radius - Vector3.Project(worldPosition-centre,direction.normalized).magnitude; | |||
float arcLength = directionFromStartPoint.magnitude; | |||
float angle = (arcLength / radius); | |||
if (Vector3.Dot(directionFromStartPoint, perpendicular) < 0) | |||
angle = -angle; | |||
Vector3 directionFromCentre = Quaternion.AngleAxis(Mathf.Rad2Deg * angle, Axis) * ((direction)); | |||
transformedVertices.Add((origin.InverseTransformPoint(centre + directionFromCentre.normalized * (radius - heightOffset) + planeOffset))); | |||
} | |||
Mesh retVal = new Mesh(); | |||
retVal.vertices = transformedVertices.ToArray(); | |||
retVal.triangles = mesh.triangles; | |||
retVal.uv = mesh.uv; | |||
retVal.RecalculateNormals(); | |||
retVal.RecalculateTangents(); | |||
retVal.RecalculateBounds(); | |||
return retVal; | |||
} | |||
} |
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 9d605cf3e1eb369488e85916fc948746 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,77 @@ | |||
%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: DoubleSided | |||
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 | |||
- _GlossMapScale: 1 | |||
- _Glossiness: 0.5 | |||
- _GlossyReflections: 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: 1} | |||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 284575bb9fa87cf408d55264b5273c44 | |||
NativeFormatImporter: | |||
externalObjects: {} | |||
mainObjectFileID: 0 | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
size 50220 |
@ -0,0 +1,97 @@ | |||
fileFormatVersion: 2 | |||
guid: 08d37afad95a047449d920cf7f3002f4 | |||
ModelImporter: | |||
serializedVersion: 19301 | |||
internalIDToNameTable: [] | |||
externalObjects: {} | |||
materials: | |||
materialImportMode: 1 | |||
materialName: 0 | |||
materialSearch: 1 | |||
materialLocation: 1 | |||
animations: | |||
legacyGenerateAnimations: 4 | |||
bakeSimulation: 0 | |||
resampleCurves: 1 | |||
optimizeGameObjects: 0 | |||
motionNodeName: | |||
rigImportErrors: | |||
rigImportWarnings: | |||
animationImportErrors: | |||
animationImportWarnings: | |||
animationRetargetingWarnings: | |||
animationDoRetargetingWarnings: 0 | |||
importAnimatedCustomProperties: 0 | |||
importConstraints: 0 | |||
animationCompression: 1 | |||
animationRotationError: 0.5 | |||
animationPositionError: 0.5 | |||
animationScaleError: 0.5 | |||
animationWrapMode: 0 | |||
extraExposedTransformPaths: [] | |||
extraUserProperties: [] | |||
clipAnimations: [] | |||
isReadable: 1 | |||
meshes: | |||
lODScreenPercentages: [] | |||
globalScale: 1 | |||
meshCompression: 0 | |||
addColliders: 0 | |||
useSRGBMaterialColor: 1 | |||
sortHierarchyByName: 1 | |||
importVisibility: 1 | |||
importBlendShapes: 1 | |||
importCameras: 1 | |||
importLights: 1 | |||
fileIdsGeneration: 2 | |||
swapUVChannels: 0 | |||
generateSecondaryUV: 0 | |||
useFileUnits: 1 | |||
keepQuads: 0 | |||
weldVertices: 1 | |||
preserveHierarchy: 0 | |||
skinWeightsMode: 0 | |||
maxBonesPerVertex: 4 | |||
minBoneWeight: 0.001 | |||
meshOptimizationFlags: -1 | |||
indexFormat: 0 | |||
secondaryUVAngleDistortion: 8 | |||
secondaryUVAreaDistortion: 15.000001 | |||
secondaryUVHardAngle: 88 | |||
secondaryUVPackMargin: 4 | |||
useFileScale: 1 | |||
tangentSpace: | |||
normalSmoothAngle: 60 | |||
normalImportMode: 0 | |||
tangentImportMode: 3 | |||
normalCalculationMode: 4 | |||
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0 | |||
blendShapeNormalImportMode: 1 | |||
normalSmoothingSource: 0 | |||
referencedClips: [] | |||
importAnimation: 1 | |||
humanDescription: | |||
serializedVersion: 3 | |||
human: [] | |||
skeleton: [] | |||
armTwist: 0.5 | |||
foreArmTwist: 0.5 | |||
upperLegTwist: 0.5 | |||
legTwist: 0.5 | |||
armStretch: 0.05 | |||
legStretch: 0.05 | |||
feetSpacing: 0 | |||
globalScale: 1 | |||
rootMotionBoneName: | |||
hasTranslationDoF: 0 | |||
hasExtraRoot: 0 | |||
skeletonHasParents: 1 | |||
lastHumanDescriptionAvatarSource: {instanceID: 0} | |||
autoGenerateAvatarMappingIfUnspecified: 1 | |||
animationType: 2 | |||
humanoidOversampling: 1 | |||
avatarSetup: 0 | |||
additionalBone: 0 | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 11923c7becd04754289b60db235cd1bb | |||
folderAsset: yes | |||
DefaultImporter: | |||
externalObjects: {} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,87 @@ | |||
Shader "Custom/DoubleSided" { | |||
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 | |||
_BumpMap("NormalMap", 2D) = "Bump" {} | |||
_BumpScale("Normal Power", Float) = 1.0 | |||
_NormalDefault("Normal Default", Color) = (128, 128, 255) | |||
} | |||
SubShader{ | |||
Tags { "RenderType" = "Opaque" } | |||
LOD 200 | |||
// Render back faces first | |||
Cull Front | |||
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; | |||
sampler2D _BumpMap; | |||
struct Input { | |||
float2 uv_MainTex; | |||
}; | |||
half _Glossiness; | |||
half _BumpScale; | |||
half _Metallic; | |||
fixed4 _Color; | |||
half3 _NormalDefault; | |||
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.Normal = -UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)); | |||
//o.Normal = -_NormalDefault; | |||
o.Alpha = c.a; | |||
} | |||
ENDCG | |||
// Now render front faces | |||
Cull Back | |||
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; | |||
sampler2D _BumpMap; | |||
struct Input { | |||
float2 uv_MainTex; | |||
}; | |||
half _Glossiness; | |||
half _BumpScale; | |||
half _Metallic; | |||
fixed4 _Color; | |||
half3 _NormalDefault; | |||
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.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex)); | |||
//o.Normal = _NormalDefault; | |||
o.Alpha = c.a; | |||
} | |||
ENDCG | |||
} | |||
FallBack "Diffuse" | |||
} |
@ -0,0 +1,9 @@ | |||
fileFormatVersion: 2 | |||
guid: af3776ac6a322cb4da895ba92b2bc463 | |||
ShaderImporter: | |||
externalObjects: {} | |||
defaultTextures: [] | |||
nonModifiableTextures: [] | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |