public static Vector3 GetOffset(Vector3 atPosition, Transform cameraTransform) { HB hb = HB.Instance; if (hb == null) { return(new Vector3(0.0f, 0.0f, 0.0f)); } Vector3 offset; HBSettings settings = GetSettings(); #if UNITY_EDITOR if (settings.AttachToCameraInEditor) { offset = HBUtils.GetOffset(atPosition, settings, cameraTransform); } else { offset = HBUtils.GetOffset(atPosition, settings); } #else offset = HBUtils.GetOffset(atPosition, settings, cameraTransform); #endif return(offset); }
public static Mesh FixMesh(Mesh originalMesh, Vector3 extents) { Bounds bounds = originalMesh.bounds; Bounds fixBounds = new Bounds(bounds.center, extents * 2.0f); Mesh fixVertices = HBUtils.BoundsToMesh(fixBounds); CombineInstance fixInstance = new CombineInstance(); fixInstance.mesh = fixVertices; fixInstance.subMeshIndex = 0; fixInstance.transform = Matrix4x4.identity; CombineInstance[] combineInstances = new CombineInstance[originalMesh.subMeshCount]; for (int i = 0; i < originalMesh.subMeshCount; ++i) { CombineInstance submeshInstance = new CombineInstance(); submeshInstance.mesh = Subdivider.ExtractSubmesh(originalMesh, i); submeshInstance.transform = Matrix4x4.identity; CombineInstance[] submeshInstances = new[] { fixInstance, submeshInstance }; Mesh fixedSubmesh = new Mesh(); fixedSubmesh.CombineMeshes(submeshInstances, true); CombineInstance meshInstance = new CombineInstance(); meshInstance.mesh = fixedSubmesh; meshInstance.transform = Matrix4x4.identity; meshInstance.subMeshIndex = 0; combineInstances[i] = meshInstance; } Mesh fixedMesh = new Mesh(); fixedMesh.CombineMeshes(combineInstances, false); return(fixedMesh); }
public void Internal_Rollback(bool full) { DestroyHBCameras(); FixBoundsRadius = 50.0f; Curvature = 5.0f; Flatten = 0.0f; HorizonXOffset = 0.0f; HorizonYOffset = 0.0f; HorizonZOffset = 0.0f; AttachToCamera = false; m_appliedRadius = 0.0f; Material[] materials = Materials; if (full) { HBUtils.Find(out Materials, out m_rendererGroups, new GameObject[0]); } else { HBUtils.Find(out Materials, out m_rendererGroups, ExcludeGameObjects); } HBUtils.HorizonBend(new HBSettings(BendingMode._HB_OFF)); TryRollbackDefaultMaterial(); ReplaceUIMaterials(materials, true, full); RendererGroupsIterate(renderer => { if (renderer == null) { return; } HBFixBounds fixBounds = renderer.GetComponent <HBFixBounds>(); if (fixBounds != null) { if (full || !fixBounds.Lock) { fixBounds.Rollback(); DestroyImmediate(fixBounds); } } }); HBUtils.ReplaceShaders(Materials, HBShaders, true); m_rendererGroups.Clear(); if (LockMaterials) { Materials = materials; } else { Materials = new Material[0]; } }
public static void ApplyFlatten(float flatten) { HB hb = HB.Instance; if (hb == null) { return; } hb.Flatten = flatten; HBUtils.HBFlatten(flatten); }
public static void ApplyCurvature(float curvature) { HB hb = HB.Instance; if (hb == null) { return; } hb.Curvature = curvature; HBUtils.HBCurvature(curvature * CURVATURE_FACTOR); }
private void FixBoundsSkinned() { if (OverrideBounds) { HBUtils.FixSkinned(SkinnedMesh, OriginalSkinnedAABB, SkinnedBounds); } else { HBUtils.FixSkinned(SkinnedMesh, OriginalSkinnedAABB, transform, HBOffset()); } }
public static void FixSkinned(SkinnedMeshRenderer skinned, float fixBoundsRadius) { HB hb = HB.Instance; if (hb == null) { return; } Vector3 hbOffset = HBUtils.GetOffset(GetSettings(), fixBoundsRadius); HBUtils.FixSkinned(skinned, skinned.localBounds, skinned.transform, hbOffset); }
public static void FixMesh(MeshFilter meshFilter, float fixBoundsRadius) { HB hb = HB.Instance; if (hb == null) { return; } Vector3 hbOffset = HBUtils.GetOffset(GetSettings(), fixBoundsRadius); meshFilter.sharedMesh = HBUtils.FixMesh(meshFilter.sharedMesh, meshFilter.transform, hbOffset); }
public static void ScreenPointToRays(Camera camera, out Ray[] rays, out float[] maxDistances) { HB hb = HB.Instance; if (hb == null) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); rays = new[] { ray }; maxDistances = new[] { Mathf.Infinity }; return; } HBUtils.ScreenPointToRays(camera, hb.RaycastStride, hb.FixBoundsRadius, GetSettings(), out rays, out maxDistances); }
public static void CameraToRays(Transform camerTransform, out Ray[] rays, out float[] maxDistances) { HB hb = HB.Instance; if (hb == null) { Ray ray = new Ray(camerTransform.position, camerTransform.forward); rays = new[] { ray }; maxDistances = new[] { Mathf.Infinity }; return; } HBUtils.CameraToRays(camerTransform, hb.RaycastStride, hb.FixBoundsRadius, GetSettings(), out rays, out maxDistances); }
public static void ApplyHorizonOffset(float horizonX, float horizonY, float horizonZ, Transform transform = null) { HB hb = HB.Instance; if (hb == null) { return; } hb.HorizonXOffset = horizonX; hb.HorizonYOffset = horizonY; hb.HorizonZOffset = horizonZ; HBUtils.HBHorizonOffset(horizonX, horizonY, horizonZ, transform); }
public static void ApplyAll(float curvature, float flatten, float horizonX, float horizonY, float horizonZ, Transform transform = null) { HB hb = HB.Instance; if (hb == null) { return; } hb.Curvature = curvature; hb.Flatten = flatten; hb.HorizonXOffset = horizonX; hb.HorizonYOffset = horizonY; hb.HorizonZOffset = horizonZ; HBSettings settings = GetSettings(); HBUtils.HorizonBend(settings, transform); }
private void FixMesh(bool global) { Mesh fixedMesh; if (OverrideBounds) { fixedMesh = HBUtils.FixMesh(OriginalMesh, Bounds); } else { fixedMesh = HBUtils.FixMesh(OriginalMesh, transform, HBOffset()); } if (IsGlobalSettingOverriden()) { fixedMesh.name = OriginalMesh.name + " HB Local"; SetMesh(fixedMesh, true, false); } else { if (global) { fixedMesh.name = OriginalMesh.name + " HB Global"; IsMeshFixed = true; IsBoundsFixed = false; if (HB.Instance == null) { throw new System.InvalidOperationException("HB.Instance is null"); } HB.Instance.Internal_UpdateMeshInGroup(this, fixedMesh); } else { fixedMesh.name = OriginalMesh.name + " HB Local"; SetMesh(fixedMesh, true, false); } } }
public void Internal_Apply() { m_rendererGroups.Clear(); if (m_defaultMaterial == null) { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); m_defaultMaterial = cube.GetComponent <Renderer>().sharedMaterial; DestroyImmediate(cube); } if (m_defaultParticle == null) { GameObject particles = new GameObject(); particles.AddComponent <ParticleSystem>(); m_defaultParticle = particles.GetComponent <Renderer>().sharedMaterial; DestroyImmediate(particles); } m_appliedRadius = FixBoundsRadius; Material[] materials; EditorUtility.DisplayProgressBar("Horizon Bend", "Searching for materials", 0.1f); HBUtils.Find(out materials, out m_rendererGroups, ExcludeGameObjects); if (!LockMaterials) { Materials = materials; } EditorUtility.DisplayProgressBar("Horizon Bend", "Replacing default materials", 0.2f); Materials = ReplaceUIMaterials(Materials, false, false); TryRelpaceDefaultMaterials(); EditorUtility.DisplayProgressBar("Horizon Bend", "Replacing shaders", 0.3f); HBUtils.ReplaceShaders(Materials, HBShaders, false); EditorUtility.DisplayProgressBar("Horizon Bend", "Cleaning materials", 0.4f); Materials = HBUtils.Trim(Materials, m_rendererGroups, CustomShaders); CreateHBCameras(); EditorUtility.DisplayProgressBar("Horizon Bend", "Fixing Bounds", 0.5f); CreateHBFixBounds(); FixBounds(); EditorUtility.DisplayProgressBar("Horizon Bend", "Completed", 1.0f); Transform fakeCameraTransform = null; bool attachToCamera = true; if (!AttachToCamera) { fakeCameraTransform = transform; attachToCamera = false; } HBUtils.HorizonBend(new HBSettings(BendingMode, Curvature * CURVATURE_FACTOR, Flatten, HorizonXOffset, HorizonYOffset, HorizonZOffset, attachToCamera), fakeCameraTransform); HBUtils.HBMode(BendingMode); EditorUtility.ClearProgressBar(); }
public void FixBounds(bool global) { if (MeshFilter == null) { if (SkinnedMesh == null) { Debug.LogError("m_fixBounds.MeshFilter is null. Unable to FixBounds. GameObject " + name); } return; } if (OriginalMesh == null) { if (SkinnedMesh == null) { Debug.LogError("m_fixBounds.OriginalMesh is null. Unable to FixBounds. GameObject " + name); } return; } if (gameObject.isStatic) { FixMesh(global); } else { Mesh fixedMesh; if (OverrideBounds) { fixedMesh = HBUtils.FixBounds(OriginalMesh, Bounds); } else { fixedMesh = HBUtils.FixBounds(OriginalMesh, transform, HBOffset()); } if (IsGlobalSettingOverriden()) { fixedMesh.name = OriginalMesh.name + " HB Local"; SetMesh(fixedMesh, false, true); } else { if (global) { fixedMesh.name = OriginalMesh.name + " HB Global"; IsMeshFixed = false; IsBoundsFixed = true; if (HB.Instance == null) { throw new System.InvalidOperationException("HB.Instance is null"); } HB.Instance.Internal_UpdateMeshInGroup(this, fixedMesh); } else { fixedMesh.name = OriginalMesh.name + " HB Local"; SetMesh(fixedMesh, false, true); } } } }
public static void FixMesh(MeshFilter meshFilter, Vector3 extents) { meshFilter.sharedMesh = HBUtils.FixMesh(meshFilter.sharedMesh, extents); }
public Vector3 HBOffset() { HBSettings settings = new HBSettings(BendingMode, Curvature * HB.CURVATURE_FACTOR, Flatten, HorizonXOffset, HorizonYOffset, HorizonZOffset, false); return(HBUtils.GetOffset(settings, FixBoundsRadius)); }
public static void FixSkinned(SkinnedMeshRenderer skinned, Vector3 extents) { HBUtils.FixSkinned(skinned, skinned.localBounds, extents); }
private void Update() { if (Application.isPlaying) { return; } bool positionChanged = false; if (m_previosPosition != transform.position) { positionChanged = !AttachToCamera; m_previosPosition = transform.position; } if (RaycastStride < 0.01f) { RaycastStride = 0.01f; } if (m_previousRadius != FixBoundsRadius) { if (FixBoundsRadius < 0) { FixBoundsRadius = 0; } m_previousRadius = FixBoundsRadius; } if (m_previousCurvature != Curvature) { HBUtils.HBCurvature(Curvature * CURVATURE_FACTOR); m_previousCurvature = Curvature; } if (m_previousFlatten != Flatten) { if (Flatten < 0) { Flatten = 0; } HBUtils.HBFlatten(Flatten); m_previousFlatten = Flatten; } if (m_previousHorizonZOffset != HorizonZOffset || m_previousHorizonYOffset != HorizonYOffset || m_previousHorizonXOffset != HorizonXOffset || positionChanged) { if (AttachToCamera) { HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset); } else { HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset, transform); } m_previousHorizonZOffset = HorizonZOffset; m_previousHorizonYOffset = HorizonYOffset; m_previousHorizonXOffset = HorizonXOffset; } if (m_previousMode != BendingMode) { HBUtils.HBMode(BendingMode); m_previousMode = BendingMode; } if (m_prevCameraTracking != AttachToCamera) { if (AttachToCamera) { HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset); } else { HBUtils.HBHorizonOffset(HorizonXOffset, HorizonYOffset, HorizonZOffset, transform); } m_prevCameraTracking = AttachToCamera; } }
public static Vector3 GetOffset(HBSettings settings, float radius) { Vector3 atPoint = Vector3.Scale(new Vector3(settings.HorizonXOffset, settings.HorizonYOffset, settings.HorizonZOffset), settings.Mask) + settings.Gradient * radius; return(HBUtils.GetOffset(atPoint, settings, null)); }