├── .gitignore ├── Assets ├── BVH.png ├── BVH.png.meta ├── Grid.png ├── Grid.png.meta ├── MeshCollider.png ├── MeshCollider.png.meta ├── Models.meta ├── Models │ ├── model.FBX │ ├── model.FBX.meta │ ├── pig.OBJ │ ├── pig.OBJ.meta │ ├── quad.obj │ └── quad.obj.meta ├── Plugins.meta ├── Plugins │ ├── Editor.meta │ └── Editor │ │ ├── JetBrains.meta │ │ └── JetBrains │ │ ├── JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll │ │ └── JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta ├── Scenes.meta ├── Scenes │ ├── SampleScene.unity │ ├── SampleScene.unity.meta │ ├── SubDivision.unity │ └── SubDivision.unity.meta ├── Scripts.meta └── Scripts │ ├── AABB.cs │ ├── AABB.cs.meta │ ├── AABBCollider.cs │ ├── AABBCollider.cs.meta │ ├── BVH.cs │ ├── BVH.cs.meta │ ├── BVHAccelerator.cs │ ├── BVHAccelerator.cs.meta │ ├── Box.cs │ ├── Box.cs.meta │ ├── BoxCollider.cs │ ├── BoxCollider.cs.meta │ ├── CameraHelper.cs │ ├── CameraHelper.cs.meta │ ├── Enum.cs │ ├── Enum.cs.meta │ ├── Grid.cs │ ├── Grid.cs.meta │ ├── GridAccelerator.cs │ ├── GridAccelerator.cs.meta │ ├── MathUtil.cs │ ├── MathUtil.cs.meta │ ├── MeshCollider.cs │ ├── MeshCollider.cs.meta │ ├── OBB.cs │ ├── OBB.cs.meta │ ├── OBBCollider.cs │ ├── OBBCollider.cs.meta │ ├── Ray.cs │ ├── Ray.cs.meta │ ├── Sphere.cs │ ├── Sphere.cs.meta │ ├── SphereCollider.cs │ ├── SphereCollider.cs.meta │ ├── SubDivision.cs │ ├── SubDivision.cs.meta │ ├── Test.cs │ ├── Test.cs.meta │ ├── Util.cs │ └── Util.cs.meta ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── PresetManager.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset └── UnityConnectSettings.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /Library/* 2 | /Temp/* 3 | /Packages/* 4 | /obj/* 5 | /.vs/* 6 | /.idea/* 7 | *.csproj 8 | *.sln 9 | *.user 10 | /ProjectSettings/ProjectVersion.txt 11 | -------------------------------------------------------------------------------- /Assets/BVH.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBLRADISH/UnityCollisionDetection/a2edd3021444b9d7b1c354cb26fb4fa0f8008e8e/Assets/BVH.png -------------------------------------------------------------------------------- /Assets/BVH.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1641100f9db00b74da69131029052f0a 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 7 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBLRADISH/UnityCollisionDetection/a2edd3021444b9d7b1c354cb26fb4fa0f8008e8e/Assets/Grid.png -------------------------------------------------------------------------------- /Assets/Grid.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 896308bfd8b074c4e9061700fcf1aae3 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 7 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/MeshCollider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBLRADISH/UnityCollisionDetection/a2edd3021444b9d7b1c354cb26fb4fa0f8008e8e/Assets/MeshCollider.png -------------------------------------------------------------------------------- /Assets/MeshCollider.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93629b3b02bd56a45a6db2710fe1f6ba 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | externalObjects: {} 6 | serializedVersion: 7 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 1 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | grayScaleToAlpha: 0 27 | generateCubemap: 6 28 | cubemapConvolution: 0 29 | seamlessCubemap: 0 30 | textureFormat: 1 31 | maxTextureSize: 2048 32 | textureSettings: 33 | serializedVersion: 2 34 | filterMode: -1 35 | aniso: -1 36 | mipBias: -100 37 | wrapU: -1 38 | wrapV: -1 39 | wrapW: -1 40 | nPOTScale: 1 41 | lightmap: 0 42 | compressionQuality: 50 43 | spriteMode: 0 44 | spriteExtrude: 1 45 | spriteMeshType: 1 46 | alignment: 0 47 | spritePivot: {x: 0.5, y: 0.5} 48 | spritePixelsToUnits: 100 49 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 50 | spriteGenerateFallbackPhysicsShape: 1 51 | alphaUsage: 1 52 | alphaIsTransparency: 0 53 | spriteTessellationDetail: -1 54 | textureType: 0 55 | textureShape: 1 56 | singleChannelComponent: 0 57 | maxTextureSizeSet: 0 58 | compressionQualitySet: 0 59 | textureFormatSet: 0 60 | platformSettings: 61 | - serializedVersion: 2 62 | buildTarget: DefaultTexturePlatform 63 | maxTextureSize: 2048 64 | resizeAlgorithm: 0 65 | textureFormat: -1 66 | textureCompression: 1 67 | compressionQuality: 50 68 | crunchedCompression: 0 69 | allowsAlphaSplitting: 0 70 | overridden: 0 71 | androidETC2FallbackOverride: 0 72 | spriteSheet: 73 | serializedVersion: 2 74 | sprites: [] 75 | outline: [] 76 | physicsShape: [] 77 | bones: [] 78 | spriteID: 79 | vertices: [] 80 | indices: 81 | edges: [] 82 | weights: [] 83 | spritePackingTag: 84 | pSDRemoveMatte: 0 85 | pSDShowRemoveMatteOption: 0 86 | userData: 87 | assetBundleName: 88 | assetBundleVariant: 89 | -------------------------------------------------------------------------------- /Assets/Models.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c8ce9b8c06398d46a7674bacf0597b5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Models/model.FBX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBLRADISH/UnityCollisionDetection/a2edd3021444b9d7b1c354cb26fb4fa0f8008e8e/Assets/Models/model.FBX -------------------------------------------------------------------------------- /Assets/Models/model.FBX.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ae648bf9e53d8fa498c98ac697af94a1 3 | ModelImporter: 4 | serializedVersion: 23 5 | fileIDToRecycleName: 6 | 100000: b_cloth 7 | 100002: b_cloth_b 8 | 100004: b_cloth_c 9 | 100006: BUFFBONE_CSTM_WEAPON_1 10 | 100008: BUFFBONE_CSTM_WEAPON_2 11 | 100010: BUFFBONE_GLB_CHANNEL_LOC 12 | 100012: BUFFBONE_GLB_GROUND_LOC 13 | 100014: BUFFBONE_GLB_WEAPON_1 14 | 100016: C_BUFFBONE_GLB_CENTER_LOC 15 | 100018: C_BUFFBONE_GLB_CHEST_LOC 16 | 100020: C_BUFFBONE_GLB_HEAD_LOC 17 | 100022: C_BUFFBONE_GLB_LAYOUT_LOC 18 | 100024: C_BUFFBONE_GLB_OVERHEAD_LOC 19 | 100026: head 20 | 100028: L_arm 21 | 100030: L_BUFFBONE_GLB_FOOT_LOC 22 | 100032: L_BUFFBONE_GLB_HAND_LOC 23 | 100034: L_calf 24 | 100036: L_cloth 25 | 100038: L_cloth_b 26 | 100040: L_cloth_c 27 | 100042: L_finger 28 | 100044: L_finger_b 29 | 100046: L_foot 30 | 100048: L_forarm 31 | 100050: L_hand 32 | 100052: L_PARENTING_HAND_LOC 33 | 100054: L_shoulder 34 | 100056: L_thigh 35 | 100058: L_thumb 36 | 100060: L_toe 37 | 100062: Model 38 | 100064: pelvis 39 | 100066: R_arm 40 | 100068: R_BUFFBONE_GLB_FOOT_LOC 41 | 100070: R_BUFFBONE_GLB_HAND_LOC 42 | 100072: R_calf 43 | 100074: R_cloth 44 | 100076: R_cloth_b 45 | 100078: R_cloth_c 46 | 100080: R_finger 47 | 100082: R_finger_b 48 | 100084: R_foot 49 | 100086: R_forarm 50 | 100088: R_hand 51 | 100090: R_PARENTING_HAND_LOC 52 | 100092: R_shoulder 53 | 100094: R_thigh 54 | 100096: R_thumb 55 | 100098: R_toe 56 | 100100: root 57 | 100102: spine 58 | 100104: weapon 59 | 100106: weaponstreak 60 | 100108: //RootNode 61 | 400000: b_cloth 62 | 400002: b_cloth_b 63 | 400004: b_cloth_c 64 | 400006: BUFFBONE_CSTM_WEAPON_1 65 | 400008: BUFFBONE_CSTM_WEAPON_2 66 | 400010: BUFFBONE_GLB_CHANNEL_LOC 67 | 400012: BUFFBONE_GLB_GROUND_LOC 68 | 400014: BUFFBONE_GLB_WEAPON_1 69 | 400016: C_BUFFBONE_GLB_CENTER_LOC 70 | 400018: C_BUFFBONE_GLB_CHEST_LOC 71 | 400020: C_BUFFBONE_GLB_HEAD_LOC 72 | 400022: C_BUFFBONE_GLB_LAYOUT_LOC 73 | 400024: C_BUFFBONE_GLB_OVERHEAD_LOC 74 | 400026: head 75 | 400028: L_arm 76 | 400030: L_BUFFBONE_GLB_FOOT_LOC 77 | 400032: L_BUFFBONE_GLB_HAND_LOC 78 | 400034: L_calf 79 | 400036: L_cloth 80 | 400038: L_cloth_b 81 | 400040: L_cloth_c 82 | 400042: L_finger 83 | 400044: L_finger_b 84 | 400046: L_foot 85 | 400048: L_forarm 86 | 400050: L_hand 87 | 400052: L_PARENTING_HAND_LOC 88 | 400054: L_shoulder 89 | 400056: L_thigh 90 | 400058: L_thumb 91 | 400060: L_toe 92 | 400062: Model 93 | 400064: pelvis 94 | 400066: R_arm 95 | 400068: R_BUFFBONE_GLB_FOOT_LOC 96 | 400070: R_BUFFBONE_GLB_HAND_LOC 97 | 400072: R_calf 98 | 400074: R_cloth 99 | 400076: R_cloth_b 100 | 400078: R_cloth_c 101 | 400080: R_finger 102 | 400082: R_finger_b 103 | 400084: R_foot 104 | 400086: R_forarm 105 | 400088: R_hand 106 | 400090: R_PARENTING_HAND_LOC 107 | 400092: R_shoulder 108 | 400094: R_thigh 109 | 400096: R_thumb 110 | 400098: R_toe 111 | 400100: root 112 | 400102: spine 113 | 400104: weapon 114 | 400106: weaponstreak 115 | 400108: //RootNode 116 | 2100000: 01 - Default 117 | 4300000: Model 118 | 7400000: Take 001 119 | 9500000: //RootNode 120 | 13700000: Model 121 | externalObjects: {} 122 | materials: 123 | importMaterials: 1 124 | materialName: 0 125 | materialSearch: 1 126 | materialLocation: 1 127 | animations: 128 | legacyGenerateAnimations: 4 129 | bakeSimulation: 0 130 | resampleCurves: 1 131 | optimizeGameObjects: 0 132 | motionNodeName: 133 | rigImportErrors: 134 | rigImportWarnings: 135 | animationImportErrors: 136 | animationImportWarnings: 137 | animationRetargetingWarnings: 138 | animationDoRetargetingWarnings: 0 139 | importAnimatedCustomProperties: 0 140 | importConstraints: 0 141 | animationCompression: 1 142 | animationRotationError: 0.5 143 | animationPositionError: 0.5 144 | animationScaleError: 0.5 145 | animationWrapMode: 0 146 | extraExposedTransformPaths: [] 147 | extraUserProperties: [] 148 | clipAnimations: [] 149 | isReadable: 1 150 | meshes: 151 | lODScreenPercentages: [] 152 | globalScale: 1 153 | meshCompression: 0 154 | addColliders: 0 155 | importVisibility: 1 156 | importBlendShapes: 1 157 | importCameras: 1 158 | importLights: 1 159 | swapUVChannels: 0 160 | generateSecondaryUV: 0 161 | useFileUnits: 1 162 | optimizeMeshForGPU: 1 163 | keepQuads: 0 164 | weldVertices: 1 165 | preserveHierarchy: 0 166 | indexFormat: 0 167 | secondaryUVAngleDistortion: 8 168 | secondaryUVAreaDistortion: 15.000001 169 | secondaryUVHardAngle: 88 170 | secondaryUVPackMargin: 4 171 | useFileScale: 0 172 | previousCalculatedGlobalScale: 0.01 173 | hasPreviousCalculatedGlobalScale: 1 174 | tangentSpace: 175 | normalSmoothAngle: 60 176 | normalImportMode: 0 177 | tangentImportMode: 3 178 | normalCalculationMode: 4 179 | importAnimation: 1 180 | copyAvatar: 0 181 | humanDescription: 182 | serializedVersion: 2 183 | human: [] 184 | skeleton: [] 185 | armTwist: 0.5 186 | foreArmTwist: 0.5 187 | upperLegTwist: 0.5 188 | legTwist: 0.5 189 | armStretch: 0.05 190 | legStretch: 0.05 191 | feetSpacing: 0 192 | rootMotionBoneName: 193 | rootMotionBoneRotation: {x: 0, y: 0, z: 0, w: 1} 194 | hasTranslationDoF: 0 195 | hasExtraRoot: 0 196 | skeletonHasParents: 1 197 | lastHumanDescriptionAvatarSource: {instanceID: 0} 198 | animationType: 2 199 | humanoidOversampling: 1 200 | additionalBone: 0 201 | userData: 202 | assetBundleName: 203 | assetBundleVariant: 204 | -------------------------------------------------------------------------------- /Assets/Models/pig.OBJ: -------------------------------------------------------------------------------- 1 | # File exported by ZBrush version 2018 2 | # www.zbrush.com 3 | #Vertex Count 173 4 | #Face Count 357 5 | #Auto scale x=1.000000 y=1.000000 z=1.000000 6 | #Auto offset x=-0.000000 y=-0.000000 z=-0.000000 7 | v -0.87959867 -2.17173695 -0.26870149 8 | v -0.61327022 -1.67510891 -0.4985935 9 | v -0.73250705 -1.07259488 -0.39736169 10 | v -0.76251202 -1.36721563 -0.685135 11 | v -0.94614327 -1.09459888 -0.91893577 12 | v -0.61776787 -1.84985351 -0.91792124 13 | v -0.79341298 -1.27312517 -0.71070319 14 | v -1.13989865 -1.54223859 -1.27369701 15 | v -0.77686077 -0.06898501 -1.72750997 16 | v -0.7332018 -1.38029956 -0.66892671 17 | v -0.75732559 -1.36108195 -0.68948614 18 | v 0.03426686 -1.95561516 -2.17714095 19 | v -0.19071498 -1.71068334 -2.40196061 20 | v -0.00509164 -1.69807314 -2.35717058 21 | v -0.02176649 -1.87428796 -2.43080377 22 | v -0.2245823 -1.66241848 -2.44992828 23 | v -0.08173031 -1.7943362 -2.41721892 24 | v -0.1523962 -1.59134256 -2.42654562 25 | v -0.30270737 -1.69870495 -2.47772646 26 | v -0.20650948 -1.46159744 -2.51361799 27 | v -0.03192937 -1.38569676 -2.49163556 28 | v 0.17722983 -1.46360552 -2.48250627 29 | v 0.09401644 -1.4524672 -2.5308783 30 | v 0.11016343 -1.43528735 -2.57731008 31 | v -0.28990608 -1.5259428 -2.45523214 32 | v -0.18801975 -1.52213752 -2.46154642 33 | v -0.3154084 -1.74686861 -2.38454341 34 | v -0.01212646 -1.61394071 -2.43720722 35 | v -0.23059639 -1.78871238 -2.33957409 36 | v -0.49483475 -1.97466075 -2.18002057 37 | v -0.23278164 -2.04258251 -2.21060562 38 | v 0.11018867 -1.43558776 -2.57716822 39 | v 0.11016959 -1.43537235 -2.57727408 40 | v 0.04242134 1.478266 -0.30204144 41 | v 0.24413552 1.42385542 0.48176002 42 | v 0.09636045 0.42453312 0.95161443 43 | v -0.46711117 -1.14545941 -2.50080347 44 | v 0.37663358 -1.23023402 -2.51123356 45 | v 0.7897095 -0.12389423 -1.73757422 46 | v -1.22564506 0.90621328 -0.30643627 47 | v 0.15326243 -2.01348042 -0.66339504 48 | v 0.54488575 -0.20231224 0.14564201 49 | v 0.94217878 -1.11510944 -0.89974951 50 | v -0.74887228 -0.14012312 0.76215058 51 | v 0.36002349 0.707111 1.02795469 52 | v 0.45558565 -0.25348824 -2.16553926 53 | v 0.64518839 -1.8277688 -0.88253426 54 | v 0.00140146 0.19727355 -1.76153409 55 | v -0.85432237 -0.27262651 -0.62578809 56 | v 0.5961712 -2.12005376 -1.47073066 57 | v -0.40941765 -1.95035767 0.05087828 58 | v 0.40893027 0.4141643 -1.54908955 59 | v -0.62744289 -1.02955842 0.14274758 60 | v -0.76057159 -1.63024854 -2.08340048 61 | v -0.39586424 -1.37030518 -0.28937503 62 | v -0.22010368 -1.08901453 -0.06284637 63 | v -0.97066074 -1.79128432 -1.0956155 64 | v 0.78980869 0.72425264 -0.06078674 65 | v 0.84333318 -1.86380708 -1.85805022 66 | v 0.62539809 0.52184575 -0.88962894 67 | v -1.26032245 0.44093939 0.59656983 68 | v -0.61679959 -2.10581588 -1.47813665 69 | v 0.75934243 0.05539483 -0.42217609 70 | v -0.83233106 0.10947831 -0.94197136 71 | v -0.65887135 1.00867283 0.80795753 72 | v 0.34071514 -1.33688175 -0.25143891 73 | v -0.91908896 -0.99343717 -1.84139299 74 | v 1.53534877 -2.01891231 -0.04051253 75 | v -1.8103609 0.78890043 -0.79297405 76 | v 0.29685413 -0.04697482 0.90240973 77 | v 0.98892307 -1.78764653 -1.07957673 78 | v -0.54861861 0.59009867 -1.13094162 79 | v 1.25710606 -1.50958216 -0.83008992 80 | v -1.10317695 -1.82914161 -0.55619901 81 | v -0.79545766 1.35280334 0.32390043 82 | v 0.77892833 -1.28651332 -0.63426119 83 | v -0.05697726 1.04900431 0.949988 84 | v 0.8433603 -0.74291706 -0.29999131 85 | v -0.66773933 0.97130727 1.36673247 86 | v 0.34796083 -2.0546987 -2.21443033 87 | v 0.31417664 0.63615524 -1.03920853 88 | v -0.74303644 0.56439 1.43410301 89 | v -0.98236793 -0.65795451 -1.0991162 90 | v -0.86070036 1.19406247 -0.32612302 91 | v -0.03088078 0.56870883 1.53679585 92 | v 0.33038178 1.12679135 -0.76583921 93 | v 0.91196298 -0.92513513 -1.84269225 94 | v 0.68394374 -1.58198213 0.09356415 95 | v -1.12377083 1.21871948 0.01750937 96 | v -0.77658975 -1.77659916 -0.25085818 97 | v 0.10120493 -1.96457612 0.14328782 98 | v 0.51659095 1.2650783 -0.11310288 99 | v -0.24862897 -0.29488694 1.00674784 100 | v -1.12227535 1.49694454 -0.27781769 101 | v 0.37945213 -1.66180658 -0.07471286 102 | v 0.4517216 0.96262621 0.55725288 103 | v -0.59554374 -1.85461258 0.16984459 104 | v -1.02498126 0.71546918 -0.40289181 105 | v 0.71457517 -1.16754162 -0.39226028 106 | v 1.10346448 0.72210902 0.01983075 107 | v -0.03228504 -0.38848802 0.51590317 108 | v -1.11301767 -1.24734413 -0.94213753 109 | v -0.2938852 0.04746069 1.2654581 110 | v -0.41741791 1.10186159 -0.85487222 111 | v -0.81751972 -0.70630198 -0.30028021 112 | v 0.7626481 0.45244959 0.7157092 113 | v 0.9867866 -0.64510232 -1.04427492 114 | v -0.29748046 -1.24175548 0.28712138 115 | v -0.6994459 0.42840051 0.86066228 116 | v 0.92408955 -1.31708645 -1.62585842 117 | v -1.46902227 0.82672226 -0.81181812 118 | v 0.4998658 -0.6022343 -0.00780914 119 | v 1.62773454 1.00890374 -0.29020357 120 | v -0.62334919 -2.00304603 0.16331304 121 | v -0.73337948 -0.93896925 -2.23115015 122 | v -0.28312057 1.01872587 1.51108205 123 | v 1.23801815 -2.14796352 -0.14401727 124 | v -0.21299772 -1.5604006 0.19332242 125 | v -0.01635427 -2.11142563 -1.65324878 126 | v -0.9607861 -1.99800372 0.11953522 127 | v 0.66695177 -1.00328958 0.1012163 128 | v -0.97058123 0.60075593 0.79372501 129 | v -0.45977672 -0.50289285 -2.3023858 130 | v 0.4123831 -2.02819609 0.52147024 131 | v 1.32066249 0.90208375 -0.39823618 132 | v 0.4763326 -1.98824358 0.03172789 133 | v -0.28352692 1.49419546 0.30139166 134 | v 0.24162311 -1.53484857 0.2755928 135 | v -1.51289153 1.28678166 -0.61769259 136 | v 0.79526668 0.59950417 -0.49384295 137 | v -1.38582265 1.28896832 -0.74174159 138 | v 1.09646439 1.49849879 -0.34093812 139 | v 0.8314507 0.09753659 -0.99039363 140 | v 0.70508486 1.61877 -0.00618681 141 | v -0.8200646 -0.26778477 -0.1529053 142 | v -0.85663342 -1.88026869 -1.72510278 143 | v -0.64066517 -2.06263852 -0.27531105 144 | v 1.27476584 -1.92248249 0.24659979 145 | v -0.39419397 1.456519 -0.28310892 146 | v 0.27760532 -0.68448084 0.01236156 147 | v 0.61053937 0.67356056 0.95651161 148 | v -0.50596475 -1.6578536 0.35107004 149 | v -0.24252404 -0.7389099 -0.00211336 150 | v -1.15873491 0.63177353 -0.0232528 151 | v 0.69915956 -1.44884991 -2.23491549 152 | v 0.83677369 1.2166332 -0.00257054 153 | v 0.11633212 -2.02507138 0.48650628 154 | v -0.55280017 -0.62232387 -0.04446756 155 | v 0.68883889 1.29146087 0.28157663 156 | v -0.05618671 -1.99789118 0.20766718 157 | v 1.3767476 -1.76337337 -0.22236551 158 | v -0.32752311 -1.91220116 -0.64527416 159 | v -0.23122465 -1.74626648 0.47195291 160 | v 1.11480116 -1.91482138 -0.14676043 161 | v -1.59330499 0.59575927 -0.69772893 162 | v 0.50903922 1.26869547 0.25874054 163 | v -0.41603294 -2.07075476 0.55613857 164 | v -0.87095183 -1.34713232 -1.75541293 165 | v 0.0190129 -1.71030116 -0.38433679 166 | v -0.51201182 -0.35609972 0.22819194 167 | v 0.6904121 0.796368 0.27516943 168 | v 1.18517506 1.48216879 -0.22554209 169 | v 0.79789125 0.11514516 0.02471446 170 | v -0.29791843 0.24909795 -1.77925229 171 | v -0.70818859 0.40634876 1.15907573 172 | v -0.95298177 1.18105065 0.03804242 173 | v 0.40212389 -0.78443038 -2.43019199 174 | v 0.00670843 -1.20707786 -0.19340862 175 | v 0.72088253 -0.90636342 -2.25152778 176 | v -1.10154914 0.52438116 -0.22028833 177 | v -0.97262102 -1.89291 -0.2287224 178 | v -0.34482762 1.15389967 0.86985158 179 | v 0.23540824 -1.1000545 -0.07362595 180 | g Group16646 181 | f 112 78 63 182 | f 92 86 34 183 | f 55 152 159 184 | f 90 2 10 185 | f 90 10 5 186 | f 10 3 7 187 | f 10 6 3 188 | f 2 4 10 189 | f 3 5 7 190 | f 10 11 5 191 | f 11 10 7 192 | f 2 7 5 193 | f 2 5 4 194 | f 4 5 11 195 | f 4 11 6 196 | f 4 6 10 197 | f 1 6 137 198 | f 6 11 7 199 | f 6 7 2 200 | f 49 83 105 201 | f 102 8 74 202 | f 57 6 1 203 | f 41 152 62 204 | f 6 57 62 205 | f 83 9 67 206 | f 158 8 102 207 | f 54 136 8 208 | f 62 31 119 209 | f 123 48 46 210 | f 14 12 29 211 | f 14 22 80 212 | f 80 22 38 213 | f 29 18 14 214 | f 28 22 14 215 | f 30 25 29 216 | f 26 18 29 217 | f 26 29 25 218 | f 26 28 18 219 | f 26 22 28 220 | f 31 29 12 221 | f 29 27 30 222 | f 13 29 31 223 | f 31 30 27 224 | f 14 17 31 225 | f 14 18 13 226 | f 18 27 13 227 | f 31 15 14 228 | f 16 27 18 229 | f 14 13 16 230 | f 14 16 17 231 | f 31 17 13 232 | f 14 15 28 233 | f 27 19 31 234 | f 29 13 27 235 | f 16 18 28 236 | f 28 17 16 237 | f 17 28 15 238 | f 19 15 31 239 | f 15 19 17 240 | f 19 13 17 241 | f 25 27 26 242 | f 19 16 13 243 | f 27 16 26 244 | f 27 25 19 245 | f 20 25 21 246 | f 26 20 22 247 | f 25 20 19 248 | f 19 26 16 249 | f 20 26 19 250 | f 23 20 21 251 | f 20 23 22 252 | f 32 21 33 253 | f 33 21 24 254 | f 24 21 22 255 | f 24 22 32 256 | f 23 21 32 257 | f 22 23 32 258 | f 144 65 75 259 | f 123 9 164 260 | f 172 75 65 261 | f 163 106 42 262 | f 141 36 70 263 | f 109 122 44 264 | f 25 37 21 265 | f 37 25 30 266 | f 21 38 22 267 | f 37 38 21 268 | f 39 107 87 269 | f 60 86 130 270 | f 98 72 64 271 | f 49 135 61 272 | f 41 62 119 273 | f 59 110 73 274 | f 140 143 168 275 | f 61 135 44 276 | f 41 50 47 277 | f 168 55 159 278 | f 106 70 42 279 | f 140 101 143 280 | f 116 45 77 281 | f 130 106 163 282 | f 169 46 39 283 | f 167 123 46 284 | f 47 50 71 285 | f 133 78 107 286 | f 84 72 98 287 | f 86 104 34 288 | f 64 9 83 289 | f 64 72 9 290 | f 119 50 41 291 | f 80 145 59 292 | f 6 55 3 293 | f 105 135 49 294 | f 46 52 39 295 | f 52 46 48 296 | f 53 105 97 297 | f 168 56 55 298 | f 37 30 54 299 | f 9 115 67 300 | f 51 3 55 301 | f 118 55 56 302 | f 101 160 143 303 | f 108 53 142 304 | f 8 57 74 305 | f 8 136 57 306 | f 77 141 96 307 | f 35 92 34 308 | f 50 80 59 309 | f 50 59 71 310 | f 60 39 52 311 | f 39 133 107 312 | f 61 170 49 313 | f 144 61 65 314 | f 62 30 31 315 | f 57 136 62 316 | f 133 63 78 317 | f 60 130 63 318 | f 49 64 83 319 | f 64 49 170 320 | f 165 82 122 321 | f 85 36 45 322 | f 41 47 66 323 | f 154 76 47 324 | f 67 158 5 325 | f 67 115 54 326 | f 76 151 43 327 | f 47 71 117 328 | f 104 84 139 329 | f 34 127 35 330 | f 70 36 103 331 | f 160 101 93 332 | f 110 43 73 333 | f 151 73 43 334 | f 81 48 72 335 | f 164 9 72 336 | f 71 59 73 337 | f 71 73 68 338 | f 57 1 74 339 | f 137 114 1 340 | f 84 75 139 341 | f 75 166 144 342 | f 66 47 76 343 | f 121 78 112 344 | f 77 96 35 345 | f 127 172 35 346 | f 78 99 43 347 | f 99 78 88 348 | f 172 65 79 349 | f 82 65 122 350 | f 12 14 80 351 | f 119 80 50 352 | f 52 48 81 353 | f 52 81 60 354 | f 65 82 79 355 | f 116 85 45 356 | f 105 83 5 357 | f 83 67 5 358 | f 111 84 98 359 | f 84 166 75 360 | f 85 82 165 361 | f 82 85 116 362 | f 81 72 86 363 | f 60 81 86 364 | f 169 39 87 365 | f 145 110 59 366 | f 140 173 128 367 | f 66 99 95 368 | f 129 69 40 369 | f 84 111 131 370 | f 90 5 171 371 | f 114 120 1 372 | f 140 128 124 373 | f 95 99 88 374 | f 86 92 130 375 | f 35 96 156 376 | f 160 93 44 377 | f 44 103 109 378 | f 166 84 94 379 | f 89 129 40 380 | f 128 173 95 381 | f 147 126 124 382 | f 161 58 100 383 | f 106 58 161 384 | f 3 51 97 385 | f 108 142 118 386 | f 170 144 155 387 | f 144 170 61 388 | f 99 66 76 389 | f 99 76 43 390 | f 58 92 125 391 | f 92 35 156 392 | f 101 42 70 393 | f 70 93 101 394 | f 102 5 158 395 | f 171 5 102 396 | f 103 93 70 397 | f 103 44 93 398 | f 104 86 72 399 | f 104 72 84 400 | f 5 3 105 401 | f 3 97 105 402 | f 106 161 141 403 | f 70 106 141 404 | f 107 78 43 405 | f 43 87 107 406 | f 143 108 118 407 | f 53 108 143 408 | f 109 103 36 409 | f 85 165 36 410 | f 87 110 145 411 | f 87 43 110 412 | f 155 111 98 413 | f 69 131 111 414 | f 63 42 112 415 | f 101 140 42 416 | f 132 125 92 417 | f 149 161 100 418 | f 90 114 137 419 | f 90 120 114 420 | f 54 115 37 421 | f 123 38 37 422 | f 79 116 172 423 | f 116 79 82 424 | f 71 68 117 425 | f 151 76 154 426 | f 51 55 118 427 | f 157 51 150 428 | f 119 31 12 429 | f 12 80 119 430 | f 120 171 1 431 | f 171 120 90 432 | f 124 121 140 433 | f 121 88 78 434 | f 122 65 61 435 | f 44 122 61 436 | f 115 123 37 437 | f 9 123 115 438 | f 121 124 88 439 | f 88 124 126 440 | f 125 100 58 441 | f 125 113 100 442 | f 91 95 126 443 | f 95 88 126 444 | f 139 75 127 445 | f 75 172 127 446 | f 128 95 91 447 | f 124 128 147 448 | f 89 94 129 449 | f 94 84 131 450 | f 130 58 106 451 | f 130 92 58 452 | f 69 129 131 453 | f 129 94 131 454 | f 132 113 125 455 | f 100 113 146 456 | f 63 133 60 457 | f 39 60 133 458 | f 92 134 132 459 | f 113 162 146 460 | f 148 135 105 461 | f 143 160 148 462 | f 62 136 30 463 | f 30 136 54 464 | f 2 137 6 465 | f 2 90 137 466 | f 68 138 117 467 | f 154 47 117 468 | f 34 139 127 469 | f 104 139 34 470 | f 121 112 140 471 | f 112 42 140 472 | f 45 141 77 473 | f 141 45 36 474 | f 97 142 53 475 | f 97 51 157 476 | f 143 56 168 477 | f 143 118 56 478 | f 144 89 40 479 | f 144 40 69 480 | f 80 38 145 481 | f 169 167 46 482 | f 146 162 149 483 | f 146 149 100 484 | f 128 91 147 485 | f 147 91 126 486 | f 148 105 53 487 | f 53 143 148 488 | f 149 162 134 489 | f 156 134 92 490 | f 51 118 150 491 | f 153 118 142 492 | f 73 151 68 493 | f 151 138 68 494 | f 55 6 152 495 | f 152 6 62 496 | f 153 150 118 497 | f 150 153 157 498 | f 117 138 154 499 | f 154 138 151 500 | f 69 111 155 501 | f 155 144 69 502 | f 134 156 149 503 | f 161 149 156 504 | f 157 153 142 505 | f 142 97 157 506 | f 67 54 158 507 | f 8 158 54 508 | f 152 41 159 509 | f 159 41 66 510 | f 135 148 160 511 | f 44 135 160 512 | f 141 161 96 513 | f 156 96 161 514 | f 134 162 132 515 | f 113 132 162 516 | f 42 63 163 517 | f 163 63 130 518 | f 48 164 72 519 | f 164 48 123 520 | f 165 122 109 521 | f 165 109 36 522 | f 144 166 89 523 | f 89 166 94 524 | f 167 169 38 525 | f 123 167 38 526 | f 159 66 168 527 | f 173 66 95 528 | f 145 169 87 529 | f 38 169 145 530 | f 98 64 170 531 | f 98 170 155 532 | f 171 102 74 533 | f 74 1 171 534 | f 77 35 172 535 | f 116 77 172 536 | f 66 173 168 537 | f 140 168 173 538 | 539 | -------------------------------------------------------------------------------- /Assets/Models/pig.OBJ.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ffec4785df0c77468481a4caad9d568 3 | ModelImporter: 4 | serializedVersion: 23 5 | fileIDToRecycleName: 6 | 100000: //RootNode 7 | 100002: Group16646 8 | 400000: //RootNode 9 | 400002: Group16646 10 | 2100000: Group16646Mat 11 | 2300000: Group16646 12 | 3300000: Group16646 13 | 4300000: Group16646 14 | 2186277476908879412: ImportLogs 15 | externalObjects: {} 16 | materials: 17 | importMaterials: 1 18 | materialName: 0 19 | materialSearch: 1 20 | materialLocation: 1 21 | animations: 22 | legacyGenerateAnimations: 4 23 | bakeSimulation: 0 24 | resampleCurves: 1 25 | optimizeGameObjects: 0 26 | motionNodeName: 27 | rigImportErrors: 28 | rigImportWarnings: 29 | animationImportErrors: 30 | animationImportWarnings: 31 | animationRetargetingWarnings: 32 | animationDoRetargetingWarnings: 0 33 | importAnimatedCustomProperties: 0 34 | importConstraints: 0 35 | animationCompression: 1 36 | animationRotationError: 0.5 37 | animationPositionError: 0.5 38 | animationScaleError: 0.5 39 | animationWrapMode: 0 40 | extraExposedTransformPaths: [] 41 | extraUserProperties: [] 42 | clipAnimations: [] 43 | isReadable: 1 44 | meshes: 45 | lODScreenPercentages: [] 46 | globalScale: 1 47 | meshCompression: 0 48 | addColliders: 0 49 | importVisibility: 1 50 | importBlendShapes: 1 51 | importCameras: 1 52 | importLights: 1 53 | swapUVChannels: 0 54 | generateSecondaryUV: 0 55 | useFileUnits: 1 56 | optimizeMeshForGPU: 1 57 | keepQuads: 0 58 | weldVertices: 1 59 | preserveHierarchy: 0 60 | indexFormat: 0 61 | secondaryUVAngleDistortion: 8 62 | secondaryUVAreaDistortion: 15.000001 63 | secondaryUVHardAngle: 88 64 | secondaryUVPackMargin: 4 65 | useFileScale: 1 66 | previousCalculatedGlobalScale: 1 67 | hasPreviousCalculatedGlobalScale: 0 68 | tangentSpace: 69 | normalSmoothAngle: 60 70 | normalImportMode: 2 71 | tangentImportMode: 2 72 | normalCalculationMode: 4 73 | importAnimation: 1 74 | copyAvatar: 0 75 | humanDescription: 76 | serializedVersion: 2 77 | human: [] 78 | skeleton: [] 79 | armTwist: 0.5 80 | foreArmTwist: 0.5 81 | upperLegTwist: 0.5 82 | legTwist: 0.5 83 | armStretch: 0.05 84 | legStretch: 0.05 85 | feetSpacing: 0 86 | rootMotionBoneName: 87 | hasTranslationDoF: 0 88 | hasExtraRoot: 0 89 | skeletonHasParents: 1 90 | lastHumanDescriptionAvatarSource: {instanceID: 0} 91 | animationType: 0 92 | humanoidOversampling: 1 93 | additionalBone: 0 94 | userData: 95 | assetBundleName: 96 | assetBundleVariant: 97 | -------------------------------------------------------------------------------- /Assets/Models/quad.obj: -------------------------------------------------------------------------------- 1 | v 1.0 1.0 1.0 2 | v 1.0 1.0 -1.0 3 | v 1.0 -1.0 1.0 4 | v 1.0 -1.0 -1.0 5 | v -1.0 1.0 1.0 6 | v -1.0 1.0 -1.0 7 | v -1.0 -1.0 1.0 8 | v -1.0 -1.0 -1.0 9 | 10 | f 4 8 6 11 | f 6 2 4 12 | #f 6 8 7 13 | #f 7 5 6 14 | #f 1 3 4 15 | #f 4 2 1 16 | #f 1 5 7 17 | #f 7 3 1 18 | #f 1 2 6 19 | #f 6 5 1 20 | #f 4 7 8 21 | #f 3 7 4 22 | -------------------------------------------------------------------------------- /Assets/Models/quad.obj.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89f0fa50948070f4bb0cf04b2ea737a9 3 | ModelImporter: 4 | serializedVersion: 23 5 | fileIDToRecycleName: 6 | 100000: //RootNode 7 | 100002: default 8 | 400000: //RootNode 9 | 400002: default 10 | 2100000: defaultMat 11 | 2300000: default 12 | 3300000: default 13 | 4300000: default 14 | 2186277476908879412: ImportLogs 15 | externalObjects: {} 16 | materials: 17 | importMaterials: 1 18 | materialName: 0 19 | materialSearch: 1 20 | materialLocation: 1 21 | animations: 22 | legacyGenerateAnimations: 4 23 | bakeSimulation: 0 24 | resampleCurves: 1 25 | optimizeGameObjects: 0 26 | motionNodeName: 27 | rigImportErrors: 28 | rigImportWarnings: 29 | animationImportErrors: 30 | animationImportWarnings: 31 | animationRetargetingWarnings: 32 | animationDoRetargetingWarnings: 0 33 | importAnimatedCustomProperties: 0 34 | importConstraints: 0 35 | animationCompression: 1 36 | animationRotationError: 0.5 37 | animationPositionError: 0.5 38 | animationScaleError: 0.5 39 | animationWrapMode: 0 40 | extraExposedTransformPaths: [] 41 | extraUserProperties: [] 42 | clipAnimations: [] 43 | isReadable: 1 44 | meshes: 45 | lODScreenPercentages: [] 46 | globalScale: 1 47 | meshCompression: 0 48 | addColliders: 0 49 | importVisibility: 1 50 | importBlendShapes: 1 51 | importCameras: 1 52 | importLights: 1 53 | swapUVChannels: 0 54 | generateSecondaryUV: 0 55 | useFileUnits: 1 56 | optimizeMeshForGPU: 1 57 | keepQuads: 0 58 | weldVertices: 1 59 | preserveHierarchy: 0 60 | indexFormat: 0 61 | secondaryUVAngleDistortion: 8 62 | secondaryUVAreaDistortion: 15.000001 63 | secondaryUVHardAngle: 88 64 | secondaryUVPackMargin: 4 65 | useFileScale: 1 66 | previousCalculatedGlobalScale: 1 67 | hasPreviousCalculatedGlobalScale: 0 68 | tangentSpace: 69 | normalSmoothAngle: 60 70 | normalImportMode: 2 71 | tangentImportMode: 2 72 | normalCalculationMode: 4 73 | importAnimation: 1 74 | copyAvatar: 0 75 | humanDescription: 76 | serializedVersion: 2 77 | human: [] 78 | skeleton: [] 79 | armTwist: 0.5 80 | foreArmTwist: 0.5 81 | upperLegTwist: 0.5 82 | legTwist: 0.5 83 | armStretch: 0.05 84 | legStretch: 0.05 85 | feetSpacing: 0 86 | rootMotionBoneName: 87 | hasTranslationDoF: 0 88 | hasExtraRoot: 0 89 | skeletonHasParents: 1 90 | lastHumanDescriptionAvatarSource: {instanceID: 0} 91 | animationType: 0 92 | humanoidOversampling: 1 93 | additionalBone: 0 94 | userData: 95 | assetBundleName: 96 | assetBundleVariant: 97 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5dc6c11b56c74cd488d9c5b93aab3e14 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b53f6dc1326718045807ba9e5820b846 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Editor/JetBrains.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ddb6edb8fd20f224989dffa58760065a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JBLRADISH/UnityCollisionDetection/a2edd3021444b9d7b1c354cb26fb4fa0f8008e8e/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll -------------------------------------------------------------------------------- /Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9ccd593cde910a42a81496e3ff29e8e 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | isPreloaded: 0 9 | isOverridable: 0 10 | platformData: 11 | - first: 12 | Any: 13 | second: 14 | enabled: 0 15 | settings: {} 16 | - first: 17 | Editor: Editor 18 | second: 19 | enabled: 1 20 | settings: 21 | DefaultValueInitialized: true 22 | - first: 23 | Windows Store Apps: WindowsStoreApps 24 | second: 25 | enabled: 0 26 | settings: 27 | CPU: AnyCPU 28 | userData: 29 | assetBundleName: 30 | assetBundleVariant: 31 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f704ae4b4f98ae41a0bce26658850c1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/SampleScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99c9720ab356a0642a771bea13969a05 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Scenes/SubDivision.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0.44657844, g: 0.49641222, b: 0.57481694, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 11 47 | m_GIWorkflowMode: 0 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_TemporalCoherenceThreshold: 1 54 | m_EnvironmentLightingMode: 0 55 | m_EnableBakedLightmaps: 1 56 | m_EnableRealtimeLightmaps: 1 57 | m_LightmapEditorSettings: 58 | serializedVersion: 10 59 | m_Resolution: 2 60 | m_BakeResolution: 40 61 | m_AtlasSize: 1024 62 | m_AO: 0 63 | m_AOMaxDistance: 1 64 | m_CompAOExponent: 1 65 | m_CompAOExponentDirect: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 500 79 | m_PVRBounces: 2 80 | m_PVRFilterTypeDirect: 0 81 | m_PVRFilterTypeIndirect: 0 82 | m_PVRFilterTypeAO: 0 83 | m_PVRFilteringMode: 1 84 | m_PVRCulling: 1 85 | m_PVRFilteringGaussRadiusDirect: 1 86 | m_PVRFilteringGaussRadiusIndirect: 5 87 | m_PVRFilteringGaussRadiusAO: 2 88 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 89 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 90 | m_PVRFilteringAtrousPositionSigmaAO: 1 91 | m_ShowResolutionOverlay: 1 92 | m_LightingDataAsset: {fileID: 0} 93 | m_UseShadowmask: 1 94 | --- !u!196 &4 95 | NavMeshSettings: 96 | serializedVersion: 2 97 | m_ObjectHideFlags: 0 98 | m_BuildSettings: 99 | serializedVersion: 2 100 | agentTypeID: 0 101 | agentRadius: 0.5 102 | agentHeight: 2 103 | agentSlope: 45 104 | agentClimb: 0.4 105 | ledgeDropHeight: 0 106 | maxJumpAcrossDistance: 0 107 | minRegionArea: 2 108 | manualCellSize: 0 109 | cellSize: 0.16666667 110 | manualTileSize: 0 111 | tileSize: 256 112 | accuratePlacement: 0 113 | debug: 114 | m_Flags: 0 115 | m_NavMeshData: {fileID: 0} 116 | --- !u!1 &132413034 stripped 117 | GameObject: 118 | m_CorrespondingSourceObject: {fileID: 100002, guid: 89f0fa50948070f4bb0cf04b2ea737a9, 119 | type: 3} 120 | m_PrefabInternal: {fileID: 1881163977} 121 | --- !u!114 &132413036 122 | MonoBehaviour: 123 | m_ObjectHideFlags: 0 124 | m_CorrespondingSourceObject: {fileID: 0} 125 | m_PrefabInternal: {fileID: 0} 126 | m_GameObject: {fileID: 132413034} 127 | m_Enabled: 1 128 | m_EditorHideFlags: 0 129 | m_Script: {fileID: 11500000, guid: 3383699b98ff30146b5b6f5effb88b9e, type: 3} 130 | m_Name: 131 | m_EditorClassIdentifier: 132 | iter: 5 133 | --- !u!1 &270642119 134 | GameObject: 135 | m_ObjectHideFlags: 0 136 | m_CorrespondingSourceObject: {fileID: 0} 137 | m_PrefabInternal: {fileID: 0} 138 | serializedVersion: 6 139 | m_Component: 140 | - component: {fileID: 270642122} 141 | - component: {fileID: 270642121} 142 | - component: {fileID: 270642120} 143 | m_Layer: 0 144 | m_Name: Main Camera 145 | m_TagString: MainCamera 146 | m_Icon: {fileID: 0} 147 | m_NavMeshLayer: 0 148 | m_StaticEditorFlags: 0 149 | m_IsActive: 1 150 | --- !u!81 &270642120 151 | AudioListener: 152 | m_ObjectHideFlags: 0 153 | m_CorrespondingSourceObject: {fileID: 0} 154 | m_PrefabInternal: {fileID: 0} 155 | m_GameObject: {fileID: 270642119} 156 | m_Enabled: 1 157 | --- !u!20 &270642121 158 | Camera: 159 | m_ObjectHideFlags: 0 160 | m_CorrespondingSourceObject: {fileID: 0} 161 | m_PrefabInternal: {fileID: 0} 162 | m_GameObject: {fileID: 270642119} 163 | m_Enabled: 1 164 | serializedVersion: 2 165 | m_ClearFlags: 1 166 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 167 | m_projectionMatrixMode: 1 168 | m_SensorSize: {x: 36, y: 24} 169 | m_LensShift: {x: 0, y: 0} 170 | m_FocalLength: 50 171 | m_NormalizedViewPortRect: 172 | serializedVersion: 2 173 | x: 0 174 | y: 0 175 | width: 1 176 | height: 1 177 | near clip plane: 0.3 178 | far clip plane: 1000 179 | field of view: 60 180 | orthographic: 0 181 | orthographic size: 5 182 | m_Depth: -1 183 | m_CullingMask: 184 | serializedVersion: 2 185 | m_Bits: 4294967295 186 | m_RenderingPath: -1 187 | m_TargetTexture: {fileID: 0} 188 | m_TargetDisplay: 0 189 | m_TargetEye: 3 190 | m_HDR: 1 191 | m_AllowMSAA: 1 192 | m_AllowDynamicResolution: 0 193 | m_ForceIntoRT: 0 194 | m_OcclusionCulling: 1 195 | m_StereoConvergence: 10 196 | m_StereoSeparation: 0.022 197 | --- !u!4 &270642122 198 | Transform: 199 | m_ObjectHideFlags: 0 200 | m_CorrespondingSourceObject: {fileID: 0} 201 | m_PrefabInternal: {fileID: 0} 202 | m_GameObject: {fileID: 270642119} 203 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 204 | m_LocalPosition: {x: 0, y: 1, z: -10} 205 | m_LocalScale: {x: 1, y: 1, z: 1} 206 | m_Children: [] 207 | m_Father: {fileID: 0} 208 | m_RootOrder: 0 209 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 210 | --- !u!1 &521645169 stripped 211 | GameObject: 212 | m_CorrespondingSourceObject: {fileID: 100002, guid: 9ffec4785df0c77468481a4caad9d568, 213 | type: 3} 214 | m_PrefabInternal: {fileID: 1513162669} 215 | --- !u!114 &521645171 216 | MonoBehaviour: 217 | m_ObjectHideFlags: 0 218 | m_CorrespondingSourceObject: {fileID: 0} 219 | m_PrefabInternal: {fileID: 0} 220 | m_GameObject: {fileID: 521645169} 221 | m_Enabled: 1 222 | m_EditorHideFlags: 0 223 | m_Script: {fileID: 11500000, guid: 3383699b98ff30146b5b6f5effb88b9e, type: 3} 224 | m_Name: 225 | m_EditorClassIdentifier: 226 | iter: 4 227 | --- !u!1 &640659082 228 | GameObject: 229 | m_ObjectHideFlags: 0 230 | m_CorrespondingSourceObject: {fileID: 0} 231 | m_PrefabInternal: {fileID: 0} 232 | serializedVersion: 6 233 | m_Component: 234 | - component: {fileID: 640659084} 235 | - component: {fileID: 640659083} 236 | m_Layer: 0 237 | m_Name: Directional Light 238 | m_TagString: Untagged 239 | m_Icon: {fileID: 0} 240 | m_NavMeshLayer: 0 241 | m_StaticEditorFlags: 0 242 | m_IsActive: 1 243 | --- !u!108 &640659083 244 | Light: 245 | m_ObjectHideFlags: 0 246 | m_CorrespondingSourceObject: {fileID: 0} 247 | m_PrefabInternal: {fileID: 0} 248 | m_GameObject: {fileID: 640659082} 249 | m_Enabled: 1 250 | serializedVersion: 8 251 | m_Type: 1 252 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 253 | m_Intensity: 1 254 | m_Range: 10 255 | m_SpotAngle: 30 256 | m_CookieSize: 10 257 | m_Shadows: 258 | m_Type: 2 259 | m_Resolution: -1 260 | m_CustomResolution: -1 261 | m_Strength: 1 262 | m_Bias: 0.05 263 | m_NormalBias: 0.4 264 | m_NearPlane: 0.2 265 | m_Cookie: {fileID: 0} 266 | m_DrawHalo: 0 267 | m_Flare: {fileID: 0} 268 | m_RenderMode: 0 269 | m_CullingMask: 270 | serializedVersion: 2 271 | m_Bits: 4294967295 272 | m_Lightmapping: 4 273 | m_LightShadowCasterMode: 0 274 | m_AreaSize: {x: 1, y: 1} 275 | m_BounceIntensity: 1 276 | m_ColorTemperature: 6570 277 | m_UseColorTemperature: 0 278 | m_ShadowRadius: 0 279 | m_ShadowAngle: 0 280 | --- !u!4 &640659084 281 | Transform: 282 | m_ObjectHideFlags: 0 283 | m_CorrespondingSourceObject: {fileID: 0} 284 | m_PrefabInternal: {fileID: 0} 285 | m_GameObject: {fileID: 640659082} 286 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 287 | m_LocalPosition: {x: 0, y: 3, z: 0} 288 | m_LocalScale: {x: 1, y: 1, z: 1} 289 | m_Children: [] 290 | m_Father: {fileID: 0} 291 | m_RootOrder: 1 292 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 293 | --- !u!1001 &1513162669 294 | Prefab: 295 | m_ObjectHideFlags: 0 296 | serializedVersion: 2 297 | m_Modification: 298 | m_TransformParent: {fileID: 0} 299 | m_Modifications: 300 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 301 | propertyPath: m_LocalPosition.x 302 | value: -0 303 | objectReference: {fileID: 0} 304 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 305 | propertyPath: m_LocalPosition.y 306 | value: 0 307 | objectReference: {fileID: 0} 308 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 309 | propertyPath: m_LocalPosition.z 310 | value: 0 311 | objectReference: {fileID: 0} 312 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 313 | propertyPath: m_LocalRotation.x 314 | value: 0 315 | objectReference: {fileID: 0} 316 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 317 | propertyPath: m_LocalRotation.y 318 | value: -0 319 | objectReference: {fileID: 0} 320 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 321 | propertyPath: m_LocalRotation.z 322 | value: -0 323 | objectReference: {fileID: 0} 324 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 325 | propertyPath: m_LocalRotation.w 326 | value: 1 327 | objectReference: {fileID: 0} 328 | - target: {fileID: 400000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 329 | propertyPath: m_RootOrder 330 | value: 3 331 | objectReference: {fileID: 0} 332 | - target: {fileID: 400002, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 333 | propertyPath: m_LocalPosition.x 334 | value: -3.87 335 | objectReference: {fileID: 0} 336 | m_RemovedComponents: [] 337 | m_SourcePrefab: {fileID: 100100000, guid: 9ffec4785df0c77468481a4caad9d568, type: 3} 338 | m_IsPrefabAsset: 0 339 | --- !u!1001 &1881163977 340 | Prefab: 341 | m_ObjectHideFlags: 0 342 | serializedVersion: 2 343 | m_Modification: 344 | m_TransformParent: {fileID: 0} 345 | m_Modifications: 346 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 347 | propertyPath: m_LocalPosition.x 348 | value: -0 349 | objectReference: {fileID: 0} 350 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 351 | propertyPath: m_LocalPosition.y 352 | value: 0 353 | objectReference: {fileID: 0} 354 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 355 | propertyPath: m_LocalPosition.z 356 | value: 0 357 | objectReference: {fileID: 0} 358 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 359 | propertyPath: m_LocalRotation.x 360 | value: 0 361 | objectReference: {fileID: 0} 362 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 363 | propertyPath: m_LocalRotation.y 364 | value: -0 365 | objectReference: {fileID: 0} 366 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 367 | propertyPath: m_LocalRotation.z 368 | value: -0 369 | objectReference: {fileID: 0} 370 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 371 | propertyPath: m_LocalRotation.w 372 | value: 1 373 | objectReference: {fileID: 0} 374 | - target: {fileID: 400000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 375 | propertyPath: m_RootOrder 376 | value: 2 377 | objectReference: {fileID: 0} 378 | m_RemovedComponents: [] 379 | m_SourcePrefab: {fileID: 100100000, guid: 89f0fa50948070f4bb0cf04b2ea737a9, type: 3} 380 | m_IsPrefabAsset: 0 381 | -------------------------------------------------------------------------------- /Assets/Scenes/SubDivision.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17a459bc6c057044eb39e7d76bd83503 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e41638810a393c243b0e419b51c52fa1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/AABB.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEditor.Experimental.UIElements.GraphView; 5 | using UnityEngine; 6 | using UnityEngine.Experimental.PlayerLoop; 7 | 8 | public class AABB : Box 9 | { 10 | private Vector3 originMin; 11 | private Vector3 originMax; 12 | public Vector3 transformMin; 13 | public Vector3 transformMax; 14 | private Matrix4x4 matrix; 15 | private AABBStructureMode mode; 16 | public int triangle; 17 | 18 | public static AABB Default 19 | { 20 | get { return new AABB(Vector3.positiveInfinity, Vector3.negativeInfinity); } 21 | } 22 | 23 | public AABB(Transform transform) 24 | { 25 | this.transform = transform; 26 | Mesh mesh = transform.GetComponent().sharedMesh; 27 | originMin = originMax = mesh.vertices[0]; 28 | for (int i = 1; i < mesh.vertices.Length; i++) 29 | { 30 | for (int j = 0; j < 3; j++) 31 | { 32 | if (mesh.vertices[i][j] < originMin[j]) 33 | originMin[j] = mesh.vertices[i][j]; 34 | if (mesh.vertices[i][j] > originMax[j]) 35 | originMax[j] = mesh.vertices[i][j]; 36 | } 37 | } 38 | 39 | transformMin = originMin; 40 | transformMax = originMax; 41 | matrix = Matrix4x4.identity; 42 | mode = AABBStructureMode.None; 43 | UpdateAABB(AABBStructureMode.Compact); 44 | } 45 | 46 | public AABB(Vector3 min, Vector3 max) 47 | { 48 | transformMin = min; 49 | transformMax = max; 50 | } 51 | 52 | public void UpdateAABB(AABBStructureMode mode) 53 | { 54 | Matrix4x4 m = transform.localToWorldMatrix; 55 | //只发生平移的话不需要重新计算包围盒,直接加上偏移量即可 56 | if (MathUtil.IsOnlyContainTranslation(matrix, m) && this.mode == mode) 57 | { 58 | Vector3 translation = MathUtil.GetTranslation(matrix, m); 59 | transformMin += translation; 60 | transformMax += translation; 61 | } 62 | else 63 | { 64 | this.mode = mode; 65 | //加速模式:只对max和min进行变换,不保证计算得到的包围盒是紧凑的 66 | if (mode == AABBStructureMode.Accelerate) 67 | { 68 | Vector3 translate = new Vector3(m.m03, m.m13, m.m23); 69 | transformMin = translate; 70 | transformMax = translate; 71 | for (int i = 0; i < 3; i++) 72 | { 73 | for (int j = 0; j < 3; j++) 74 | { 75 | float e = m[j, i] * originMin[i]; 76 | float f = m[j, i] * originMax[i]; 77 | if (e < f) 78 | { 79 | transformMin[j] += e; 80 | transformMax[j] += f; 81 | } 82 | else 83 | { 84 | transformMin[j] += f; 85 | transformMax[j] += e; 86 | } 87 | } 88 | } 89 | } 90 | //紧凑模式:对所有顶点进行变换,计算得到的包围盒是紧凑的 91 | else if (mode == AABBStructureMode.Compact) 92 | { 93 | Mesh mesh = transform.GetComponent().sharedMesh; 94 | List vertices = Util.GetNoRepeatVertices(mesh); 95 | transformMin = transformMax = m * MathUtil.Vector4(vertices[0], 1); 96 | for (int i = 1; i < vertices.Count; i++) 97 | { 98 | for (int j = 0; j < 3; j++) 99 | { 100 | Vector3 tmp = m * MathUtil.Vector4(vertices[i], 1); 101 | if (tmp[j] < transformMin[j]) 102 | transformMin[j] = tmp[j]; 103 | if (tmp[j] > transformMax[j]) 104 | transformMax[j] = tmp[j]; 105 | } 106 | } 107 | } 108 | } 109 | 110 | matrix = m; 111 | } 112 | 113 | public void DrawAABB() 114 | { 115 | Vector3 offset0 = Vector3.right * (transformMax - transformMin).x; 116 | Vector3 offset1 = Vector3.up * (transformMax - transformMin).y; 117 | Vector3 offset2 = Vector3.forward * (transformMax - transformMin).z; 118 | Gizmos.color = Color.yellow; 119 | Gizmos.DrawLine(transformMin, transformMin + offset0); 120 | Gizmos.DrawLine(transformMin, transformMin + offset1); 121 | Gizmos.DrawLine(transformMin, transformMin + offset2); 122 | Gizmos.DrawLine(transformMin + offset0, transformMax - offset2); 123 | Gizmos.DrawLine(transformMin + offset1, transformMax - offset2); 124 | Gizmos.DrawLine(transformMin + offset0, transformMax - offset1); 125 | Gizmos.DrawLine(transformMin + offset2, transformMax - offset1); 126 | Gizmos.DrawLine(transformMin + offset1, transformMax - offset0); 127 | Gizmos.DrawLine(transformMin + offset2, transformMax - offset0); 128 | Gizmos.DrawLine(transformMax, transformMax - offset0); 129 | Gizmos.DrawLine(transformMax, transformMax - offset1); 130 | Gizmos.DrawLine(transformMax, transformMax - offset2); 131 | } 132 | 133 | public override bool RayDetection(Ray ray, RaycastHit hitInfo) 134 | { 135 | float[] t = new float[3]; 136 | for (int i = 0; i < 3; i++) 137 | { 138 | if (ray.origin[i] < transformMin[i]) 139 | { 140 | t[i] = (transformMin[i] - ray.origin[i]); 141 | if (t[i] > ray.distance * ray.direction[i]) 142 | { 143 | return false; 144 | } 145 | 146 | t[i] /= ray.direction[i]; 147 | } 148 | else if (ray.origin[i] > transformMax[i]) 149 | { 150 | t[i] = (transformMax[i] - ray.origin[i]); 151 | if (t[i] < ray.distance * ray.direction[i]) 152 | { 153 | return false; 154 | } 155 | 156 | t[i] /= ray.direction[i]; 157 | } 158 | else 159 | { 160 | t[i] = -1; 161 | } 162 | } 163 | 164 | int idx = 0; 165 | for (int i = 1; i < 3; i++) 166 | { 167 | if (t[i] > t[idx]) 168 | { 169 | idx = i; 170 | } 171 | } 172 | 173 | for (int i = 0; i < 3; i++) 174 | { 175 | if (i == idx) 176 | { 177 | continue; 178 | } 179 | 180 | float tmp = ray.origin[i] + ray.direction[i] * t[idx]; 181 | if (tmp < transformMin[i] || tmp > transformMax[i]) 182 | { 183 | return false; 184 | } 185 | } 186 | 187 | ray.distance = t[idx]; 188 | hitInfo.point = ray.origin + ray.direction * t[idx]; 189 | hitInfo.transform = transform; 190 | return true; 191 | } 192 | 193 | public bool RayDetection(Ray ray, ref float dist) 194 | { 195 | float[] t = new float[3]; 196 | for (int i = 0; i < 3; i++) 197 | { 198 | if (ray.origin[i] < transformMin[i]) 199 | { 200 | t[i] = (transformMin[i] - ray.origin[i]); 201 | if (t[i] > ray.distance * ray.direction[i]) 202 | { 203 | return false; 204 | } 205 | 206 | t[i] /= ray.direction[i]; 207 | } 208 | else if (ray.origin[i] > transformMax[i]) 209 | { 210 | t[i] = (transformMax[i] - ray.origin[i]); 211 | if (t[i] < ray.distance * ray.direction[i]) 212 | { 213 | return false; 214 | } 215 | 216 | t[i] /= ray.direction[i]; 217 | } 218 | else 219 | { 220 | t[i] = -1; 221 | } 222 | } 223 | 224 | int idx = 0; 225 | for (int i = 1; i < 3; i++) 226 | { 227 | if (t[i] > t[idx]) 228 | { 229 | idx = i; 230 | } 231 | } 232 | 233 | for (int i = 0; i < 3; i++) 234 | { 235 | if (i == idx) 236 | { 237 | continue; 238 | } 239 | 240 | float tmp = ray.origin[i] + ray.direction[i] * t[idx]; 241 | if (tmp < transformMin[i] || tmp > transformMax[i]) 242 | { 243 | return false; 244 | } 245 | } 246 | 247 | dist = t[idx]; 248 | return true; 249 | } 250 | 251 | public bool RayDetection(Ray ray) 252 | { 253 | float t = 0; 254 | return RayDetection(ray, ref t); 255 | } 256 | 257 | public override bool BoxDetection(Box box) 258 | { 259 | if (box is AABB) 260 | { 261 | return Util.TestAABBAABB(this, box as AABB); 262 | } 263 | else if (box is Sphere) 264 | { 265 | return Util.TestAABBSphere(this, box as Sphere); 266 | } 267 | else if (box is OBB) 268 | { 269 | return Util.TestAABBOBB(this, box as OBB); 270 | } 271 | 272 | return false; 273 | } 274 | 275 | //找到AABB上离Point最近的一点 276 | public Vector3 ClosestPoint(Vector3 point) 277 | { 278 | for (int i = 0; i < 3; i++) 279 | { 280 | if (point[i] < transformMin[i]) 281 | { 282 | point[i] = transformMin[i]; 283 | } 284 | else if (point[i] > transformMax[i]) 285 | { 286 | point[i] = transformMax[i]; 287 | } 288 | } 289 | 290 | return point; 291 | } 292 | 293 | public OBB GetOBB() 294 | { 295 | Vector3[] axis = new[] {Vector3.right, Vector3.up, Vector3.forward}; 296 | return new OBB(axis, (transformMax + transformMin) * 0.5f, (transformMax - transformMin) * 0.5f); 297 | } 298 | 299 | public AABB Union(AABB aabb) 300 | { 301 | for (int i = 0; i < 3; i++) 302 | { 303 | if (aabb.transformMin[i] < transformMin[i]) 304 | { 305 | transformMin[i] = aabb.transformMin[i]; 306 | } 307 | 308 | if (aabb.transformMax[i] > transformMax[i]) 309 | { 310 | transformMax[i] = aabb.transformMax[i]; 311 | } 312 | } 313 | 314 | return this; 315 | } 316 | 317 | public AABB Union(Vector3 point) 318 | { 319 | for (int i = 0; i < 3; i++) 320 | { 321 | if (point[i] < transformMin[i]) 322 | { 323 | transformMin[i] = point[i]; 324 | } 325 | 326 | if (point[i] > transformMax[i]) 327 | { 328 | transformMax[i] = point[i]; 329 | } 330 | } 331 | 332 | return this; 333 | } 334 | 335 | public Vector3 GetCentroid() 336 | { 337 | return (transformMin + transformMax) * 0.5f; 338 | } 339 | 340 | public int MaximumExtent() 341 | { 342 | int idx = 0; 343 | for (int i = 1; i < 3; i++) 344 | { 345 | if (transformMax[i] - transformMin[i] > transformMax[idx] - transformMin[idx]) 346 | { 347 | idx = i; 348 | } 349 | } 350 | 351 | return idx; 352 | } 353 | 354 | public float GetSurfaceArea() 355 | { 356 | Vector3 d = transformMax - transformMin; 357 | return 2 * (d.x * d.y + d.x * d.z + d.y * d.z); 358 | } 359 | 360 | public override AABB OuterAABB() 361 | { 362 | return Clone(); 363 | } 364 | 365 | } 366 | -------------------------------------------------------------------------------- /Assets/Scripts/AABB.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92832071d514d24489fecb40e7e9e024 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/AABBCollider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEditor; 5 | using UnityEngine; 6 | 7 | public class AABBCollider : BoxCollider 8 | { 9 | public AABBStructureMode mode = AABBStructureMode.Compact; 10 | 11 | private AABB aabb; 12 | 13 | // Use this for initialization 14 | void Awake() 15 | { 16 | aabb = new AABB(transform); 17 | box = aabb; 18 | } 19 | 20 | // Update is called once per frame 21 | void Update() 22 | { 23 | aabb.UpdateAABB(mode); 24 | } 25 | 26 | void OnDrawGizmos() 27 | { 28 | if (aabb != null) 29 | { 30 | aabb.DrawAABB(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Assets/Scripts/AABBCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 396ea8b1f2de7e64db4f1875095ac905 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/BVH.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using UnityEngine.Assertions; 6 | using UnityEngine.Rendering; 7 | 8 | public class BVHNode 9 | { 10 | public AABB aabb; 11 | public BVHNode left; 12 | public BVHNode right; 13 | public int axis; 14 | public int[] triangles; 15 | } 16 | 17 | public class LinearBVHNode 18 | { 19 | public AABB aabb; 20 | public bool left; 21 | public int right; 22 | public int axis; 23 | public int[] triangles; 24 | } 25 | 26 | public class BVHBucket 27 | { 28 | public AABB aabb; 29 | public int count; 30 | 31 | public BVHBucket() 32 | { 33 | aabb = AABB.Default; 34 | count = 0; 35 | } 36 | } 37 | 38 | //默认构造AABB BVH 39 | public class BVH : Box 40 | { 41 | private BVHSplitMethod bvhSplitMethod; 42 | private int maxPrimsInNode; 43 | private LinearBVHNode[] bvhNodes; 44 | 45 | //transform为null则构建基于场景的粗略测试bvh, 不为null则构建基于对象的精细测试bvh 46 | public BVH(Transform transform, BVHSplitMethod bvhSplitMethod, int maxPrimsInNode) 47 | { 48 | this.transform = transform; 49 | this.bvhSplitMethod = bvhSplitMethod; 50 | this.maxPrimsInNode = maxPrimsInNode; 51 | } 52 | 53 | public void CreateBVH() 54 | { 55 | if (transform == null) 56 | { 57 | BoxCollider[] boxColliders = GameObject.FindObjectsOfType(); 58 | AABB[] aabbs = new AABB[boxColliders.Length]; 59 | for (int i = 0; i < boxColliders.Length; i++) 60 | { 61 | AABB aabb = boxColliders[i].box.OuterAABB(); 62 | aabbs[i] = aabb; 63 | } 64 | 65 | int count = 0; 66 | BVHNode root = BuildBVH(aabbs, 0, aabbs.Length, ref count); 67 | FlattenBVH(root, count); 68 | } 69 | else 70 | { 71 | Mesh mesh = transform.GetComponent().sharedMesh; 72 | AABB[] aabbs = new AABB[mesh.triangles.Length / 3]; 73 | for (int i = 0; i < aabbs.Length; i++) 74 | { 75 | AABB aabb = AABB.Default; 76 | aabb.triangle = i; 77 | aabb.Union(mesh.vertices[mesh.triangles[i * 3]]); 78 | aabb.Union(mesh.vertices[mesh.triangles[i * 3 + 1]]); 79 | aabb.Union(mesh.vertices[mesh.triangles[i * 3 + 2]]); 80 | aabbs[i] = aabb; 81 | } 82 | 83 | int count = 0; 84 | BVHNode root = BuildBVH(aabbs, 0, aabbs.Length, ref count); 85 | FlattenBVH(root, count); 86 | } 87 | } 88 | 89 | //顺序存储BVH 90 | void FlattenBVH(BVHNode root, int count) 91 | { 92 | bvhNodes = new LinearBVHNode[count]; 93 | for (int i = 0; i < count; i++) 94 | { 95 | bvhNodes[i] = new LinearBVHNode(); 96 | } 97 | 98 | int offset = 0; 99 | BuildFlattenBVH(root, ref offset); 100 | } 101 | 102 | void BuildFlattenBVH(BVHNode bvhNode, ref int offset) 103 | { 104 | LinearBVHNode linearBVHNode = new LinearBVHNode(); 105 | linearBVHNode.aabb = bvhNode.aabb; 106 | linearBVHNode.axis = bvhNode.axis; 107 | if (bvhNode.triangles != null) 108 | { 109 | linearBVHNode.triangles = new int[bvhNode.triangles.Length]; 110 | for (int i = 0; i < linearBVHNode.triangles.Length; i++) 111 | { 112 | linearBVHNode.triangles[i] = bvhNode.triangles[i]; 113 | } 114 | } 115 | 116 | bvhNodes[offset] = linearBVHNode; 117 | if (bvhNode.left == null && bvhNode.right == null) 118 | { 119 | offset++; 120 | linearBVHNode.left = false; 121 | linearBVHNode.right = -1; 122 | } 123 | else 124 | { 125 | if (bvhNode.left != null) 126 | { 127 | linearBVHNode.left = true; 128 | offset++; 129 | BuildFlattenBVH(bvhNode.left, ref offset); 130 | linearBVHNode.right = offset; 131 | } 132 | 133 | if (bvhNode.right != null) 134 | { 135 | BuildFlattenBVH(bvhNode.right, ref offset); 136 | } 137 | } 138 | } 139 | 140 | BVHNode BuildBVH(AABB[] aabbs, int start, int end, ref int count) 141 | { 142 | AABB aabb = AABB.Default; 143 | for (int i = start; i < end; i++) 144 | { 145 | aabb.Union(aabbs[i]); 146 | } 147 | 148 | count++; 149 | BVHNode bvhNode = new BVHNode(); 150 | if (start == end - 1) 151 | { 152 | bvhNode.aabb = aabbs[start]; 153 | bvhNode.triangles = new[] {bvhNode.aabb.triangle}; 154 | } 155 | else 156 | { 157 | AABB centroidAABB = AABB.Default; 158 | for (int i = start; i < end; i++) 159 | { 160 | centroidAABB.Union(aabbs[i].GetCentroid()); 161 | } 162 | 163 | int dim = centroidAABB.MaximumExtent(); 164 | int split = 0; 165 | float splitCentroid = 0; 166 | if (Mathf.Abs(centroidAABB.transformMax[dim] - centroidAABB.transformMin[dim]) <= float.Epsilon) 167 | { 168 | if (end - start <= maxPrimsInNode) 169 | { 170 | bvhNode.aabb = aabb; 171 | bvhNode.triangles = new int[end - start]; 172 | for (int i = start; i < end; i++) 173 | { 174 | bvhNode.triangles[i - start] = aabbs[i].triangle; 175 | } 176 | 177 | return bvhNode; 178 | } 179 | 180 | split = (start + end) / 2; 181 | } 182 | else 183 | { 184 | //质心中点分割方法 185 | if (bvhSplitMethod == BVHSplitMethod.SplitMiddle) 186 | { 187 | float pivot = centroidAABB.GetCentroid()[dim]; 188 | int left = start; 189 | int right = end - 1; 190 | do 191 | { 192 | while (pivot > aabbs[left].GetCentroid()[dim]) 193 | { 194 | left++; 195 | } 196 | 197 | while (pivot < aabbs[right].GetCentroid()[dim]) 198 | { 199 | right--; 200 | } 201 | 202 | if (left > right) 203 | { 204 | break; 205 | } 206 | 207 | if (left < right) 208 | { 209 | Swap(aabbs, left, right); 210 | } 211 | 212 | left++; 213 | right--; 214 | } while (left <= right); 215 | 216 | split = left; 217 | splitCentroid = pivot; 218 | } 219 | //等尺寸集分割方法 220 | else if (bvhSplitMethod == BVHSplitMethod.SplitEqualCounts) 221 | { 222 | split = (start + end) / 2; 223 | QuickSelect(aabbs, split, start, end - 1, dim); 224 | splitCentroid = aabbs[split].GetCentroid()[dim]; 225 | } 226 | //启发式表面积方法 227 | else if (bvhSplitMethod == BVHSplitMethod.SplitSAH) 228 | { 229 | if (end - start <= 4) 230 | { 231 | split = (start + end) / 2; 232 | QuickSelect(aabbs, split, start, end - 1, dim); 233 | splitCentroid = aabbs[split].GetCentroid()[dim]; 234 | } 235 | else 236 | { 237 | int splitBucket = 12; 238 | BVHBucket[] buckets = new BVHBucket[splitBucket]; 239 | for (int i = 0; i < splitBucket; i++) 240 | { 241 | buckets[i] = new BVHBucket(); 242 | } 243 | 244 | for (int i = start; i < end; i++) 245 | { 246 | int bucketNo = GetBucketNo(aabbs[i], centroidAABB, dim, splitBucket); 247 | buckets[bucketNo].count++; 248 | buckets[bucketNo].aabb.Union(aabbs[i]); 249 | } 250 | 251 | float[] cost = new float[splitBucket - 1]; 252 | for (int i = 0; i < splitBucket - 1; i++) 253 | { 254 | AABB aabb1 = AABB.Default; 255 | AABB aabb2 = AABB.Default; 256 | int count1 = 0; 257 | int count2 = 0; 258 | for (int j = 0; j <= i; j++) 259 | { 260 | aabb1.Union(buckets[j].aabb); 261 | count1 += buckets[j].count; 262 | } 263 | 264 | for (int j = i + 1; j < splitBucket; j++) 265 | { 266 | aabb2.Union(buckets[j].aabb); 267 | count2 += buckets[j].count; 268 | } 269 | 270 | cost[i] = 0.125f + (aabb1.GetSurfaceArea() * count1 + aabb2.GetSurfaceArea() * count2) / 271 | aabb.GetSurfaceArea(); 272 | } 273 | 274 | float minCost = cost[0]; 275 | int pivot = 0; 276 | for (int i = 1; i < splitBucket - 1; i++) 277 | { 278 | if (cost[i] < minCost) 279 | { 280 | minCost = cost[i]; 281 | pivot = i; 282 | } 283 | } 284 | 285 | int left = start; 286 | int right = end - 1; 287 | do 288 | { 289 | while (pivot >= GetBucketNo(aabbs[left], centroidAABB, dim, splitBucket)) 290 | { 291 | left++; 292 | } 293 | 294 | while (pivot < GetBucketNo(aabbs[right], centroidAABB, dim, splitBucket)) 295 | { 296 | right--; 297 | } 298 | 299 | if (left > right) 300 | { 301 | break; 302 | } 303 | 304 | if (left < right) 305 | { 306 | Swap(aabbs, left, right); 307 | } 308 | 309 | left++; 310 | right--; 311 | } while (left <= right); 312 | 313 | if (end - start <= maxPrimsInNode && minCost >= maxPrimsInNode) 314 | { 315 | bvhNode.aabb = aabb; 316 | bvhNode.triangles = new int[end - start]; 317 | for (int i = start; i < end; i++) 318 | { 319 | bvhNode.triangles[i - start] = aabbs[i].triangle; 320 | } 321 | 322 | return bvhNode; 323 | } 324 | 325 | split = left; 326 | 327 | splitCentroid = centroidAABB.transformMin[dim] + (pivot + 1.0f) / splitBucket * 328 | (centroidAABB.transformMax[dim] - centroidAABB.transformMin[dim]); 329 | } 330 | } 331 | 332 | //断言检验 333 | for (int i = start; i < split; i++) 334 | { 335 | Assert.IsTrue(aabbs[i].GetCentroid()[dim] <= splitCentroid); 336 | } 337 | 338 | for (int i = split; i < end; i++) 339 | { 340 | Assert.IsTrue(aabbs[i].GetCentroid()[dim] >= splitCentroid); 341 | } 342 | } 343 | 344 | bvhNode.left = BuildBVH(aabbs, start, split, ref count); 345 | bvhNode.right = BuildBVH(aabbs, split, end, ref count); 346 | bvhNode.aabb = AABB.Default; 347 | bvhNode.aabb.Union(bvhNode.left.aabb); 348 | bvhNode.aabb.Union(bvhNode.right.aabb); 349 | bvhNode.axis = dim; 350 | } 351 | 352 | return bvhNode; 353 | } 354 | 355 | int GetBucketNo(AABB aabb, AABB centroidAABB, int dim, int splitBucket) 356 | { 357 | int bucketNo = (int) ((aabb.GetCentroid()[dim] - centroidAABB.transformMin[dim]) / 358 | (centroidAABB.transformMax[dim] - centroidAABB.transformMin[dim]) * 359 | splitBucket); 360 | if (bucketNo == splitBucket) 361 | { 362 | bucketNo--; 363 | } 364 | 365 | return bucketNo; 366 | } 367 | 368 | void QuickSelect(AABB[] aabbs, int k, int left, int right, int dim) 369 | { 370 | float pivot = Median3(aabbs, left, right, dim); 371 | int i = left; 372 | int j = right; 373 | do 374 | { 375 | while (pivot > aabbs[left].GetCentroid()[dim]) 376 | { 377 | left++; 378 | } 379 | 380 | while (pivot < aabbs[right].GetCentroid()[dim]) 381 | { 382 | right--; 383 | } 384 | 385 | if (left > right) 386 | { 387 | break; 388 | } 389 | 390 | if (left < right) 391 | { 392 | Swap(aabbs, left, right); 393 | } 394 | 395 | left++; 396 | right--; 397 | } while (left <= right); 398 | 399 | if (k <= right) 400 | { 401 | QuickSelect(aabbs, k, i, right, dim); 402 | } 403 | else if (k >= left) 404 | { 405 | QuickSelect(aabbs, k, left, j, dim); 406 | } 407 | } 408 | 409 | void Swap(AABB[] aabbs, int i, int j) 410 | { 411 | AABB tmp = aabbs[i]; 412 | aabbs[i] = aabbs[j]; 413 | aabbs[j] = tmp; 414 | } 415 | 416 | float Median3(AABB[] aabbs, int left, int right, int dim) 417 | { 418 | int mid = (left + right) / 2; 419 | if (aabbs[left].GetCentroid()[dim] > aabbs[mid].GetCentroid()[dim]) 420 | { 421 | Swap(aabbs, left, mid); 422 | } 423 | 424 | if (aabbs[left].GetCentroid()[dim] > aabbs[right].GetCentroid()[dim]) 425 | { 426 | Swap(aabbs, left, right); 427 | } 428 | 429 | if (aabbs[mid].GetCentroid()[dim] > aabbs[right].GetCentroid()[dim]) 430 | { 431 | Swap(aabbs, mid, right); 432 | } 433 | 434 | return aabbs[mid].GetCentroid()[dim]; 435 | } 436 | 437 | public void DrawBVH() 438 | { 439 | if (transform == null) 440 | { 441 | for (int i = 0; i < bvhNodes.Length; i++) 442 | { 443 | bvhNodes[i].aabb.DrawAABB(); 444 | } 445 | } 446 | else 447 | { 448 | for (int i = 0; i < bvhNodes.Length; i++) 449 | { 450 | OBB obb = bvhNodes[i].aabb.GetOBB(); 451 | obb.UpdateOBB(transform.localToWorldMatrix); 452 | obb.DrawOBB(); 453 | } 454 | } 455 | } 456 | 457 | public override bool RayDetection(Ray ray, RaycastHit hitInfo) 458 | { 459 | if (transform != null) 460 | { 461 | ray.Transform(transform.worldToLocalMatrix); 462 | } 463 | 464 | bool[] dirIsNeg = new bool[3] {ray.direction.x < 0, ray.direction.y < 0, ray.direction.z < 0}; 465 | Stack s = new Stack(); 466 | s.Push(0); 467 | bool hit = false; 468 | while (s.Count > 0) 469 | { 470 | int idx = s.Pop(); 471 | LinearBVHNode linearBVHNode = bvhNodes[idx]; 472 | if (linearBVHNode.aabb.RayDetection(ray)) 473 | { 474 | if (!linearBVHNode.left && linearBVHNode.right == -1) 475 | { 476 | if (transform != null) 477 | { 478 | Mesh mesh = transform.GetComponent().sharedMesh; 479 | for (int i = 0; i < linearBVHNode.triangles.Length; i++) 480 | { 481 | int triangle = linearBVHNode.triangles[i]; 482 | hit |= ray.Raycast(mesh.vertices[mesh.triangles[triangle * 3]], 483 | mesh.vertices[mesh.triangles[triangle * 3 + 1]], 484 | mesh.vertices[mesh.triangles[triangle * 3 + 2]]); 485 | } 486 | } 487 | else 488 | { 489 | hit |= linearBVHNode.aabb.transform.GetComponent().box 490 | .RayDetection(ray, hitInfo); 491 | } 492 | } 493 | 494 | if (dirIsNeg[linearBVHNode.axis]) 495 | { 496 | if (linearBVHNode.left) 497 | { 498 | s.Push(++idx); 499 | } 500 | 501 | if (linearBVHNode.right != -1) 502 | { 503 | s.Push(linearBVHNode.right); 504 | } 505 | } 506 | else 507 | { 508 | if (linearBVHNode.right != -1) 509 | { 510 | s.Push(linearBVHNode.right); 511 | } 512 | 513 | if (linearBVHNode.left) 514 | { 515 | s.Push(++idx); 516 | } 517 | } 518 | } 519 | } 520 | 521 | if (transform != null) 522 | { 523 | ray.Transform(transform.localToWorldMatrix); 524 | if (hit) 525 | { 526 | hitInfo.point = ray.origin + ray.direction * ray.distance; 527 | hitInfo.transform = transform; 528 | } 529 | } 530 | 531 | return hit; 532 | } 533 | 534 | public override bool BoxDetection(Box box) 535 | { 536 | return false; 537 | } 538 | 539 | public override AABB OuterAABB() 540 | { 541 | return new AABB(transform); 542 | } 543 | } -------------------------------------------------------------------------------- /Assets/Scripts/BVH.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa40cb9a75bdcf44fbaa2e53b70f8dea 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/BVHAccelerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class BVHAccelerator : MonoBehaviour 6 | { 7 | 8 | public BVHSplitMethod bvhSplitMethod = BVHSplitMethod.SplitSAH; 9 | 10 | private BVH bvh; 11 | private CameraHelper cameraHelper; 12 | 13 | // Use this for initialization 14 | void Start() 15 | { 16 | bvh = new BVH(null, bvhSplitMethod, 1); 17 | bvh.CreateBVH(); 18 | cameraHelper = new CameraHelper(Camera.main); 19 | } 20 | 21 | // Update is called once per fram 22 | void Update() 23 | { 24 | if (Input.GetMouseButtonDown(0)) 25 | { 26 | Ray ray = cameraHelper.ScreenPointToRay(); 27 | RaycastHit info = new RaycastHit(); 28 | if (bvh.RayDetection(ray, info)) 29 | { 30 | info.transform.GetComponent().material.color = Color.green; 31 | } 32 | } 33 | } 34 | 35 | void OnDrawGizmos() 36 | { 37 | if (bvh != null) 38 | { 39 | bvh.DrawBVH(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Assets/Scripts/BVHAccelerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f68afd655894ce4ab9f449d567e7a43 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Box.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public abstract class Box 6 | { 7 | public Transform transform; 8 | 9 | public abstract bool RayDetection(Ray ray, RaycastHit hitInfo); 10 | 11 | public abstract bool BoxDetection(Box box); 12 | 13 | public abstract AABB OuterAABB(); 14 | 15 | public T Clone() where T : Box 16 | { 17 | return MemberwiseClone() as T; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Assets/Scripts/Box.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68cf722ee8c8e764084e3e57ca4fb3c9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/BoxCollider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | public class BoxCollider : MonoBehaviour 7 | { 8 | [HideInInspector] public Box box; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Assets/Scripts/BoxCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 33ac6ca30ddc3e04e90db5a9f9e83a6a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/CameraHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class CameraHelper 6 | { 7 | 8 | private Camera camera; 9 | 10 | public Transform transform; 11 | 12 | public CameraHelper(Camera camera) 13 | { 14 | this.camera = camera; 15 | transform = camera.transform; 16 | } 17 | 18 | public Ray ScreenPointToRay() 19 | { 20 | Vector2 uv = new Vector2(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height) - 21 | Vector2.one * 0.5f; 22 | //注意tan的参数是弧度 23 | float y = camera.nearClipPlane * Mathf.Tan(camera.fieldOfView / 360 * Mathf.PI) * 2; 24 | float x = camera.aspect * y; 25 | //注意观察空间和世界空间的Z轴是反向的,所以z值要取反 26 | Vector4 p = new Vector4(x * uv.x, y * uv.y, -camera.nearClipPlane, 1); 27 | Vector3 wp = camera.cameraToWorldMatrix * p; 28 | Ray ray = new Ray(camera.transform.position, (wp - camera.transform.position), 1000); 29 | return ray; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Assets/Scripts/CameraHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e85329318a589d84681710713b6ff621 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Enum.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public enum AABBStructureMode 6 | { 7 | None, 8 | Accelerate, 9 | Compact 10 | } 11 | 12 | public enum SphereStructureMode 13 | { 14 | Ritter, 15 | RitterIter, 16 | RitterEigen 17 | } 18 | 19 | public enum OBBStructureMode 20 | { 21 | Eigen, 22 | AABB 23 | } 24 | 25 | public enum BVHSplitMethod 26 | { 27 | SplitMiddle, 28 | SplitEqualCounts, 29 | SplitSAH 30 | } 31 | -------------------------------------------------------------------------------- /Assets/Scripts/Enum.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bab948edfb8a1c44ad2c804879c83bf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Grid.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Voxel 6 | { 7 | public List aabbs; 8 | 9 | public void Add(AABB aabb) 10 | { 11 | if (aabbs == null) 12 | { 13 | aabbs = new List(); 14 | } 15 | 16 | if (!aabbs.Contains(aabb)) 17 | { 18 | aabbs.Add(aabb); 19 | } 20 | } 21 | } 22 | 23 | public class Grid 24 | { 25 | Voxel[,,] voxels; 26 | AABB aabb; 27 | Vector3 unitWidth; 28 | Vector3 invUnitWidth; 29 | 30 | public Grid() 31 | { 32 | BoxCollider[] boxColliders = GameObject.FindObjectsOfType(); 33 | aabb = AABB.Default; 34 | AABB[] aabbs = new AABB[boxColliders.Length]; 35 | for (int i = 0; i < boxColliders.Length; i++) 36 | { 37 | aabbs[i] = boxColliders[i].box.OuterAABB(); 38 | aabb.Union(aabbs[i]); 39 | } 40 | 41 | //计算单位距离的体素数量 42 | Vector3 delta = aabb.transformMax - aabb.transformMin; 43 | int dim = aabb.MaximumExtent(); 44 | float dimVoxel = 3 * Mathf.Pow((float) aabbs.Length, 1.0f / 3); 45 | float unitVoxel = dimVoxel / delta[dim]; 46 | int[] nVoxel = new int[3]; 47 | for (int i = 0; i < 3; i++) 48 | { 49 | nVoxel[i] = (int) (delta[i] * unitVoxel); 50 | nVoxel[i] = Mathf.Clamp(nVoxel[i], 1, 64); 51 | } 52 | 53 | voxels = new Voxel[nVoxel[0], nVoxel[1], nVoxel[2]]; 54 | 55 | for (int i = 0; i < 3; i++) 56 | { 57 | unitWidth[i] = delta[i] / voxels.GetLength(i); 58 | invUnitWidth[i] = unitWidth[i] <= float.Epsilon ? 0 : 1 / unitWidth[i]; 59 | } 60 | 61 | int[] voxelMin = new int[3]; 62 | int[] voxelMax = new int[3]; 63 | for (int i = 0; i < aabbs.Length; i++) 64 | { 65 | for (int j = 0; j < 3; j++) 66 | { 67 | voxelMin[j] = Point2Voxel(aabbs[i].transformMin, j); 68 | voxelMax[j] = Point2Voxel(aabbs[i].transformMax, j); 69 | } 70 | 71 | for (int x = voxelMin[0]; x <= voxelMax[0]; x++) 72 | { 73 | for (int y = voxelMin[1]; y <= voxelMax[1]; y++) 74 | { 75 | for (int z = voxelMin[2]; z <= voxelMax[2]; z++) 76 | { 77 | Voxel voxel = GetVoxel(x, y, z); 78 | voxel.Add(aabbs[i]); 79 | } 80 | } 81 | } 82 | } 83 | } 84 | 85 | Voxel GetVoxel(int x, int y, int z) 86 | { 87 | Voxel voxel = voxels[x, y, z]; 88 | if (voxel == null) 89 | { 90 | voxel = new Voxel(); 91 | voxels[x, y, z] = voxel; 92 | } 93 | 94 | return voxel; 95 | } 96 | 97 | int Point2Voxel(Vector3 point, int axis) 98 | { 99 | int voxel = (int) ((point[axis] - aabb.transformMin[axis]) * invUnitWidth[axis]); 100 | return Mathf.Clamp(voxel, 0, voxels.GetLength(axis) - 1); 101 | } 102 | 103 | float Voxel2Point(int voxel, int axis) 104 | { 105 | return aabb.transformMin[axis] + unitWidth[axis] * voxel; 106 | } 107 | 108 | public void DrawGrid() 109 | { 110 | for (int i = 0; i < voxels.GetLength(0); i++) 111 | { 112 | for (int j = 0; j < voxels.GetLength(1); j++) 113 | { 114 | for (int k = 0; k < voxels.GetLength(2); k++) 115 | { 116 | Vector3 min = this.aabb.transformMin + 117 | new Vector3(i * unitWidth[0], j * unitWidth[1], k * unitWidth[2]); 118 | Vector3 max = min + unitWidth; 119 | AABB aabb = new AABB(min, max); 120 | aabb.DrawAABB(); 121 | } 122 | } 123 | } 124 | } 125 | 126 | public bool RayDetection(Ray ray, RaycastHit hitInfo) 127 | { 128 | float t = 0; 129 | if (!aabb.RayDetection(ray, ref t)) 130 | { 131 | return false; 132 | } 133 | 134 | Vector3 p = ray.origin + ray.direction * t; 135 | 136 | int[] step = new int[3]; 137 | int[] end = new int[3]; 138 | int[] vp = new int[3]; 139 | float[] deltaT = new float[3]; 140 | float[] nextT = new float[3]; 141 | for (int i = 0; i < 3; i++) 142 | { 143 | vp[i] = Point2Voxel(p, i); 144 | if (ray.direction[i] >= 0) 145 | { 146 | step[i] = 1; 147 | end[i] = voxels.GetLength(i); 148 | deltaT[i] = unitWidth[i] / ray.direction[i]; 149 | nextT[i] = t + (Voxel2Point(vp[i] + 1, i) - p[i]) / ray.direction[i]; 150 | } 151 | else 152 | { 153 | step[i] = -1; 154 | end[i] = -1; 155 | deltaT[i] = -unitWidth[i] / ray.direction[i]; 156 | nextT[i] = t + (Voxel2Point(vp[i], i) - p[i]) / ray.direction[i]; 157 | } 158 | } 159 | 160 | HashSet hs = new HashSet(); 161 | bool hit = false; 162 | while (true) 163 | { 164 | Voxel voxel = voxels[vp[0], vp[1], vp[2]]; 165 | if (voxel != null && voxel.aabbs != null) 166 | { 167 | for (int i = 0; i < voxel.aabbs.Count; i++) 168 | { 169 | AABB tmp = voxel.aabbs[i]; 170 | if (!hs.Contains(aabb)) 171 | { 172 | hs.Add(tmp); 173 | hit |= tmp.transform.GetComponent().box 174 | .RayDetection(ray, hitInfo); 175 | } 176 | } 177 | } 178 | 179 | int bits = ((nextT[0] < nextT[1] ? 1 : 0) << 2) + ((nextT[0] < nextT[2] ? 1 : 0) << 1) + 180 | nextT[1] < nextT[2] ? 1 : 0; 181 | int[] cmpToAxis = {2, 1, 2, 1, 2, 2, 0, 0}; 182 | int stepAxis = cmpToAxis[bits]; 183 | if (ray.distance < nextT[stepAxis]) 184 | break; 185 | vp[stepAxis] += step[stepAxis]; 186 | if (vp[stepAxis] == end[stepAxis]) 187 | break; 188 | nextT[stepAxis] += deltaT[stepAxis]; 189 | } 190 | 191 | return hit; 192 | } 193 | } 194 | 195 | -------------------------------------------------------------------------------- /Assets/Scripts/Grid.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28a767e8b3075634ca794e2f38b76a17 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/GridAccelerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class GridAccelerator : MonoBehaviour 6 | { 7 | 8 | private Grid grid; 9 | private CameraHelper cameraHelper; 10 | 11 | // Use this for initialization 12 | void Start() 13 | { 14 | grid = new Grid(); 15 | cameraHelper = new CameraHelper(Camera.main); 16 | } 17 | 18 | // Update is called once per fram 19 | void Update() 20 | { 21 | if (Input.GetMouseButtonDown(0)) 22 | { 23 | Ray ray = cameraHelper.ScreenPointToRay(); 24 | ray.DrawRay(); 25 | RaycastHit info = new RaycastHit(); 26 | if (grid.RayDetection(ray, info)) 27 | { 28 | info.transform.GetComponent().material.color = Color.green; 29 | } 30 | } 31 | } 32 | 33 | void OnDrawGizmos() 34 | { 35 | if (grid != null) 36 | { 37 | grid.DrawGrid(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/Scripts/GridAccelerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a859201628b93ec46a732cc43e283147 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/MathUtil.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public static class MathUtil 6 | { 7 | public static Vector4 Vector4(Vector3 v, float w) 8 | { 9 | return new Vector4(v.x, v.y, v.z, w); 10 | } 11 | 12 | //变换矩阵是否只发生了平移 13 | public static bool IsOnlyContainTranslation(Matrix4x4 oldMatrix, Matrix4x4 newMatrix) 14 | { 15 | for (int i = 0; i < 12; i++) 16 | { 17 | if (Mathf.Abs(oldMatrix[i] - newMatrix[i]) > float.Epsilon) 18 | return false; 19 | } 20 | 21 | return true; 22 | } 23 | 24 | //提取平移 25 | public static Vector3 ExtractTranslate(Matrix4x4 matrix) 26 | { 27 | return new Vector3(matrix.m03, matrix.m13, matrix.m23); 28 | } 29 | 30 | //得到平移偏移 31 | public static Vector3 GetTranslation(Matrix4x4 oldMatrix, Matrix4x4 newMatrix) 32 | { 33 | return ExtractTranslate(newMatrix) - ExtractTranslate(oldMatrix); 34 | } 35 | 36 | //试图提取缩放 第i列的长度为ki (只能保证数值正确,计算不了正负) 37 | public static Vector3 ExtractScale(Matrix4x4 matrix, bool sqrt = true) 38 | { 39 | Vector3 scale = Vector3.zero; 40 | for (int i = 0; i < 3; i++) 41 | { 42 | scale[i] = sqrt ? matrix.GetColumn(i).magnitude : matrix.GetColumn(i).sqrMagnitude; 43 | } 44 | 45 | return scale; 46 | } 47 | 48 | //变换矩阵是否发生了缩放 (相反数认为没发生缩放) 49 | public static bool IsContainScale(Matrix4x4 oldMatrix, Matrix4x4 newMatrix) 50 | { 51 | return ExtractScale(oldMatrix, false) != ExtractScale(newMatrix, false); 52 | } 53 | 54 | public static bool IsContainScale(Matrix4x4 matrix, out Vector3 scale) 55 | { 56 | scale = ExtractScale(matrix, false); 57 | bool res = scale != Vector3.one; 58 | if (res) 59 | { 60 | for (int i = 0; i < 3; i++) 61 | { 62 | scale[i] = Mathf.Sqrt(scale[i]); 63 | } 64 | } 65 | 66 | return res; 67 | } 68 | 69 | 70 | //计算协方差矩阵 71 | public static Matrix4x4 GetCovarianceMatrix(List vertices) 72 | { 73 | Matrix4x4 m = Matrix4x4.zero; 74 | Vector3 avg = Vector3.zero; 75 | float inverseSum = 1.0f / vertices.Count; 76 | for (int i = 0; i < vertices.Count; i++) 77 | { 78 | avg += vertices[i]; 79 | } 80 | 81 | avg *= inverseSum; 82 | 83 | for (int i = 0; i < vertices.Count; i++) 84 | { 85 | Vector3 p = vertices[i] - avg; 86 | for (int j = 0; j < 3; j++) 87 | { 88 | for (int k = 0; k < 3; k++) 89 | { 90 | m[k, j] += p[k] * p[j]; 91 | } 92 | } 93 | } 94 | 95 | for (int j = 0; j < 3; j++) 96 | { 97 | for (int k = 0; k < 3; k++) 98 | { 99 | m[k, j] *= inverseSum; 100 | } 101 | } 102 | 103 | return m; 104 | } 105 | 106 | //雅可比迭代法计算特征值和特征向量 107 | public static Matrix4x4 Jacobi(ref Matrix4x4 m, int iter = 50, double eps = 1e-10) 108 | { 109 | Matrix4x4 res = Matrix4x4.identity; 110 | int count = 0; 111 | while (true) 112 | { 113 | float max = float.MinValue; 114 | int row = -1; 115 | int col = -1; 116 | for (int i = 0; i < 3; i++) 117 | { 118 | for (int j = 0; j < 3; j++) 119 | { 120 | if (i != j && Mathf.Abs(m[i, j]) > max) 121 | { 122 | max = Mathf.Abs(m[i, j]); 123 | row = i; 124 | col = j; 125 | } 126 | } 127 | } 128 | 129 | if (max < eps) 130 | break; 131 | if (count > iter) 132 | break; 133 | count++; 134 | 135 | float mii = m[row, row]; 136 | float mij = m[row, col]; 137 | float mjj = m[col, col]; 138 | float theta = 0.5f * Mathf.Atan2(2 * mij, mjj - mii); 139 | float sinTheta = Mathf.Sin(theta); 140 | float cosTheta = Mathf.Cos(theta); 141 | float sin2Theta = Mathf.Sin(2 * theta); 142 | float cos2Theta = Mathf.Cos(2 * theta); 143 | m[row, row] = cosTheta * cosTheta * mii - sin2Theta * mij + sinTheta * sinTheta * mjj; 144 | m[col, col] = sinTheta * sinTheta * mii + sin2Theta * mij + cosTheta * cosTheta * mjj; 145 | m[row, col] = m[col, row] = cos2Theta * mij + 0.5f * sin2Theta * (mii - mjj); 146 | for (int k = 0; k < 3; k++) 147 | { 148 | if (k != row && k != col) 149 | { 150 | float tmp = m[row, k]; 151 | m[row, k] = m[k, row] = 152 | cosTheta * tmp - sinTheta * m[col, k]; 153 | m[col, k] = m[k, col] = 154 | sinTheta * tmp + cosTheta * m[col, k]; 155 | } 156 | } 157 | 158 | for (int k = 0; k < 3; k++) 159 | { 160 | float tmp = res[k, row]; 161 | res[k, row] = cosTheta * tmp - sinTheta * res[k, col]; 162 | res[k, col] = sinTheta * tmp + cosTheta * res[k, col]; 163 | } 164 | 165 | } 166 | 167 | return res; 168 | 169 | } 170 | 171 | //根据特征值降序排列特征向量 172 | public static void EigenSort(ref Matrix4x4 eigenVector, ref Matrix4x4 eigenValue) 173 | { 174 | for (int i = 1; i < 3; i++) 175 | { 176 | float tmp = eigenValue[i, i]; 177 | Vector4 tmp2 = eigenVector.GetColumn(i); 178 | int j = i - 1; 179 | while (j >= 0 && tmp > eigenValue[j, j]) 180 | { 181 | eigenValue[j + 1, j + 1] = eigenValue[j, j]; 182 | eigenVector.SetColumn(j + 1, eigenVector.GetColumn(j)); 183 | j--; 184 | } 185 | 186 | eigenValue[j + 1, j + 1] = tmp; 187 | eigenVector.SetColumn(j + 1, tmp2); 188 | } 189 | } 190 | 191 | //施密特正交化 192 | public static void SchmidtOrthogonalization(ref Matrix4x4 m) 193 | { 194 | m.SetColumn(0, Vector3.Normalize(m.GetColumn(0))); 195 | m.SetColumn(1, 196 | Vector3.Normalize(m.GetColumn(1) - Vector3.Dot(m.GetColumn(0), m.GetColumn(1)) * m.GetColumn(0))); 197 | m.SetColumn(2, 198 | Vector3.Normalize(m.GetColumn(2) - Vector3.Dot(m.GetColumn(0), m.GetColumn(2)) * m.GetColumn(0) - 199 | Vector3.Dot(m.GetColumn(1), m.GetColumn(2)) * m.GetColumn(1))); 200 | } 201 | 202 | } -------------------------------------------------------------------------------- /Assets/Scripts/MathUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61f792f53bc5835468c704df419b9a10 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/MeshCollider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Security; 4 | using UnityEngine; 5 | 6 | public class MeshCollider : BoxCollider 7 | { 8 | 9 | public BVHSplitMethod bvhSplitMethod = BVHSplitMethod.SplitSAH; 10 | 11 | private BVH bvh; 12 | 13 | // Use this for initialization 14 | void Awake() 15 | { 16 | bvh = new BVH(transform, bvhSplitMethod, 4); 17 | bvh.CreateBVH(); 18 | box = bvh; 19 | } 20 | 21 | void OnDrawGizmos() 22 | { 23 | if (bvh != null) 24 | { 25 | bvh.DrawBVH(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Assets/Scripts/MeshCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0c28c6c2f018954cac905796094b50b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/OBB.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class OBB : Box 6 | { 7 | private Vector3 center; 8 | public Vector3[] axis; 9 | private Vector3 radius; 10 | public Vector3 transformCenter; 11 | public Vector3 transformRadius; 12 | private Matrix4x4 matrix; 13 | private OBBStructureMode mode; 14 | 15 | public OBB(Transform transform, OBBStructureMode mode) 16 | { 17 | this.transform = transform; 18 | this.mode = mode; 19 | switch (mode) 20 | { 21 | case OBBStructureMode.Eigen: 22 | matrix = transform.localToWorldMatrix; 23 | break; 24 | case OBBStructureMode.AABB: 25 | matrix = Matrix4x4.identity; 26 | break; 27 | } 28 | 29 | StructureOBB(mode, matrix); 30 | UpdateOBB(mode); 31 | } 32 | 33 | public OBB(Vector3[] axis, Vector3 center, Vector3 radius) 34 | { 35 | this.axis = new Vector3[3]; 36 | for (int i = 0; i < 3; i++) 37 | { 38 | this.axis[i] = axis[i]; 39 | } 40 | 41 | this.center = center; 42 | this.radius = radius; 43 | transformCenter = center; 44 | transformRadius = radius; 45 | } 46 | 47 | void StructureOBB(OBBStructureMode mode, Matrix4x4 local2world) 48 | { 49 | switch (mode) 50 | { 51 | case OBBStructureMode.Eigen: 52 | EigenOBB(local2world); 53 | break; 54 | case OBBStructureMode.AABB: 55 | AABBOBB(); 56 | break; 57 | } 58 | 59 | transformCenter = center; 60 | transformRadius = radius; 61 | } 62 | 63 | void EigenOBB(Matrix4x4 local2world) 64 | { 65 | Mesh mesh = transform.GetComponent().sharedMesh; 66 | List vertices = Util.GetNoRepeatVertices(mesh); 67 | for (int i = 0; i < vertices.Count; i++) 68 | { 69 | vertices[i] = local2world * MathUtil.Vector4(vertices[i], 1); 70 | } 71 | 72 | Matrix4x4 covarianceM = MathUtil.GetCovarianceMatrix(vertices); 73 | Matrix4x4 eigenM = MathUtil.Jacobi(ref covarianceM); 74 | MathUtil.SchmidtOrthogonalization(ref eigenM); 75 | 76 | axis = new Vector3[3]; 77 | for (int i = 0; i < 3; i++) 78 | { 79 | axis[i] = eigenM.GetColumn(i); 80 | } 81 | 82 | Vector3 min = Vector3.positiveInfinity; 83 | Vector3 max = Vector3.negativeInfinity; 84 | for (int i = 1; i < vertices.Count; i++) 85 | { 86 | for (int j = 0; j < 3; j++) 87 | { 88 | float tmp = Vector3.Dot(axis[j], vertices[i]); 89 | if (tmp < min[j]) 90 | { 91 | min[j] = tmp; 92 | } 93 | 94 | if (tmp > max[j]) 95 | { 96 | max[j] = tmp; 97 | } 98 | } 99 | } 100 | 101 | radius = (max - min) * 0.5f; 102 | 103 | center = Vector3.zero; 104 | for (int i = 0; i < 3; i++) 105 | { 106 | center += (radius + min)[i] * axis[i]; 107 | } 108 | } 109 | 110 | void AABBOBB() 111 | { 112 | Mesh mesh = transform.GetComponent().sharedMesh; 113 | Vector3 originMin = mesh.vertices[0]; 114 | Vector3 originMax = originMin; 115 | for (int i = 1; i < mesh.vertices.Length; i++) 116 | { 117 | for (int j = 0; j < 3; j++) 118 | { 119 | if (mesh.vertices[i][j] < originMin[j]) 120 | originMin[j] = mesh.vertices[i][j]; 121 | if (mesh.vertices[i][j] > originMax[j]) 122 | originMax[j] = mesh.vertices[i][j]; 123 | } 124 | } 125 | 126 | axis = new Vector3[3]; 127 | for (int i = 0; i < 3; i++) 128 | { 129 | Vector3 tmp = Vector3.zero; 130 | tmp[i] = 1; 131 | axis[i] = tmp; 132 | } 133 | 134 | center = (originMax + originMin) * 0.5f; 135 | 136 | radius = (originMax - originMin) * 0.5f; 137 | 138 | } 139 | 140 | public void UpdateOBB(OBBStructureMode mode) 141 | { 142 | Matrix4x4 m = transform.localToWorldMatrix; 143 | if (MathUtil.IsOnlyContainTranslation(matrix, m) && this.mode == mode) 144 | { 145 | Vector3 translation = MathUtil.GetTranslation(matrix, m); 146 | transformCenter += translation; 147 | } 148 | else 149 | { 150 | if (mode == OBBStructureMode.Eigen) 151 | { 152 | StructureOBB(mode, m); 153 | } 154 | else if (mode == OBBStructureMode.AABB) 155 | { 156 | if (this.mode != mode) 157 | { 158 | StructureOBB(mode, m); 159 | } 160 | 161 | UpdateOBB(m); 162 | } 163 | 164 | this.mode = mode; 165 | } 166 | 167 | matrix = m; 168 | } 169 | 170 | public void UpdateOBB(Matrix4x4 m) 171 | { 172 | for (int i = 0; i < 3; i++) 173 | { 174 | Vector3 tmp = Vector3.zero; 175 | tmp[i] = 1; 176 | axis[i] = m * tmp; 177 | } 178 | 179 | transformCenter = m * MathUtil.Vector4(center, 1); 180 | 181 | Vector3 scale; 182 | if (MathUtil.IsContainScale(m, out scale)) 183 | { 184 | for (int i = 0; i < 3; i++) 185 | { 186 | axis[i] /= scale[i]; 187 | transformRadius[i] = radius[i] * scale[i]; 188 | } 189 | } 190 | else 191 | { 192 | transformRadius = radius; 193 | } 194 | } 195 | 196 | public void DrawOBB() 197 | { 198 | Gizmos.color = Color.yellow; 199 | Vector3 min = transformCenter; 200 | Vector3 max = transformCenter; 201 | for (int i = 0; i < 3; i++) 202 | { 203 | min -= axis[i] * transformRadius[i]; 204 | max += axis[i] * transformRadius[i]; 205 | } 206 | 207 | Vector3 offset0 = axis[0] * (transformRadius[0] * 2); 208 | Vector3 offset1 = axis[1] * (transformRadius[1] * 2); 209 | Vector3 offset2 = axis[2] * (transformRadius[2] * 2); 210 | Gizmos.color = Color.yellow; 211 | Gizmos.DrawLine(min, min + offset0); 212 | Gizmos.DrawLine(min, min + offset1); 213 | Gizmos.DrawLine(min, min + offset2); 214 | Gizmos.DrawLine(min + offset0, max - offset2); 215 | Gizmos.DrawLine(min + offset1, max - offset2); 216 | Gizmos.DrawLine(min + offset0, max - offset1); 217 | Gizmos.DrawLine(min + offset2, max - offset1); 218 | Gizmos.DrawLine(min + offset1, max - offset0); 219 | Gizmos.DrawLine(min + offset2, max - offset0); 220 | Gizmos.DrawLine(max, max - offset0); 221 | Gizmos.DrawLine(max, max - offset1); 222 | Gizmos.DrawLine(max, max - offset2); 223 | } 224 | 225 | public override bool RayDetection(Ray ray, RaycastHit hitInfo) 226 | { 227 | AABB aabb = GetAABB(); 228 | 229 | ray.Transform(RTMatrix); 230 | 231 | bool res = aabb.RayDetection(ray, hitInfo); 232 | if (res) 233 | { 234 | hitInfo.point = TRMatrix * MathUtil.Vector4(hitInfo.point, 1); 235 | hitInfo.transform = transform; 236 | } 237 | 238 | ray.Transform(TRMatrix); 239 | 240 | return res; 241 | } 242 | 243 | public override bool BoxDetection(Box box) 244 | { 245 | if (box is Sphere) 246 | { 247 | return Util.TestOBBSphere(this, box as Sphere); 248 | } 249 | else if (box is OBB) 250 | { 251 | return Util.TestOBBOBB(this, box as OBB); 252 | } 253 | else if (box is AABB) 254 | { 255 | return Util.TestAABBOBB(box as AABB, this); 256 | } 257 | 258 | return false; 259 | } 260 | 261 | public Matrix4x4 RTMatrix 262 | { 263 | get 264 | { 265 | Matrix4x4 t = Matrix4x4.identity; 266 | t.SetColumn(3, MathUtil.Vector4(-transformCenter, 1)); 267 | Matrix4x4 r = Matrix4x4.identity; 268 | for (int i = 0; i < 3; i++) 269 | { 270 | r.SetRow(i, axis[i]); 271 | } 272 | 273 | Matrix4x4 m = r * t; 274 | return m; 275 | } 276 | } 277 | 278 | public Matrix4x4 TRMatrix 279 | { 280 | get 281 | { 282 | Matrix4x4 t = Matrix4x4.identity; 283 | t.SetColumn(3, MathUtil.Vector4(transformCenter, 1)); 284 | Matrix4x4 r = Matrix4x4.identity; 285 | for (int i = 0; i < 3; i++) 286 | { 287 | r.SetColumn(i, axis[i]); 288 | } 289 | 290 | Matrix4x4 m = t * r; 291 | return m; 292 | } 293 | } 294 | 295 | public AABB GetAABB() 296 | { 297 | return new AABB(-transformRadius, transformRadius); 298 | } 299 | 300 | public override AABB OuterAABB() 301 | { 302 | AABB aabb = AABB.Default; 303 | aabb.Union(transformCenter + axis[0] * transformRadius[0] + axis[1] * transformRadius[1] + 304 | axis[2] * transformRadius[2]); 305 | aabb.Union(transformCenter + axis[0] * transformRadius[0] + axis[1] * transformRadius[1] - 306 | axis[2] * transformRadius[2]); 307 | aabb.Union(transformCenter + axis[0] * transformRadius[0] - axis[1] * transformRadius[1] + 308 | axis[2] * transformRadius[2]); 309 | aabb.Union(transformCenter + axis[0] * transformRadius[0] - axis[1] * transformRadius[1] - 310 | axis[2] * transformRadius[2]); 311 | aabb.Union(transformCenter - axis[0] * transformRadius[0] + axis[1] * transformRadius[1] + 312 | axis[2] * transformRadius[2]); 313 | aabb.Union(transformCenter - axis[0] * transformRadius[0] + axis[1] * transformRadius[1] - 314 | axis[2] * transformRadius[2]); 315 | aabb.Union(transformCenter - axis[0] * transformRadius[0] - axis[1] * transformRadius[1] + 316 | axis[2] * transformRadius[2]); 317 | aabb.Union(transformCenter - axis[0] * transformRadius[0] - axis[1] * transformRadius[1] - 318 | axis[2] * transformRadius[2]); 319 | aabb.transform = transform; 320 | return aabb; 321 | } 322 | 323 | } 324 | -------------------------------------------------------------------------------- /Assets/Scripts/OBB.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 473b5657f46c48748b0103988b90df66 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/OBBCollider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class OBBCollider : BoxCollider 6 | { 7 | public OBBStructureMode mode = OBBStructureMode.AABB; 8 | 9 | private OBB obb; 10 | 11 | // Use this for initialization 12 | void Awake() 13 | { 14 | obb = new OBB(transform, mode); 15 | box = obb; 16 | } 17 | 18 | // Update is called once per frame 19 | void Update() 20 | { 21 | obb.UpdateOBB(mode); 22 | } 23 | 24 | void OnDrawGizmos() 25 | { 26 | if (obb != null) 27 | { 28 | obb.DrawOBB(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Assets/Scripts/OBBCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9903e9f69856081458ac8015325e9733 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Ray.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Ray 6 | { 7 | public Vector3 origin; 8 | public Vector3 direction; 9 | public float distance; 10 | 11 | public Ray(Vector3 origin, Vector3 direction, float distance) 12 | { 13 | this.origin = origin; 14 | this.direction = direction.normalized; 15 | this.distance = distance; 16 | } 17 | 18 | public bool Raycast(Vector3 p0, Vector3 p1, Vector3 p2) 19 | { 20 | Vector3 e0 = p0 - p1; 21 | Vector3 e1 = p1 - p2; 22 | Vector3 n = Vector3.Cross(e0, e1); 23 | float dot = Vector3.Dot(n, direction); 24 | if (dot >= 0) 25 | { 26 | return false; 27 | } 28 | 29 | float d = Vector3.Dot(n, p0); 30 | float t = (d - Vector3.Dot(origin, n)) / dot; 31 | if (t < 0 || t > distance) 32 | { 33 | return false; 34 | } 35 | 36 | Vector3 p = origin + direction * t; 37 | Vector3 e2 = p2 - p0; 38 | Vector3 d0 = p0 - p; 39 | Vector3 d2 = p2 - p; 40 | float inverseNN = 1 / Vector3.Dot(n, n); 41 | float b0 = Vector3.Dot(Vector3.Cross(e1, d2), n) * inverseNN; 42 | if (b0 < 0 || b0 > 1) 43 | { 44 | return false; 45 | } 46 | 47 | float b1 = Vector3.Dot(Vector3.Cross(e2, d0), n) * inverseNN; 48 | if (b1 < 0 || b1 > 1) 49 | { 50 | return false; 51 | } 52 | 53 | float b2 = 1 - b0 - b1; 54 | if (b2 < 0 || b2 > 1) 55 | { 56 | return false; 57 | } 58 | 59 | if (t > distance) 60 | { 61 | return false; 62 | } 63 | else 64 | { 65 | distance = t; 66 | return true; 67 | } 68 | } 69 | 70 | public void Transform(Matrix4x4 m) 71 | { 72 | origin = m * MathUtil.Vector4(origin, 1); 73 | direction = m * direction; 74 | direction.Normalize(); 75 | } 76 | 77 | public void DrawRay() 78 | { 79 | Debug.DrawLine(origin, origin + direction * distance, Color.green, 10); 80 | } 81 | } 82 | 83 | public class RaycastHit 84 | { 85 | public Vector3 point; 86 | public Transform transform; 87 | } 88 | -------------------------------------------------------------------------------- /Assets/Scripts/Ray.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 857063d6573f56b46ad48cbf0f2b4a75 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Sphere.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Experimental.PlayerLoop; 5 | 6 | public class Sphere : Box 7 | { 8 | public Vector3 center; 9 | public float radius; 10 | private Matrix4x4 matrix; 11 | private SphereStructureMode mode; 12 | 13 | public Sphere(Transform transform, SphereStructureMode mode) 14 | { 15 | this.transform = transform; 16 | this.mode = mode; 17 | matrix = transform.localToWorldMatrix; 18 | StructureSphere(mode, matrix); 19 | } 20 | 21 | void StructureSphere(SphereStructureMode mode, Matrix4x4 local2world) 22 | { 23 | Mesh mesh = transform.GetComponent().sharedMesh; 24 | List vertices = Util.GetNoRepeatVertices(mesh); 25 | for (int i = 0; i < vertices.Count; i++) 26 | { 27 | vertices[i] = local2world * MathUtil.Vector4(vertices[i], 1); 28 | } 29 | 30 | switch (mode) 31 | { 32 | case SphereStructureMode.Ritter: 33 | RitterSphere(vertices); 34 | break; 35 | case SphereStructureMode.RitterIter: 36 | RitterIterSphere(vertices); 37 | break; 38 | case SphereStructureMode.RitterEigen: 39 | RitterEigenSphere(vertices); 40 | break; 41 | } 42 | } 43 | 44 | void RitterSphere(List vertices) 45 | { 46 | Vector3 min = Vector3.zero; 47 | Vector3 max = Vector3.zero; 48 | for (int i = 1; i < vertices.Count; i++) 49 | { 50 | for (int j = 0; j < 3; j++) 51 | { 52 | if (vertices[i][j] < vertices[(int) min[j]][j]) 53 | { 54 | min[j] = i; 55 | } 56 | 57 | if (vertices[i][j] > vertices[(int) max[j]][j]) 58 | { 59 | max[j] = i; 60 | } 61 | } 62 | } 63 | 64 | float[] dist2 = new float[3]; 65 | for (int i = 0; i < 3; i++) 66 | { 67 | Vector3 offset = vertices[(int) max[i]] - vertices[(int) min[i]]; 68 | dist2[i] = Vector3.Dot(offset, offset); 69 | } 70 | 71 | int idx = 0; 72 | for (int i = 1; i < 3; i++) 73 | { 74 | if (dist2[i] > dist2[idx]) 75 | { 76 | idx = i; 77 | } 78 | } 79 | 80 | center = (vertices[(int) max[idx]] + vertices[(int) min[idx]]) * 0.5f; 81 | radius = Vector3.Distance(vertices[(int) max[idx]], center); 82 | 83 | ApproachSphere(this, vertices); 84 | 85 | } 86 | 87 | void ApproachSphere(Sphere sphere, List vertices, bool random = false) 88 | { 89 | for (int i = 0; i < vertices.Count; i++) 90 | { 91 | if (random && i < vertices.Count - 1) 92 | { 93 | int randomIdx = Random.Range(i + 1, vertices.Count); 94 | Vector3 tmp = vertices[randomIdx]; 95 | vertices[randomIdx] = vertices[i]; 96 | vertices[i] = tmp; 97 | } 98 | 99 | Vector3 d = vertices[i] - sphere.center; 100 | float d2 = Vector3.Dot(d, d); 101 | if (d2 > sphere.radius * sphere.radius) 102 | { 103 | float dist = Mathf.Sqrt(d2); 104 | float newRadius = (sphere.radius + dist) * 0.5f; 105 | float k = (newRadius - sphere.radius) / dist; 106 | sphere.radius = newRadius; 107 | sphere.center += d * k; 108 | } 109 | } 110 | } 111 | 112 | void RitterIterSphere(List vertices, int iter = 8, float shrink = 0.95f) 113 | { 114 | RitterSphere(vertices); 115 | Sphere sphere = Clone(); 116 | for (int i = 0; i < iter; i++) 117 | { 118 | sphere.radius *= shrink; 119 | ApproachSphere(sphere, vertices, true); 120 | if (sphere.radius < radius) 121 | { 122 | radius = sphere.radius; 123 | center = sphere.center; 124 | } 125 | } 126 | } 127 | 128 | void RitterEigenSphere(List vertices) 129 | { 130 | Matrix4x4 covarianceM = MathUtil.GetCovarianceMatrix(vertices); 131 | Matrix4x4 eigenM = MathUtil.Jacobi(ref covarianceM); 132 | MathUtil.EigenSort(ref eigenM, ref covarianceM); 133 | MathUtil.SchmidtOrthogonalization(ref eigenM); 134 | //得到具有最大特征值的主轴 135 | Vector3 axis = eigenM.GetColumn(0); 136 | int min = 0; 137 | int max = 0; 138 | float dmin = Vector3.Dot(axis, vertices[0]); 139 | float dmax = dmin; 140 | for (int i = 1; i < vertices.Count; i++) 141 | { 142 | float tmp = Vector3.Dot(axis, vertices[i]); 143 | if (tmp < dmin) 144 | { 145 | min = i; 146 | dmin = tmp; 147 | } 148 | 149 | if (tmp > dmax) 150 | { 151 | max = i; 152 | dmax = tmp; 153 | } 154 | } 155 | 156 | center = (vertices[max] + vertices[min]) * 0.5f; 157 | radius = Vector3.Distance(vertices[max], center); 158 | 159 | ApproachSphere(this, vertices); 160 | } 161 | 162 | public void UpdateSphere(SphereStructureMode mode) 163 | { 164 | Matrix4x4 m = transform.localToWorldMatrix; 165 | //发生缩放需要重构包围球 166 | if (MathUtil.IsContainScale(matrix, m) || this.mode != mode) 167 | { 168 | StructureSphere(mode, m); 169 | this.mode = mode; 170 | } 171 | else 172 | { 173 | //旋转不需要改变包围球 174 | //平移只需把球心偏移即可 175 | Vector3 translation = MathUtil.GetTranslation(matrix, m); 176 | center += translation; 177 | } 178 | 179 | matrix = m; 180 | } 181 | 182 | public void DrawSphere() 183 | { 184 | Gizmos.color = Color.yellow; 185 | Gizmos.DrawWireSphere(center, radius); 186 | } 187 | 188 | public override bool RayDetection(Ray ray, RaycastHit hitInfo) 189 | { 190 | Vector3 e = center - ray.origin; 191 | 192 | float a = Vector3.Dot(e, ray.direction); 193 | if (a <= 0) 194 | { 195 | return false; 196 | } 197 | 198 | float f2 = radius * radius - Vector3.Dot(e, e) + a * a; 199 | if (f2 < 0) 200 | { 201 | return false; 202 | } 203 | 204 | float t = a - Mathf.Sqrt(f2); 205 | if (t < 0 || t > ray.distance) 206 | { 207 | return false; 208 | } 209 | 210 | ray.distance = t; 211 | hitInfo.point = ray.origin + ray.direction * t; 212 | hitInfo.transform = transform; 213 | return true; 214 | } 215 | 216 | public override bool BoxDetection(Box box) 217 | { 218 | if (box is Sphere) 219 | { 220 | return Util.TestSphereSphere(this, box as Sphere); 221 | } 222 | else if (box is AABB) 223 | { 224 | return Util.TestAABBSphere(box as AABB, this); 225 | } 226 | else if (box is OBB) 227 | { 228 | return Util.TestOBBSphere(box as OBB, this); 229 | } 230 | 231 | return false; 232 | } 233 | 234 | public Sphere Union(Sphere sphere) 235 | { 236 | Vector3 d = sphere.center - center; 237 | float dist2 = Vector3.Dot(d, d); 238 | if ((sphere.radius - radius) * (sphere.radius - radius) >= dist2) 239 | { 240 | if (sphere.radius > radius) 241 | { 242 | center = sphere.center; 243 | radius = sphere.radius; 244 | } 245 | } 246 | else 247 | { 248 | float dist = Mathf.Sqrt(dist2); 249 | float oldRadius = radius; 250 | radius = (dist + oldRadius + sphere.radius) * 0.5f; 251 | center += (radius - oldRadius) / dist * d; 252 | } 253 | 254 | return this; 255 | } 256 | 257 | public override AABB OuterAABB() 258 | { 259 | AABB aabb = new AABB(center - Vector3.one * radius, center + Vector3.one * radius); 260 | aabb.transform = transform; 261 | return aabb; 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /Assets/Scripts/Sphere.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1113e59960e6d884c96ce8ba4cbee5a1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/SphereCollider.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class SphereCollider : BoxCollider 6 | { 7 | 8 | public SphereStructureMode mode = SphereStructureMode.RitterIter; 9 | 10 | private Sphere sphere; 11 | 12 | // Use this for initialization 13 | void Awake() 14 | { 15 | sphere = new Sphere(transform, mode); 16 | box = sphere; 17 | } 18 | 19 | // Update is called once per frame 20 | void Update() 21 | { 22 | sphere.UpdateSphere(mode); 23 | } 24 | 25 | void OnDrawGizmos() 26 | { 27 | if (sphere != null) 28 | { 29 | sphere.DrawSphere(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Assets/Scripts/SphereCollider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe85f235519a71d4e95434fda62a225e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/SubDivision.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using UnityEditor.Experimental.UIElements.GraphView; 6 | using UnityEngine; 7 | using UnityEngine.UI; 8 | 9 | public class Edge 10 | { 11 | public int[] vertexIdx; 12 | public List faceIdx; 13 | public Vector3 newPos; 14 | 15 | public Edge(int vidx1, int vidx2) 16 | { 17 | if (vidx1 < vidx2) 18 | { 19 | vertexIdx = new[] {vidx1, vidx2}; 20 | } 21 | else 22 | { 23 | vertexIdx = new[] {vidx2, vidx1}; 24 | } 25 | 26 | faceIdx = new List(); 27 | } 28 | 29 | public override bool Equals(object obj) 30 | { 31 | Edge edge = obj as Edge; 32 | return Enumerable.SequenceEqual(vertexIdx, edge.vertexIdx); 33 | } 34 | } 35 | 36 | public class SubDivision : MonoBehaviour 37 | { 38 | 39 | public int iter; 40 | 41 | // Use this for initialization 42 | void Start() 43 | { 44 | Mesh mesh = transform.GetComponent().mesh; 45 | for (int iter = 0; iter < this.iter; iter++) 46 | { 47 | Vector3[] vertexs = new Vector3[mesh.vertexCount]; 48 | List edges = new List(); 49 | Dictionary edgeDict = new Dictionary(); 50 | HashSet[] degrees = new HashSet[mesh.vertexCount]; 51 | Vector3Int[] faces = new Vector3Int[mesh.triangles.Length / 3]; 52 | HashSet edgeVertexs = new HashSet(); 53 | 54 | for (int i = 0; i < degrees.Length; i++) 55 | { 56 | degrees[i] = new HashSet(); 57 | } 58 | 59 | for (int i = 0; i < faces.Length; i++) 60 | { 61 | faces[i] = Vector3Int.zero; 62 | } 63 | 64 | for (int i = 0; i < mesh.triangles.Length; i += 3) 65 | { 66 | int idx1 = mesh.triangles[i]; 67 | int idx2 = mesh.triangles[i + 1]; 68 | int idx3 = mesh.triangles[i + 2]; 69 | AddDegree(degrees, idx1, idx2); 70 | AddDegree(degrees, idx1, idx3); 71 | AddDegree(degrees, idx2, idx3); 72 | int face = i / 3; 73 | AddFace(faces, face, 0, AddEdge(edges, edgeDict, idx1, idx2, i)); 74 | AddFace(faces, face, 1, AddEdge(edges, edgeDict, idx2, idx3, i)); 75 | AddFace(faces, face, 2, AddEdge(edges, edgeDict, idx3, idx1, i)); 76 | } 77 | 78 | for (int i = 0; i < edges.Count; i++) 79 | { 80 | Edge edge = edges[i]; 81 | if (edge.faceIdx.Count == 1) 82 | { 83 | edgeVertexs.Add(edge.vertexIdx[0]); 84 | edgeVertexs.Add(edge.vertexIdx[1]); 85 | edge.newPos = (mesh.vertices[edge.vertexIdx[0]] + mesh.vertices[edge.vertexIdx[1]]) * 0.5f; 86 | } 87 | else 88 | { 89 | edge.newPos = Vector3.zero; 90 | edge.newPos += (mesh.vertices[edge.vertexIdx[0]] + mesh.vertices[edge.vertexIdx[1]]) * 0.375f; 91 | int idx1 = GetOtherIdx(mesh.triangles, edge.faceIdx[0], edge.vertexIdx[0], edge.vertexIdx[1]); 92 | int idx2 = GetOtherIdx(mesh.triangles, edge.faceIdx[1], edge.vertexIdx[0], edge.vertexIdx[1]); 93 | edge.newPos += (mesh.vertices[idx1] + mesh.vertices[idx2]) * 0.125f; 94 | } 95 | } 96 | 97 | for (int i = 0; i < vertexs.Length; i++) 98 | { 99 | Vector3 tmp = Vector3.zero; 100 | if (edgeVertexs.Contains(i)) 101 | { 102 | vertexs[i] = 0.75f * mesh.vertices[i]; 103 | int count = 0; 104 | foreach (int j in degrees[i]) 105 | { 106 | if (edgeVertexs.Contains(j)) 107 | { 108 | String key = i < j ? i + "," + j : j + "," + i; 109 | if (edgeDict.ContainsKey(key) && edges[edgeDict[key]].faceIdx.Count == 1) 110 | { 111 | tmp += mesh.vertices[j]; 112 | count++; 113 | if (count == 2) 114 | { 115 | break; 116 | } 117 | } 118 | } 119 | } 120 | 121 | vertexs[i] += 0.125f * tmp; 122 | } 123 | else 124 | { 125 | int degree = degrees[i].Count; 126 | float beta = (0.625f - Mathf.Pow(0.375f + 0.25f * Mathf.Cos(Mathf.PI * 2.0f / degree), 2.0f)) / 127 | degree; 128 | vertexs[i] = (1 - degree * beta) * mesh.vertices[i]; 129 | foreach (int j in degrees[i]) 130 | { 131 | tmp += mesh.vertices[j]; 132 | } 133 | 134 | vertexs[i] += beta * tmp; 135 | } 136 | } 137 | 138 | Vector3[] newVertexs = new Vector3[vertexs.Length + edges.Count]; 139 | for (int i = 0; i < newVertexs.Length; i++) 140 | { 141 | if (i < vertexs.Length) 142 | { 143 | newVertexs[i] = vertexs[i]; 144 | } 145 | else 146 | { 147 | newVertexs[i] = edges[i - vertexs.Length].newPos; 148 | } 149 | } 150 | 151 | int[] newTriangles = new int[mesh.triangles.Length * 4]; 152 | for (int i = 0; i < faces.Length; i++) 153 | { 154 | int fidx1 = faces[i][0]; 155 | int fidx2 = faces[i][1]; 156 | int fidx3 = faces[i][2]; 157 | Edge edge1 = edges[fidx1]; 158 | Edge edge2 = edges[fidx2]; 159 | CheckOrder(edge1, mesh.triangles[i * 3]); 160 | CheckOrder(edge2, mesh.triangles[i * 3 + 1]); 161 | newTriangles[i * 12] = edge1.vertexIdx[0]; 162 | newTriangles[i * 12 + 1] = vertexs.Length + fidx1; 163 | newTriangles[i * 12 + 2] = vertexs.Length + fidx3; 164 | newTriangles[i * 12 + 3] = vertexs.Length + fidx1; 165 | newTriangles[i * 12 + 4] = edge1.vertexIdx[1]; 166 | newTriangles[i * 12 + 5] = vertexs.Length + fidx2; 167 | newTriangles[i * 12 + 6] = vertexs.Length + fidx3; 168 | newTriangles[i * 12 + 7] = vertexs.Length + fidx2; 169 | newTriangles[i * 12 + 8] = edge2.vertexIdx[1]; 170 | newTriangles[i * 12 + 9] = vertexs.Length + fidx1; 171 | newTriangles[i * 12 + 10] = vertexs.Length + fidx2; 172 | newTriangles[i * 12 + 11] = vertexs.Length + fidx3; 173 | } 174 | 175 | mesh.vertices = newVertexs; 176 | mesh.triangles = newTriangles; 177 | } 178 | 179 | mesh.RecalculateNormals(); 180 | transform.GetComponent().mesh = mesh; 181 | } 182 | 183 | void CheckOrder(Edge edge, int idx1) 184 | { 185 | if (edge.vertexIdx[0] != idx1) 186 | { 187 | int tmp = edge.vertexIdx[0]; 188 | edge.vertexIdx[0] = edge.vertexIdx[1]; 189 | edge.vertexIdx[1] = tmp; 190 | } 191 | } 192 | 193 | int GetOtherIdx(int[] triangles, int idx, int idx1, int idx2) 194 | { 195 | if (triangles[idx] != idx1 && triangles[idx] != idx2) 196 | { 197 | return triangles[idx]; 198 | } 199 | else if (triangles[idx + 1] != idx1 && triangles[idx + 1] != idx2) 200 | { 201 | return triangles[idx + 1]; 202 | } 203 | else 204 | { 205 | return triangles[idx + 2]; 206 | } 207 | } 208 | 209 | void AddDegree(HashSet[] degrees, int idx1, int idx2) 210 | { 211 | degrees[idx1].Add(idx2); 212 | degrees[idx2].Add(idx1); 213 | } 214 | 215 | int AddEdge(List edges, Dictionary edgeDict, int idx1, int idx2, int face) 216 | { 217 | Edge edge = new Edge(idx1, idx2); 218 | String key = edge.vertexIdx[0] + "," + edge.vertexIdx[1]; 219 | int idx = edgeDict.ContainsKey(key) ? edgeDict[key] : -1; 220 | if (idx >= 0) 221 | { 222 | edges[idx].faceIdx.Add(face); 223 | return idx; 224 | } 225 | else 226 | { 227 | edge.faceIdx.Add(face); 228 | edges.Add(edge); 229 | edgeDict.Add(key, edges.Count - 1); 230 | return edges.Count - 1; 231 | } 232 | } 233 | 234 | void AddFace(Vector3Int[] faces, int idx1, int idx2, int edge) 235 | { 236 | faces[idx1][idx2] = edge; 237 | } 238 | } -------------------------------------------------------------------------------- /Assets/Scripts/SubDivision.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3383699b98ff30146b5b6f5effb88b9e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Test.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Test : MonoBehaviour 6 | { 7 | private CameraHelper cameraHelper; 8 | 9 | void Start() 10 | { 11 | cameraHelper = new CameraHelper(Camera.main); 12 | } 13 | 14 | // Update is called once per frame 15 | void Update() 16 | { 17 | if (Input.GetKeyDown(KeyCode.A)) 18 | { 19 | TestBoxDetection(); 20 | } 21 | } 22 | 23 | void TestBoxDetection() 24 | { 25 | BoxCollider[] boxColliders = GameObject.FindObjectsOfType(); 26 | for (int i = 0; i < boxColliders.Length - 1; i++) 27 | { 28 | for (int j = i + 1; j < boxColliders.Length; j++) 29 | { 30 | if (boxColliders[i].box.BoxDetection(boxColliders[j].box)) 31 | { 32 | Debug.DrawLine(boxColliders[i].transform.position, boxColliders[j].transform.position, Color.green, 33 | 10); 34 | } 35 | } 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Assets/Scripts/Test.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c12b295dc95cbfd4e8473cafb81c0a9a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Util.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.Serialization.Formatters.Binary; 6 | using UnityEngine; 7 | 8 | public static class Util 9 | { 10 | //去掉unity mesh里面重复的顶点 11 | public static List GetNoRepeatVertices(Mesh mesh) 12 | { 13 | HashSet set = new HashSet(); 14 | 15 | for (int i = 0; i < mesh.vertices.Length; i++) 16 | { 17 | if (!set.Contains(mesh.vertices[i])) 18 | { 19 | set.Add(mesh.vertices[i]); 20 | } 21 | } 22 | 23 | return set.ToList(); 24 | } 25 | 26 | public static bool TestAABBAABB(AABB aabb1, AABB aabb2) 27 | { 28 | for (int i = 0; i < 3; i++) 29 | { 30 | if (aabb1.transformMin[i] > aabb2.transformMax[i] || aabb1.transformMax[i] < aabb2.transformMin[i]) 31 | return false; 32 | } 33 | 34 | return true; 35 | } 36 | 37 | public static bool TestSphereSphere(Sphere sphere1, Sphere sphere2) 38 | { 39 | Vector3 d = sphere2.center - sphere1.center; 40 | float rSum = sphere1.radius + sphere2.radius; 41 | return Vector3.Dot(d, d) <= rSum * rSum; 42 | } 43 | 44 | 45 | public static bool TestAABBSphere(AABB aabb, Sphere sphere) 46 | { 47 | Vector3 p = aabb.ClosestPoint(sphere.center); 48 | Vector3 d = sphere.center - p; 49 | return Vector3.Dot(d, d) <= sphere.radius * sphere.radius; 50 | } 51 | 52 | public static bool TestOBBSphere(OBB obb, Sphere sphere) 53 | { 54 | sphere = sphere.Clone(); 55 | sphere.center = obb.RTMatrix * MathUtil.Vector4(sphere.center, 1); 56 | return TestAABBSphere(obb.GetAABB(), sphere); 57 | } 58 | 59 | public static bool TestOBBOBB(OBB obb1, OBB obb2) 60 | { 61 | //This algorithm comes from Separating Axis Theorem for Oriented Bounding Boxes 62 | 63 | //设置B到A的旋转矩阵 64 | Matrix4x4 r = Matrix4x4.identity; 65 | Matrix4x4 absR = Matrix4x4.identity; 66 | for (int i = 0; i < 3; i++) 67 | { 68 | for (int j = 0; j < 3; j++) 69 | { 70 | r[i, j] = Vector3.Dot(obb1.axis[i], obb2.axis[j]); 71 | absR[i, j] = Mathf.Abs(r[i, j]) + float.Epsilon; 72 | } 73 | } 74 | 75 | //t为A到B的位移向量 76 | Vector3 t = obb2.transformCenter - obb1.transformCenter; 77 | t = new Vector3(Vector3.Dot(obb1.axis[0], t), Vector3.Dot(obb1.axis[1], t), Vector3.Dot(obb1.axis[2], t)); 78 | 79 | float ra, rb; 80 | 81 | //测试分离轴 obb1.axis[0], obb1.axis[1], obb1.axis[2] 82 | for (int i = 0; i < 3; i++) 83 | { 84 | ra = obb1.transformRadius[i]; 85 | rb = obb2.transformRadius[0] * absR[i, 0] + obb2.transformRadius[1] * absR[i, 1] + 86 | obb2.transformRadius[2] * absR[i, 2]; 87 | if (Mathf.Abs(t[i]) > ra + rb) 88 | { 89 | return false; 90 | } 91 | } 92 | 93 | //测试分离轴 obb2.axis[0], obb2.axis[1], obb2.axis[2] 94 | for (int i = 0; i < 3; i++) 95 | { 96 | ra = obb1.transformRadius[0] * absR[0, i] + obb1.transformRadius[1] * absR[1, i] + 97 | obb1.transformRadius[2] * absR[2, i]; 98 | rb = obb2.transformRadius[i]; 99 | if (Mathf.Abs(t[0] * r[0, i] + t[1] * r[1, i] + t[2] * r[2, i]) > ra + rb) 100 | { 101 | return false; 102 | } 103 | } 104 | 105 | //测试分离轴 obb1.axis[0] X obb2.axis[0] 106 | ra = obb1.transformRadius[1] * absR[2, 0] + obb1.transformRadius[2] * absR[1, 0]; 107 | rb = obb2.transformRadius[1] * absR[0, 2] + obb2.transformRadius[2] * absR[0, 1]; 108 | if (Mathf.Abs(t[2] * absR[1, 0] - t[1] * absR[2, 0]) > ra + rb) 109 | { 110 | return false; 111 | } 112 | 113 | //测试分离轴 obb1.axis[0] X obb2.axis[1] 114 | ra = obb1.transformRadius[1] * absR[2, 1] + obb1.transformRadius[2] * absR[1, 1]; 115 | rb = obb2.transformRadius[0] * absR[0, 2] + obb2.transformRadius[2] * absR[0, 0]; 116 | if (Mathf.Abs(t[2] * absR[1, 1] - t[1] * absR[2, 1]) > ra + rb) 117 | { 118 | return false; 119 | } 120 | 121 | //测试分离轴 obb1.axis[0] X obb2.axis[2] 122 | ra = obb1.transformRadius[1] * absR[2, 2] + obb1.transformRadius[2] * absR[1, 2]; 123 | rb = obb2.transformRadius[0] * absR[0, 1] + obb2.transformRadius[1] * absR[0, 0]; 124 | if (Mathf.Abs(t[2] * absR[1, 2] - t[1] * absR[2, 2]) > ra + rb) 125 | { 126 | return false; 127 | } 128 | 129 | //测试分离轴 obb1.axis[1] X obb2.axis[0] 130 | ra = obb1.transformRadius[0] * absR[2, 0] + obb1.transformRadius[2] * absR[0, 0]; 131 | rb = obb2.transformRadius[1] * absR[1, 2] + obb2.transformRadius[2] * absR[1, 1]; 132 | if (Mathf.Abs(t[0] * absR[2, 0] - t[2] * absR[0, 0]) > ra + rb) 133 | { 134 | return false; 135 | } 136 | 137 | //测试分离轴 obb1.axis[1] X obb2.axis[1] 138 | ra = obb1.transformRadius[0] * absR[2, 1] + obb1.transformRadius[2] * absR[0, 1]; 139 | rb = obb2.transformRadius[0] * absR[1, 2] + obb2.transformRadius[2] * absR[1, 0]; 140 | if (Mathf.Abs(t[0] * absR[2, 1] - t[2] * absR[0, 1]) > ra + rb) 141 | { 142 | return false; 143 | } 144 | 145 | //测试分离轴 obb1.axis[1] X obb2.axis[2] 146 | ra = obb1.transformRadius[0] * absR[2, 2] + obb1.transformRadius[2] * absR[0, 2]; 147 | rb = obb2.transformRadius[0] * absR[1, 1] + obb2.transformRadius[1] * absR[1, 0]; 148 | if (Mathf.Abs(t[0] * absR[2, 2] - t[2] * absR[0, 2]) > ra + rb) 149 | { 150 | return false; 151 | } 152 | 153 | //测试分离轴 obb1.axis[2] X obb2.axis[0] 154 | ra = obb1.transformRadius[0] * absR[1, 0] + obb1.transformRadius[1] * absR[0, 0]; 155 | rb = obb2.transformRadius[1] * absR[2, 2] + obb2.transformRadius[2] * absR[2, 1]; 156 | if (Mathf.Abs(t[1] * absR[0, 0] - t[0] * absR[1, 0]) > ra + rb) 157 | { 158 | return false; 159 | } 160 | 161 | //测试分离轴 obb1.axis[2] X obb2.axis[1] 162 | ra = obb1.transformRadius[0] * absR[1, 1] + obb1.transformRadius[1] * absR[0, 1]; 163 | rb = obb2.transformRadius[0] * absR[2, 2] + obb2.transformRadius[2] * absR[2, 0]; 164 | if (Mathf.Abs(t[1] * absR[0, 1] - t[0] * absR[1, 1]) > ra + rb) 165 | { 166 | return false; 167 | } 168 | 169 | //测试分离轴 obb1.axis[2] X obb2.axis[2] 170 | ra = obb1.transformRadius[0] * absR[1, 2] + obb1.transformRadius[1] * absR[0, 2]; 171 | rb = obb2.transformRadius[0] * absR[2, 1] + obb2.transformRadius[1] * absR[2, 0]; 172 | if (Mathf.Abs(t[1] * absR[0, 2] - t[0] * absR[1, 2]) > ra + rb) 173 | { 174 | return false; 175 | } 176 | 177 | return true; 178 | } 179 | 180 | public static bool TestAABBOBB(AABB aabb, OBB obb) 181 | { 182 | return TestOBBOBB(aabb.GetOBB(), obb); 183 | } 184 | 185 | } 186 | -------------------------------------------------------------------------------- /Assets/Scripts/Util.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c397b0cfde2e4c3498e111e0ae2e4e35 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 1024 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_SpatializerPlugin: 15 | m_AmbisonicDecoderPlugin: 16 | m_DisableAudio: 0 17 | m_VirtualizeEffects: 1 18 | -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!236 &1 4 | ClusterInputManager: 5 | m_ObjectHideFlags: 0 6 | m_Inputs: [] 7 | -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_Gravity: {x: 0, y: -9.81, z: 0} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_BounceThreshold: 2 10 | m_SleepThreshold: 0.005 11 | m_DefaultContactOffset: 0.01 12 | m_DefaultSolverIterations: 6 13 | m_DefaultSolverVelocityIterations: 1 14 | m_QueriesHitBackfaces: 0 15 | m_QueriesHitTriggers: 1 16 | m_EnableAdaptiveForce: 0 17 | m_ClothInterCollisionDistance: 0 18 | m_ClothInterCollisionStiffness: 0 19 | m_ContactsGeneration: 1 20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 21 | m_AutoSimulation: 1 22 | m_AutoSyncTransforms: 1 23 | m_ClothInterCollisionSettingsToggle: 0 24 | m_ContactPairsMode: 0 25 | m_BroadphaseType: 0 26 | m_WorldBounds: 27 | m_Center: {x: 0, y: 0, z: 0} 28 | m_Extent: {x: 250, y: 250, z: 250} 29 | m_WorldSubdivisions: 8 30 | -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: 8 | - enabled: 1 9 | path: Assets/Scenes/SampleScene.unity 10 | guid: 99c9720ab356a0642a771bea13969a05 11 | m_configObjects: {} 12 | -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 7 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_LineEndingsForNewScripts: 2 10 | m_DefaultBehaviorMode: 0 11 | m_SpritePackerMode: 0 12 | m_SpritePackerPaddingPower: 1 13 | m_EtcTextureCompressorBehavior: 1 14 | m_EtcTextureFastCompressor: 1 15 | m_EtcTextureNormalCompressor: 2 16 | m_EtcTextureBestCompressor: 4 17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef 18 | m_ProjectGenerationRootNamespace: 19 | m_UserGeneratedProjectSuffix: 20 | m_CollabEditorSettings: 21 | inProgressEnabled: 1 22 | m_EnableTextureStreamingInPlayMode: 1 23 | -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 12 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_DeferredReflections: 11 | m_Mode: 1 12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0} 13 | m_ScreenSpaceShadows: 14 | m_Mode: 1 15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0} 16 | m_LegacyDeferred: 17 | m_Mode: 1 18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 19 | m_DepthNormals: 20 | m_Mode: 1 21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0} 22 | m_MotionVectors: 23 | m_Mode: 1 24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0} 25 | m_LightHalo: 26 | m_Mode: 1 27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0} 28 | m_LensFlare: 29 | m_Mode: 1 30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0} 31 | m_AlwaysIncludedShaders: 32 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 33 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 34 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 35 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 36 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} 37 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 38 | m_PreloadedShaders: [] 39 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, 40 | type: 0} 41 | m_CustomRenderPipeline: {fileID: 0} 42 | m_TransparencySortMode: 0 43 | m_TransparencySortAxis: {x: 0, y: 0, z: 1} 44 | m_DefaultRenderingPath: 1 45 | m_DefaultMobileRenderingPath: 1 46 | m_TierSettings: [] 47 | m_LightmapStripping: 0 48 | m_FogStripping: 0 49 | m_InstancingStripping: 0 50 | m_LightmapKeepPlain: 1 51 | m_LightmapKeepDirCombined: 1 52 | m_LightmapKeepDynamicPlain: 1 53 | m_LightmapKeepDynamicDirCombined: 1 54 | m_LightmapKeepShadowMask: 1 55 | m_LightmapKeepSubtractive: 1 56 | m_FogKeepLinear: 1 57 | m_FogKeepExp: 1 58 | m_FogKeepExp2: 1 59 | m_AlbedoSwatchInfos: [] 60 | m_LightsUseLinearIntensity: 0 61 | m_LightsUseColorTemperature: 0 62 | -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!13 &1 4 | InputManager: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Axes: 8 | - serializedVersion: 3 9 | m_Name: Horizontal 10 | descriptiveName: 11 | descriptiveNegativeName: 12 | negativeButton: left 13 | positiveButton: right 14 | altNegativeButton: a 15 | altPositiveButton: d 16 | gravity: 3 17 | dead: 0.001 18 | sensitivity: 3 19 | snap: 1 20 | invert: 0 21 | type: 0 22 | axis: 0 23 | joyNum: 0 24 | - serializedVersion: 3 25 | m_Name: Vertical 26 | descriptiveName: 27 | descriptiveNegativeName: 28 | negativeButton: down 29 | positiveButton: up 30 | altNegativeButton: s 31 | altPositiveButton: w 32 | gravity: 3 33 | dead: 0.001 34 | sensitivity: 3 35 | snap: 1 36 | invert: 0 37 | type: 0 38 | axis: 0 39 | joyNum: 0 40 | - serializedVersion: 3 41 | m_Name: Fire1 42 | descriptiveName: 43 | descriptiveNegativeName: 44 | negativeButton: 45 | positiveButton: left ctrl 46 | altNegativeButton: 47 | altPositiveButton: mouse 0 48 | gravity: 1000 49 | dead: 0.001 50 | sensitivity: 1000 51 | snap: 0 52 | invert: 0 53 | type: 0 54 | axis: 0 55 | joyNum: 0 56 | - serializedVersion: 3 57 | m_Name: Fire2 58 | descriptiveName: 59 | descriptiveNegativeName: 60 | negativeButton: 61 | positiveButton: left alt 62 | altNegativeButton: 63 | altPositiveButton: mouse 1 64 | gravity: 1000 65 | dead: 0.001 66 | sensitivity: 1000 67 | snap: 0 68 | invert: 0 69 | type: 0 70 | axis: 0 71 | joyNum: 0 72 | - serializedVersion: 3 73 | m_Name: Fire3 74 | descriptiveName: 75 | descriptiveNegativeName: 76 | negativeButton: 77 | positiveButton: left shift 78 | altNegativeButton: 79 | altPositiveButton: mouse 2 80 | gravity: 1000 81 | dead: 0.001 82 | sensitivity: 1000 83 | snap: 0 84 | invert: 0 85 | type: 0 86 | axis: 0 87 | joyNum: 0 88 | - serializedVersion: 3 89 | m_Name: Jump 90 | descriptiveName: 91 | descriptiveNegativeName: 92 | negativeButton: 93 | positiveButton: space 94 | altNegativeButton: 95 | altPositiveButton: 96 | gravity: 1000 97 | dead: 0.001 98 | sensitivity: 1000 99 | snap: 0 100 | invert: 0 101 | type: 0 102 | axis: 0 103 | joyNum: 0 104 | - serializedVersion: 3 105 | m_Name: Mouse X 106 | descriptiveName: 107 | descriptiveNegativeName: 108 | negativeButton: 109 | positiveButton: 110 | altNegativeButton: 111 | altPositiveButton: 112 | gravity: 0 113 | dead: 0 114 | sensitivity: 0.1 115 | snap: 0 116 | invert: 0 117 | type: 1 118 | axis: 0 119 | joyNum: 0 120 | - serializedVersion: 3 121 | m_Name: Mouse Y 122 | descriptiveName: 123 | descriptiveNegativeName: 124 | negativeButton: 125 | positiveButton: 126 | altNegativeButton: 127 | altPositiveButton: 128 | gravity: 0 129 | dead: 0 130 | sensitivity: 0.1 131 | snap: 0 132 | invert: 0 133 | type: 1 134 | axis: 1 135 | joyNum: 0 136 | - serializedVersion: 3 137 | m_Name: Mouse ScrollWheel 138 | descriptiveName: 139 | descriptiveNegativeName: 140 | negativeButton: 141 | positiveButton: 142 | altNegativeButton: 143 | altPositiveButton: 144 | gravity: 0 145 | dead: 0 146 | sensitivity: 0.1 147 | snap: 0 148 | invert: 0 149 | type: 1 150 | axis: 2 151 | joyNum: 0 152 | - serializedVersion: 3 153 | m_Name: Horizontal 154 | descriptiveName: 155 | descriptiveNegativeName: 156 | negativeButton: 157 | positiveButton: 158 | altNegativeButton: 159 | altPositiveButton: 160 | gravity: 0 161 | dead: 0.19 162 | sensitivity: 1 163 | snap: 0 164 | invert: 0 165 | type: 2 166 | axis: 0 167 | joyNum: 0 168 | - serializedVersion: 3 169 | m_Name: Vertical 170 | descriptiveName: 171 | descriptiveNegativeName: 172 | negativeButton: 173 | positiveButton: 174 | altNegativeButton: 175 | altPositiveButton: 176 | gravity: 0 177 | dead: 0.19 178 | sensitivity: 1 179 | snap: 0 180 | invert: 1 181 | type: 2 182 | axis: 1 183 | joyNum: 0 184 | - serializedVersion: 3 185 | m_Name: Fire1 186 | descriptiveName: 187 | descriptiveNegativeName: 188 | negativeButton: 189 | positiveButton: joystick button 0 190 | altNegativeButton: 191 | altPositiveButton: 192 | gravity: 1000 193 | dead: 0.001 194 | sensitivity: 1000 195 | snap: 0 196 | invert: 0 197 | type: 0 198 | axis: 0 199 | joyNum: 0 200 | - serializedVersion: 3 201 | m_Name: Fire2 202 | descriptiveName: 203 | descriptiveNegativeName: 204 | negativeButton: 205 | positiveButton: joystick button 1 206 | altNegativeButton: 207 | altPositiveButton: 208 | gravity: 1000 209 | dead: 0.001 210 | sensitivity: 1000 211 | snap: 0 212 | invert: 0 213 | type: 0 214 | axis: 0 215 | joyNum: 0 216 | - serializedVersion: 3 217 | m_Name: Fire3 218 | descriptiveName: 219 | descriptiveNegativeName: 220 | negativeButton: 221 | positiveButton: joystick button 2 222 | altNegativeButton: 223 | altPositiveButton: 224 | gravity: 1000 225 | dead: 0.001 226 | sensitivity: 1000 227 | snap: 0 228 | invert: 0 229 | type: 0 230 | axis: 0 231 | joyNum: 0 232 | - serializedVersion: 3 233 | m_Name: Jump 234 | descriptiveName: 235 | descriptiveNegativeName: 236 | negativeButton: 237 | positiveButton: joystick button 3 238 | altNegativeButton: 239 | altPositiveButton: 240 | gravity: 1000 241 | dead: 0.001 242 | sensitivity: 1000 243 | snap: 0 244 | invert: 0 245 | type: 0 246 | axis: 0 247 | joyNum: 0 248 | - serializedVersion: 3 249 | m_Name: Submit 250 | descriptiveName: 251 | descriptiveNegativeName: 252 | negativeButton: 253 | positiveButton: return 254 | altNegativeButton: 255 | altPositiveButton: joystick button 0 256 | gravity: 1000 257 | dead: 0.001 258 | sensitivity: 1000 259 | snap: 0 260 | invert: 0 261 | type: 0 262 | axis: 0 263 | joyNum: 0 264 | - serializedVersion: 3 265 | m_Name: Submit 266 | descriptiveName: 267 | descriptiveNegativeName: 268 | negativeButton: 269 | positiveButton: enter 270 | altNegativeButton: 271 | altPositiveButton: space 272 | gravity: 1000 273 | dead: 0.001 274 | sensitivity: 1000 275 | snap: 0 276 | invert: 0 277 | type: 0 278 | axis: 0 279 | joyNum: 0 280 | - serializedVersion: 3 281 | m_Name: Cancel 282 | descriptiveName: 283 | descriptiveNegativeName: 284 | negativeButton: 285 | positiveButton: escape 286 | altNegativeButton: 287 | altPositiveButton: joystick button 1 288 | gravity: 1000 289 | dead: 0.001 290 | sensitivity: 1000 291 | snap: 0 292 | invert: 0 293 | type: 0 294 | axis: 0 295 | joyNum: 0 296 | -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshProjectSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | m_LastAgentTypeID: -887442657 73 | m_Settings: 74 | - serializedVersion: 2 75 | agentTypeID: 0 76 | agentRadius: 0.5 77 | agentHeight: 2 78 | agentSlope: 45 79 | agentClimb: 0.75 80 | ledgeDropHeight: 0 81 | maxJumpAcrossDistance: 0 82 | minRegionArea: 2 83 | manualCellSize: 0 84 | cellSize: 0.16666667 85 | manualTileSize: 0 86 | tileSize: 256 87 | accuratePlacement: 0 88 | debug: 89 | m_Flags: 0 90 | m_SettingNames: 91 | - Humanoid 92 | -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Gravity: {x: 0, y: -9.81} 8 | m_DefaultMaterial: {fileID: 0} 9 | m_VelocityIterations: 8 10 | m_PositionIterations: 3 11 | m_VelocityThreshold: 1 12 | m_MaxLinearCorrection: 0.2 13 | m_MaxAngularCorrection: 8 14 | m_MaxTranslationSpeed: 100 15 | m_MaxRotationSpeed: 360 16 | m_BaumgarteScale: 0.2 17 | m_BaumgarteTimeOfImpactScale: 0.75 18 | m_TimeToSleep: 0.5 19 | m_LinearSleepTolerance: 0.01 20 | m_AngularSleepTolerance: 2 21 | m_DefaultContactOffset: 0.01 22 | m_AutoSimulation: 1 23 | m_QueriesHitTriggers: 1 24 | m_QueriesStartInColliders: 1 25 | m_ChangeStopsCallbacks: 0 26 | m_CallbacksOnDisable: 1 27 | m_AutoSyncTransforms: 1 28 | m_AlwaysShowColliders: 0 29 | m_ShowColliderSleep: 1 30 | m_ShowColliderContacts: 0 31 | m_ShowColliderAABB: 0 32 | m_ContactArrowScale: 0.2 33 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412} 34 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} 35 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} 36 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} 37 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 38 | -------------------------------------------------------------------------------- /ProjectSettings/PresetManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1386491679 &1 4 | PresetManager: 5 | m_ObjectHideFlags: 0 6 | m_DefaultList: 7 | - type: 8 | m_NativeTypeID: 108 9 | m_ManagedTypePPtr: {fileID: 0} 10 | m_ManagedTypeFallback: 11 | defaultPresets: 12 | - m_Preset: {fileID: 2655988077585873504, guid: c1cf8506f04ef2c4a88b64b6c4202eea, 13 | type: 2} 14 | - type: 15 | m_NativeTypeID: 1020 16 | m_ManagedTypePPtr: {fileID: 0} 17 | m_ManagedTypeFallback: 18 | defaultPresets: 19 | - m_Preset: {fileID: 2655988077585873504, guid: 0cd792cc87e492d43b4e95b205fc5cc6, 20 | type: 2} 21 | - type: 22 | m_NativeTypeID: 1006 23 | m_ManagedTypePPtr: {fileID: 0} 24 | m_ManagedTypeFallback: 25 | defaultPresets: 26 | - m_Preset: {fileID: 2655988077585873504, guid: 7a99f8aa944efe94cb9bd74562b7d5f9, 27 | type: 2} 28 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!129 &1 4 | PlayerSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 15 7 | productGUID: 118355becfd411547bdb3af421f04299 8 | AndroidProfiler: 0 9 | AndroidFilterTouchesWhenObscured: 0 10 | AndroidEnableSustainedPerformanceMode: 0 11 | defaultScreenOrientation: 4 12 | targetDevice: 2 13 | useOnDemandResources: 0 14 | accelerometerFrequency: 60 15 | companyName: DefaultCompany 16 | productName: CollisionDetection 17 | defaultCursor: {fileID: 0} 18 | cursorHotspot: {x: 0, y: 0} 19 | m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1} 20 | m_ShowUnitySplashScreen: 1 21 | m_ShowUnitySplashLogo: 1 22 | m_SplashScreenOverlayOpacity: 1 23 | m_SplashScreenAnimation: 1 24 | m_SplashScreenLogoStyle: 1 25 | m_SplashScreenDrawMode: 0 26 | m_SplashScreenBackgroundAnimationZoom: 1 27 | m_SplashScreenLogoAnimationZoom: 1 28 | m_SplashScreenBackgroundLandscapeAspect: 1 29 | m_SplashScreenBackgroundPortraitAspect: 1 30 | m_SplashScreenBackgroundLandscapeUvs: 31 | serializedVersion: 2 32 | x: 0 33 | y: 0 34 | width: 1 35 | height: 1 36 | m_SplashScreenBackgroundPortraitUvs: 37 | serializedVersion: 2 38 | x: 0 39 | y: 0 40 | width: 1 41 | height: 1 42 | m_SplashScreenLogos: [] 43 | m_VirtualRealitySplashScreen: {fileID: 0} 44 | m_HolographicTrackingLossScreen: {fileID: 0} 45 | defaultScreenWidth: 1024 46 | defaultScreenHeight: 768 47 | defaultScreenWidthWeb: 960 48 | defaultScreenHeightWeb: 600 49 | m_StereoRenderingPath: 0 50 | m_ActiveColorSpace: 0 51 | m_MTRendering: 1 52 | m_StackTraceTypes: 010000000100000001000000010000000100000001000000 53 | iosShowActivityIndicatorOnLoading: -1 54 | androidShowActivityIndicatorOnLoading: -1 55 | iosAppInBackgroundBehavior: 0 56 | displayResolutionDialog: 1 57 | iosAllowHTTPDownload: 1 58 | allowedAutorotateToPortrait: 1 59 | allowedAutorotateToPortraitUpsideDown: 1 60 | allowedAutorotateToLandscapeRight: 1 61 | allowedAutorotateToLandscapeLeft: 1 62 | useOSAutorotation: 1 63 | use32BitDisplayBuffer: 1 64 | preserveFramebufferAlpha: 0 65 | disableDepthAndStencilBuffers: 0 66 | androidBlitType: 0 67 | defaultIsNativeResolution: 1 68 | macRetinaSupport: 1 69 | runInBackground: 1 70 | captureSingleScreen: 0 71 | muteOtherAudioSources: 0 72 | Prepare IOS For Recording: 0 73 | Force IOS Speakers When Recording: 0 74 | deferSystemGesturesMode: 0 75 | hideHomeButton: 0 76 | submitAnalytics: 1 77 | usePlayerLog: 1 78 | bakeCollisionMeshes: 0 79 | forceSingleInstance: 0 80 | resizableWindow: 0 81 | useMacAppStoreValidation: 0 82 | macAppStoreCategory: public.app-category.games 83 | gpuSkinning: 1 84 | graphicsJobs: 0 85 | xboxPIXTextureCapture: 0 86 | xboxEnableAvatar: 0 87 | xboxEnableKinect: 0 88 | xboxEnableKinectAutoTracking: 0 89 | xboxEnableFitness: 0 90 | visibleInBackground: 1 91 | allowFullscreenSwitch: 1 92 | graphicsJobMode: 0 93 | fullscreenMode: 1 94 | xboxSpeechDB: 0 95 | xboxEnableHeadOrientation: 0 96 | xboxEnableGuest: 0 97 | xboxEnablePIXSampling: 0 98 | metalFramebufferOnly: 0 99 | n3dsDisableStereoscopicView: 0 100 | n3dsEnableSharedListOpt: 1 101 | n3dsEnableVSync: 0 102 | xboxOneResolution: 0 103 | xboxOneSResolution: 0 104 | xboxOneXResolution: 3 105 | xboxOneMonoLoggingLevel: 0 106 | xboxOneLoggingLevel: 1 107 | xboxOneDisableEsram: 0 108 | xboxOnePresentImmediateThreshold: 0 109 | switchQueueCommandMemory: 0 110 | videoMemoryForVertexBuffers: 0 111 | psp2PowerMode: 0 112 | psp2AcquireBGM: 1 113 | vulkanEnableSetSRGBWrite: 0 114 | vulkanUseSWCommandBuffers: 0 115 | m_SupportedAspectRatios: 116 | 4:3: 1 117 | 5:4: 1 118 | 16:10: 1 119 | 16:9: 1 120 | Others: 1 121 | bundleVersion: 0.1 122 | preloadedAssets: [] 123 | metroInputSource: 0 124 | wsaTransparentSwapchain: 0 125 | m_HolographicPauseOnTrackingLoss: 1 126 | xboxOneDisableKinectGpuReservation: 0 127 | xboxOneEnable7thCore: 0 128 | vrSettings: 129 | cardboard: 130 | depthFormat: 0 131 | enableTransitionView: 0 132 | daydream: 133 | depthFormat: 0 134 | useSustainedPerformanceMode: 0 135 | enableVideoLayer: 0 136 | useProtectedVideoMemory: 0 137 | minimumSupportedHeadTracking: 0 138 | maximumSupportedHeadTracking: 1 139 | hololens: 140 | depthFormat: 1 141 | depthBufferSharingEnabled: 0 142 | oculus: 143 | sharedDepthBuffer: 0 144 | dashSupport: 0 145 | enable360StereoCapture: 0 146 | protectGraphicsMemory: 0 147 | useHDRDisplay: 0 148 | m_ColorGamuts: 00000000 149 | targetPixelDensity: 30 150 | resolutionScalingMode: 0 151 | androidSupportedAspectRatio: 1 152 | androidMaxAspectRatio: 2.1 153 | applicationIdentifier: {} 154 | buildNumber: {} 155 | AndroidBundleVersionCode: 1 156 | AndroidMinSdkVersion: 16 157 | AndroidTargetSdkVersion: 0 158 | AndroidPreferredInstallLocation: 1 159 | aotOptions: 160 | stripEngineCode: 1 161 | iPhoneStrippingLevel: 0 162 | iPhoneScriptCallOptimization: 0 163 | ForceInternetPermission: 0 164 | ForceSDCardPermission: 0 165 | CreateWallpaper: 0 166 | APKExpansionFiles: 0 167 | keepLoadedShadersAlive: 0 168 | StripUnusedMeshComponents: 1 169 | VertexChannelCompressionMask: 4054 170 | iPhoneSdkVersion: 988 171 | iOSTargetOSVersionString: 8.0 172 | tvOSSdkVersion: 0 173 | tvOSRequireExtendedGameController: 0 174 | tvOSTargetOSVersionString: 9.0 175 | uIPrerenderedIcon: 0 176 | uIRequiresPersistentWiFi: 0 177 | uIRequiresFullScreen: 1 178 | uIStatusBarHidden: 1 179 | uIExitOnSuspend: 0 180 | uIStatusBarStyle: 0 181 | iPhoneSplashScreen: {fileID: 0} 182 | iPhoneHighResSplashScreen: {fileID: 0} 183 | iPhoneTallHighResSplashScreen: {fileID: 0} 184 | iPhone47inSplashScreen: {fileID: 0} 185 | iPhone55inPortraitSplashScreen: {fileID: 0} 186 | iPhone55inLandscapeSplashScreen: {fileID: 0} 187 | iPhone58inPortraitSplashScreen: {fileID: 0} 188 | iPhone58inLandscapeSplashScreen: {fileID: 0} 189 | iPadPortraitSplashScreen: {fileID: 0} 190 | iPadHighResPortraitSplashScreen: {fileID: 0} 191 | iPadLandscapeSplashScreen: {fileID: 0} 192 | iPadHighResLandscapeSplashScreen: {fileID: 0} 193 | appleTVSplashScreen: {fileID: 0} 194 | appleTVSplashScreen2x: {fileID: 0} 195 | tvOSSmallIconLayers: [] 196 | tvOSSmallIconLayers2x: [] 197 | tvOSLargeIconLayers: [] 198 | tvOSLargeIconLayers2x: [] 199 | tvOSTopShelfImageLayers: [] 200 | tvOSTopShelfImageLayers2x: [] 201 | tvOSTopShelfImageWideLayers: [] 202 | tvOSTopShelfImageWideLayers2x: [] 203 | iOSLaunchScreenType: 0 204 | iOSLaunchScreenPortrait: {fileID: 0} 205 | iOSLaunchScreenLandscape: {fileID: 0} 206 | iOSLaunchScreenBackgroundColor: 207 | serializedVersion: 2 208 | rgba: 0 209 | iOSLaunchScreenFillPct: 100 210 | iOSLaunchScreenSize: 100 211 | iOSLaunchScreenCustomXibPath: 212 | iOSLaunchScreeniPadType: 0 213 | iOSLaunchScreeniPadImage: {fileID: 0} 214 | iOSLaunchScreeniPadBackgroundColor: 215 | serializedVersion: 2 216 | rgba: 0 217 | iOSLaunchScreeniPadFillPct: 100 218 | iOSLaunchScreeniPadSize: 100 219 | iOSLaunchScreeniPadCustomXibPath: 220 | iOSUseLaunchScreenStoryboard: 0 221 | iOSLaunchScreenCustomStoryboardPath: 222 | iOSDeviceRequirements: [] 223 | iOSURLSchemes: [] 224 | iOSBackgroundModes: 0 225 | iOSMetalForceHardShadows: 0 226 | metalEditorSupport: 1 227 | metalAPIValidation: 1 228 | iOSRenderExtraFrameOnPause: 0 229 | appleDeveloperTeamID: 230 | iOSManualSigningProvisioningProfileID: 231 | tvOSManualSigningProvisioningProfileID: 232 | iOSManualSigningProvisioningProfileType: 0 233 | tvOSManualSigningProvisioningProfileType: 0 234 | appleEnableAutomaticSigning: 0 235 | iOSRequireARKit: 0 236 | appleEnableProMotion: 0 237 | vulkanEditorSupport: 0 238 | clonedFromGUID: c0afd0d1d80e3634a9dac47e8a0426ea 239 | templatePackageId: com.unity.3d@1.0.2 240 | templateDefaultScene: Assets/Scenes/SampleScene.unity 241 | AndroidTargetArchitectures: 5 242 | AndroidSplashScreenScale: 0 243 | androidSplashScreen: {fileID: 0} 244 | AndroidKeystoreName: 245 | AndroidKeyaliasName: 246 | AndroidBuildApkPerCpuArchitecture: 0 247 | AndroidTVCompatibility: 1 248 | AndroidIsGame: 1 249 | AndroidEnableTango: 0 250 | androidEnableBanner: 1 251 | androidUseLowAccuracyLocation: 0 252 | m_AndroidBanners: 253 | - width: 320 254 | height: 180 255 | banner: {fileID: 0} 256 | androidGamepadSupportLevel: 0 257 | resolutionDialogBanner: {fileID: 0} 258 | m_BuildTargetIcons: [] 259 | m_BuildTargetPlatformIcons: [] 260 | m_BuildTargetBatching: 261 | - m_BuildTarget: Standalone 262 | m_StaticBatching: 1 263 | m_DynamicBatching: 0 264 | - m_BuildTarget: tvOS 265 | m_StaticBatching: 1 266 | m_DynamicBatching: 0 267 | - m_BuildTarget: Android 268 | m_StaticBatching: 1 269 | m_DynamicBatching: 0 270 | - m_BuildTarget: iPhone 271 | m_StaticBatching: 1 272 | m_DynamicBatching: 0 273 | - m_BuildTarget: WebGL 274 | m_StaticBatching: 0 275 | m_DynamicBatching: 0 276 | m_BuildTargetGraphicsAPIs: 277 | - m_BuildTarget: AndroidPlayer 278 | m_APIs: 0b00000015000000 279 | m_Automatic: 1 280 | - m_BuildTarget: iOSSupport 281 | m_APIs: 10000000 282 | m_Automatic: 1 283 | - m_BuildTarget: AppleTVSupport 284 | m_APIs: 10000000 285 | m_Automatic: 0 286 | - m_BuildTarget: WebGLSupport 287 | m_APIs: 0b000000 288 | m_Automatic: 1 289 | m_BuildTargetVRSettings: 290 | - m_BuildTarget: Standalone 291 | m_Enabled: 0 292 | m_Devices: 293 | - Oculus 294 | - OpenVR 295 | m_BuildTargetEnableVuforiaSettings: [] 296 | openGLRequireES31: 0 297 | openGLRequireES31AEP: 0 298 | m_TemplateCustomTags: {} 299 | mobileMTRendering: 300 | Android: 1 301 | iPhone: 1 302 | tvOS: 1 303 | m_BuildTargetGroupLightmapEncodingQuality: [] 304 | m_BuildTargetGroupLightmapSettings: [] 305 | playModeTestRunnerEnabled: 0 306 | runPlayModeTestAsEditModeTest: 0 307 | actionOnDotNetUnhandledException: 1 308 | enableInternalProfiler: 0 309 | logObjCUncaughtExceptions: 1 310 | enableCrashReportAPI: 0 311 | cameraUsageDescription: 312 | locationUsageDescription: 313 | microphoneUsageDescription: 314 | switchNetLibKey: 315 | switchSocketMemoryPoolSize: 6144 316 | switchSocketAllocatorPoolSize: 128 317 | switchSocketConcurrencyLimit: 14 318 | switchScreenResolutionBehavior: 2 319 | switchUseCPUProfiler: 0 320 | switchApplicationID: 0x01004b9000490000 321 | switchNSODependencies: 322 | switchTitleNames_0: 323 | switchTitleNames_1: 324 | switchTitleNames_2: 325 | switchTitleNames_3: 326 | switchTitleNames_4: 327 | switchTitleNames_5: 328 | switchTitleNames_6: 329 | switchTitleNames_7: 330 | switchTitleNames_8: 331 | switchTitleNames_9: 332 | switchTitleNames_10: 333 | switchTitleNames_11: 334 | switchTitleNames_12: 335 | switchTitleNames_13: 336 | switchTitleNames_14: 337 | switchPublisherNames_0: 338 | switchPublisherNames_1: 339 | switchPublisherNames_2: 340 | switchPublisherNames_3: 341 | switchPublisherNames_4: 342 | switchPublisherNames_5: 343 | switchPublisherNames_6: 344 | switchPublisherNames_7: 345 | switchPublisherNames_8: 346 | switchPublisherNames_9: 347 | switchPublisherNames_10: 348 | switchPublisherNames_11: 349 | switchPublisherNames_12: 350 | switchPublisherNames_13: 351 | switchPublisherNames_14: 352 | switchIcons_0: {fileID: 0} 353 | switchIcons_1: {fileID: 0} 354 | switchIcons_2: {fileID: 0} 355 | switchIcons_3: {fileID: 0} 356 | switchIcons_4: {fileID: 0} 357 | switchIcons_5: {fileID: 0} 358 | switchIcons_6: {fileID: 0} 359 | switchIcons_7: {fileID: 0} 360 | switchIcons_8: {fileID: 0} 361 | switchIcons_9: {fileID: 0} 362 | switchIcons_10: {fileID: 0} 363 | switchIcons_11: {fileID: 0} 364 | switchIcons_12: {fileID: 0} 365 | switchIcons_13: {fileID: 0} 366 | switchIcons_14: {fileID: 0} 367 | switchSmallIcons_0: {fileID: 0} 368 | switchSmallIcons_1: {fileID: 0} 369 | switchSmallIcons_2: {fileID: 0} 370 | switchSmallIcons_3: {fileID: 0} 371 | switchSmallIcons_4: {fileID: 0} 372 | switchSmallIcons_5: {fileID: 0} 373 | switchSmallIcons_6: {fileID: 0} 374 | switchSmallIcons_7: {fileID: 0} 375 | switchSmallIcons_8: {fileID: 0} 376 | switchSmallIcons_9: {fileID: 0} 377 | switchSmallIcons_10: {fileID: 0} 378 | switchSmallIcons_11: {fileID: 0} 379 | switchSmallIcons_12: {fileID: 0} 380 | switchSmallIcons_13: {fileID: 0} 381 | switchSmallIcons_14: {fileID: 0} 382 | switchManualHTML: 383 | switchAccessibleURLs: 384 | switchLegalInformation: 385 | switchMainThreadStackSize: 1048576 386 | switchPresenceGroupId: 387 | switchLogoHandling: 0 388 | switchReleaseVersion: 0 389 | switchDisplayVersion: 1.0.0 390 | switchStartupUserAccount: 0 391 | switchTouchScreenUsage: 0 392 | switchSupportedLanguagesMask: 0 393 | switchLogoType: 0 394 | switchApplicationErrorCodeCategory: 395 | switchUserAccountSaveDataSize: 0 396 | switchUserAccountSaveDataJournalSize: 0 397 | switchApplicationAttribute: 0 398 | switchCardSpecSize: -1 399 | switchCardSpecClock: -1 400 | switchRatingsMask: 0 401 | switchRatingsInt_0: 0 402 | switchRatingsInt_1: 0 403 | switchRatingsInt_2: 0 404 | switchRatingsInt_3: 0 405 | switchRatingsInt_4: 0 406 | switchRatingsInt_5: 0 407 | switchRatingsInt_6: 0 408 | switchRatingsInt_7: 0 409 | switchRatingsInt_8: 0 410 | switchRatingsInt_9: 0 411 | switchRatingsInt_10: 0 412 | switchRatingsInt_11: 0 413 | switchLocalCommunicationIds_0: 414 | switchLocalCommunicationIds_1: 415 | switchLocalCommunicationIds_2: 416 | switchLocalCommunicationIds_3: 417 | switchLocalCommunicationIds_4: 418 | switchLocalCommunicationIds_5: 419 | switchLocalCommunicationIds_6: 420 | switchLocalCommunicationIds_7: 421 | switchParentalControl: 0 422 | switchAllowsScreenshot: 1 423 | switchAllowsVideoCapturing: 1 424 | switchAllowsRuntimeAddOnContentInstall: 0 425 | switchDataLossConfirmation: 0 426 | switchSupportedNpadStyles: 3 427 | switchNativeFsCacheSize: 32 428 | switchIsHoldTypeHorizontal: 0 429 | switchSupportedNpadCount: 8 430 | switchSocketConfigEnabled: 0 431 | switchTcpInitialSendBufferSize: 32 432 | switchTcpInitialReceiveBufferSize: 64 433 | switchTcpAutoSendBufferSizeMax: 256 434 | switchTcpAutoReceiveBufferSizeMax: 256 435 | switchUdpSendBufferSize: 9 436 | switchUdpReceiveBufferSize: 42 437 | switchSocketBufferEfficiency: 4 438 | switchSocketInitializeEnabled: 1 439 | switchNetworkInterfaceManagerInitializeEnabled: 1 440 | switchPlayerConnectionEnabled: 1 441 | ps4NPAgeRating: 12 442 | ps4NPTitleSecret: 443 | ps4NPTrophyPackPath: 444 | ps4ParentalLevel: 11 445 | ps4ContentID: ED1633-NPXX51362_00-0000000000000000 446 | ps4Category: 0 447 | ps4MasterVersion: 01.00 448 | ps4AppVersion: 01.00 449 | ps4AppType: 0 450 | ps4ParamSfxPath: 451 | ps4VideoOutPixelFormat: 0 452 | ps4VideoOutInitialWidth: 1920 453 | ps4VideoOutBaseModeInitialWidth: 1920 454 | ps4VideoOutReprojectionRate: 60 455 | ps4PronunciationXMLPath: 456 | ps4PronunciationSIGPath: 457 | ps4BackgroundImagePath: 458 | ps4StartupImagePath: 459 | ps4StartupImagesFolder: 460 | ps4IconImagesFolder: 461 | ps4SaveDataImagePath: 462 | ps4SdkOverride: 463 | ps4BGMPath: 464 | ps4ShareFilePath: 465 | ps4ShareOverlayImagePath: 466 | ps4PrivacyGuardImagePath: 467 | ps4NPtitleDatPath: 468 | ps4RemotePlayKeyAssignment: -1 469 | ps4RemotePlayKeyMappingDir: 470 | ps4PlayTogetherPlayerCount: 0 471 | ps4EnterButtonAssignment: 1 472 | ps4ApplicationParam1: 0 473 | ps4ApplicationParam2: 0 474 | ps4ApplicationParam3: 0 475 | ps4ApplicationParam4: 0 476 | ps4DownloadDataSize: 0 477 | ps4GarlicHeapSize: 2048 478 | ps4ProGarlicHeapSize: 2560 479 | ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ 480 | ps4pnSessions: 1 481 | ps4pnPresence: 1 482 | ps4pnFriends: 1 483 | ps4pnGameCustomData: 1 484 | playerPrefsSupport: 0 485 | enableApplicationExit: 0 486 | restrictedAudioUsageRights: 0 487 | ps4UseResolutionFallback: 0 488 | ps4ReprojectionSupport: 0 489 | ps4UseAudio3dBackend: 0 490 | ps4SocialScreenEnabled: 0 491 | ps4ScriptOptimizationLevel: 0 492 | ps4Audio3dVirtualSpeakerCount: 14 493 | ps4attribCpuUsage: 0 494 | ps4PatchPkgPath: 495 | ps4PatchLatestPkgPath: 496 | ps4PatchChangeinfoPath: 497 | ps4PatchDayOne: 0 498 | ps4attribUserManagement: 0 499 | ps4attribMoveSupport: 0 500 | ps4attrib3DSupport: 0 501 | ps4attribShareSupport: 0 502 | ps4attribExclusiveVR: 0 503 | ps4disableAutoHideSplash: 0 504 | ps4videoRecordingFeaturesUsed: 0 505 | ps4contentSearchFeaturesUsed: 0 506 | ps4attribEyeToEyeDistanceSettingVR: 0 507 | ps4IncludedModules: [] 508 | monoEnv: 509 | psp2Splashimage: {fileID: 0} 510 | psp2NPTrophyPackPath: 511 | psp2NPSupportGBMorGJP: 0 512 | psp2NPAgeRating: 12 513 | psp2NPTitleDatPath: 514 | psp2NPCommsID: 515 | psp2NPCommunicationsID: 516 | psp2NPCommsPassphrase: 517 | psp2NPCommsSig: 518 | psp2ParamSfxPath: 519 | psp2ManualPath: 520 | psp2LiveAreaGatePath: 521 | psp2LiveAreaBackroundPath: 522 | psp2LiveAreaPath: 523 | psp2LiveAreaTrialPath: 524 | psp2PatchChangeInfoPath: 525 | psp2PatchOriginalPackage: 526 | psp2PackagePassword: F69AzBlax3CF3EDNhm3soLBPh71Yexui 527 | psp2KeystoneFile: 528 | psp2MemoryExpansionMode: 0 529 | psp2DRMType: 0 530 | psp2StorageType: 0 531 | psp2MediaCapacity: 0 532 | psp2DLCConfigPath: 533 | psp2ThumbnailPath: 534 | psp2BackgroundPath: 535 | psp2SoundPath: 536 | psp2TrophyCommId: 537 | psp2TrophyPackagePath: 538 | psp2PackagedResourcesPath: 539 | psp2SaveDataQuota: 10240 540 | psp2ParentalLevel: 1 541 | psp2ShortTitle: Not Set 542 | psp2ContentID: IV0000-ABCD12345_00-0123456789ABCDEF 543 | psp2Category: 0 544 | psp2MasterVersion: 01.00 545 | psp2AppVersion: 01.00 546 | psp2TVBootMode: 0 547 | psp2EnterButtonAssignment: 2 548 | psp2TVDisableEmu: 0 549 | psp2AllowTwitterDialog: 1 550 | psp2Upgradable: 0 551 | psp2HealthWarning: 0 552 | psp2UseLibLocation: 0 553 | psp2InfoBarOnStartup: 0 554 | psp2InfoBarColor: 0 555 | psp2ScriptOptimizationLevel: 0 556 | splashScreenBackgroundSourceLandscape: {fileID: 0} 557 | splashScreenBackgroundSourcePortrait: {fileID: 0} 558 | spritePackerPolicy: 559 | webGLMemorySize: 256 560 | webGLExceptionSupport: 1 561 | webGLNameFilesAsHashes: 0 562 | webGLDataCaching: 1 563 | webGLDebugSymbols: 0 564 | webGLEmscriptenArgs: 565 | webGLModulesDirectory: 566 | webGLTemplate: APPLICATION:Default 567 | webGLAnalyzeBuildSize: 0 568 | webGLUseEmbeddedResources: 0 569 | webGLCompressionFormat: 1 570 | webGLLinkerTarget: 1 571 | scriptingDefineSymbols: {} 572 | platformArchitecture: {} 573 | scriptingBackend: {} 574 | il2cppCompilerConfiguration: {} 575 | incrementalIl2cppBuild: {} 576 | allowUnsafeCode: 0 577 | additionalIl2CppArgs: 578 | scriptingRuntimeVersion: 0 579 | apiCompatibilityLevelPerPlatform: {} 580 | m_RenderingPath: 1 581 | m_MobileRenderingPath: 1 582 | metroPackageName: Template_3D 583 | metroPackageVersion: 584 | metroCertificatePath: 585 | metroCertificatePassword: 586 | metroCertificateSubject: 587 | metroCertificateIssuer: 588 | metroCertificateNotAfter: 0000000000000000 589 | metroApplicationDescription: Template_3D 590 | wsaImages: {} 591 | metroTileShortName: 592 | metroTileShowName: 0 593 | metroMediumTileShowName: 0 594 | metroLargeTileShowName: 0 595 | metroWideTileShowName: 0 596 | metroDefaultTileSize: 1 597 | metroTileForegroundText: 2 598 | metroTileBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21568628, a: 0} 599 | metroSplashScreenBackgroundColor: {r: 0.12941177, g: 0.17254902, b: 0.21568628, 600 | a: 1} 601 | metroSplashScreenUseBackgroundColor: 0 602 | platformCapabilities: {} 603 | metroFTAName: 604 | metroFTAFileTypes: [] 605 | metroProtocolName: 606 | metroCompilationOverrides: 1 607 | n3dsUseExtSaveData: 0 608 | n3dsCompressStaticMem: 1 609 | n3dsExtSaveDataNumber: 0x12345 610 | n3dsStackSize: 131072 611 | n3dsTargetPlatform: 2 612 | n3dsRegion: 7 613 | n3dsMediaSize: 0 614 | n3dsLogoStyle: 3 615 | n3dsTitle: GameName 616 | n3dsProductCode: 617 | n3dsApplicationId: 0xFF3FF 618 | XboxOneProductId: 619 | XboxOneUpdateKey: 620 | XboxOneSandboxId: 621 | XboxOneContentId: 622 | XboxOneTitleId: 623 | XboxOneSCId: 624 | XboxOneGameOsOverridePath: 625 | XboxOnePackagingOverridePath: 626 | XboxOneAppManifestOverridePath: 627 | XboxOneVersion: 1.0.0.0 628 | XboxOnePackageEncryption: 0 629 | XboxOnePackageUpdateGranularity: 2 630 | XboxOneDescription: 631 | XboxOneLanguage: 632 | - enus 633 | XboxOneCapability: [] 634 | XboxOneGameRating: {} 635 | XboxOneIsContentPackage: 0 636 | XboxOneEnableGPUVariability: 0 637 | XboxOneSockets: {} 638 | XboxOneSplashScreen: {fileID: 0} 639 | XboxOneAllowedProductIds: [] 640 | XboxOnePersistentLocalStorageSize: 0 641 | XboxOneXTitleMemory: 8 642 | xboxOneScriptCompiler: 0 643 | vrEditorSettings: 644 | daydream: 645 | daydreamIconForeground: {fileID: 0} 646 | daydreamIconBackground: {fileID: 0} 647 | cloudServicesEnabled: 648 | UNet: 1 649 | facebookSdkVersion: 7.9.4 650 | apiCompatibilityLevel: 2 651 | cloudProjectId: 0bb0562a-88f4-4d4f-bdda-e1b78dad42e9 652 | projectName: CollisionDetection 653 | organizationId: 1149216056 654 | cloudEnabled: 0 655 | enableNativePlatformBackendsForNewInputSystem: 0 656 | disableOldInputManagerSupport: 0 657 | -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2018.2.13f1 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!47 &1 4 | QualitySettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 5 7 | m_CurrentQuality: 4 8 | m_QualitySettings: 9 | - serializedVersion: 2 10 | name: Very Low 11 | pixelLightCount: 0 12 | shadows: 0 13 | shadowResolution: 0 14 | shadowProjection: 1 15 | shadowCascades: 1 16 | shadowDistance: 15 17 | shadowNearPlaneOffset: 3 18 | shadowCascade2Split: 0.33333334 19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 20 | shadowmaskMode: 0 21 | blendWeights: 1 22 | textureQuality: 1 23 | anisotropicTextures: 0 24 | antiAliasing: 0 25 | softParticles: 0 26 | softVegetation: 0 27 | realtimeReflectionProbes: 0 28 | billboardsFaceCameraPosition: 0 29 | vSyncCount: 0 30 | lodBias: 0.3 31 | maximumLODLevel: 0 32 | particleRaycastBudget: 4 33 | asyncUploadTimeSlice: 2 34 | asyncUploadBufferSize: 4 35 | resolutionScalingFixedDPIFactor: 1 36 | excludedTargetPlatforms: [] 37 | - serializedVersion: 2 38 | name: Low 39 | pixelLightCount: 0 40 | shadows: 0 41 | shadowResolution: 0 42 | shadowProjection: 1 43 | shadowCascades: 1 44 | shadowDistance: 20 45 | shadowNearPlaneOffset: 3 46 | shadowCascade2Split: 0.33333334 47 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 48 | shadowmaskMode: 0 49 | blendWeights: 2 50 | textureQuality: 0 51 | anisotropicTextures: 0 52 | antiAliasing: 0 53 | softParticles: 0 54 | softVegetation: 0 55 | realtimeReflectionProbes: 0 56 | billboardsFaceCameraPosition: 0 57 | vSyncCount: 0 58 | lodBias: 0.4 59 | maximumLODLevel: 0 60 | particleRaycastBudget: 16 61 | asyncUploadTimeSlice: 2 62 | asyncUploadBufferSize: 4 63 | resolutionScalingFixedDPIFactor: 1 64 | excludedTargetPlatforms: [] 65 | - serializedVersion: 2 66 | name: Medium 67 | pixelLightCount: 1 68 | shadows: 1 69 | shadowResolution: 0 70 | shadowProjection: 1 71 | shadowCascades: 1 72 | shadowDistance: 20 73 | shadowNearPlaneOffset: 3 74 | shadowCascade2Split: 0.33333334 75 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 76 | shadowmaskMode: 0 77 | blendWeights: 2 78 | textureQuality: 0 79 | anisotropicTextures: 1 80 | antiAliasing: 0 81 | softParticles: 0 82 | softVegetation: 0 83 | realtimeReflectionProbes: 0 84 | billboardsFaceCameraPosition: 0 85 | vSyncCount: 1 86 | lodBias: 0.7 87 | maximumLODLevel: 0 88 | particleRaycastBudget: 64 89 | asyncUploadTimeSlice: 2 90 | asyncUploadBufferSize: 4 91 | resolutionScalingFixedDPIFactor: 1 92 | excludedTargetPlatforms: [] 93 | - serializedVersion: 2 94 | name: High 95 | pixelLightCount: 2 96 | shadows: 2 97 | shadowResolution: 1 98 | shadowProjection: 1 99 | shadowCascades: 2 100 | shadowDistance: 40 101 | shadowNearPlaneOffset: 3 102 | shadowCascade2Split: 0.33333334 103 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 104 | shadowmaskMode: 1 105 | blendWeights: 2 106 | textureQuality: 0 107 | anisotropicTextures: 1 108 | antiAliasing: 2 109 | softParticles: 0 110 | softVegetation: 1 111 | realtimeReflectionProbes: 1 112 | billboardsFaceCameraPosition: 1 113 | vSyncCount: 1 114 | lodBias: 1 115 | maximumLODLevel: 0 116 | particleRaycastBudget: 256 117 | asyncUploadTimeSlice: 2 118 | asyncUploadBufferSize: 4 119 | resolutionScalingFixedDPIFactor: 1 120 | excludedTargetPlatforms: [] 121 | - serializedVersion: 2 122 | name: Very High 123 | pixelLightCount: 3 124 | shadows: 2 125 | shadowResolution: 2 126 | shadowProjection: 1 127 | shadowCascades: 2 128 | shadowDistance: 40 129 | shadowNearPlaneOffset: 3 130 | shadowCascade2Split: 0.33333334 131 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 132 | shadowmaskMode: 1 133 | blendWeights: 4 134 | textureQuality: 0 135 | anisotropicTextures: 1 136 | antiAliasing: 4 137 | softParticles: 1 138 | softVegetation: 1 139 | realtimeReflectionProbes: 1 140 | billboardsFaceCameraPosition: 1 141 | vSyncCount: 1 142 | lodBias: 1.5 143 | maximumLODLevel: 0 144 | particleRaycastBudget: 1024 145 | asyncUploadTimeSlice: 2 146 | asyncUploadBufferSize: 4 147 | resolutionScalingFixedDPIFactor: 1 148 | excludedTargetPlatforms: [] 149 | - serializedVersion: 2 150 | name: Ultra 151 | pixelLightCount: 4 152 | shadows: 2 153 | shadowResolution: 2 154 | shadowProjection: 1 155 | shadowCascades: 4 156 | shadowDistance: 150 157 | shadowNearPlaneOffset: 3 158 | shadowCascade2Split: 0.33333334 159 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} 160 | shadowmaskMode: 1 161 | blendWeights: 4 162 | textureQuality: 0 163 | anisotropicTextures: 1 164 | antiAliasing: 4 165 | softParticles: 1 166 | softVegetation: 1 167 | realtimeReflectionProbes: 1 168 | billboardsFaceCameraPosition: 1 169 | vSyncCount: 1 170 | lodBias: 2 171 | maximumLODLevel: 0 172 | particleRaycastBudget: 4096 173 | asyncUploadTimeSlice: 2 174 | asyncUploadBufferSize: 4 175 | resolutionScalingFixedDPIFactor: 1 176 | excludedTargetPlatforms: [] 177 | m_PerPlatformDefaultQuality: 178 | Android: 2 179 | Nintendo 3DS: 5 180 | Nintendo Switch: 5 181 | PS4: 5 182 | PSP2: 2 183 | Standalone: 5 184 | Tizen: 2 185 | WebGL: 3 186 | WiiU: 5 187 | Windows Store Apps: 5 188 | XboxOne: 5 189 | iPhone: 2 190 | tvOS: 2 191 | -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 14 | - 15 | - 16 | - PostProcessing 17 | - 18 | - 19 | - 20 | - 21 | - 22 | - 23 | - 24 | - 25 | - 26 | - 27 | - 28 | - 29 | - 30 | - 31 | - 32 | - 33 | - 34 | - 35 | - 36 | - 37 | - 38 | - 39 | - 40 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: 0.02 7 | Maximum Allowed Timestep: 0.1 8 | m_TimeScale: 1 9 | Maximum Particle Timestep: 0.03 10 | -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!310 &1 4 | UnityConnectSettings: 5 | m_ObjectHideFlags: 0 6 | m_Enabled: 0 7 | m_TestMode: 0 8 | m_TestEventUrl: 9 | m_TestConfigUrl: 10 | m_TestInitMode: 0 11 | CrashReportingSettings: 12 | m_EventUrl: https://perf-events.cloud.unity3d.com/api/events/crashes 13 | m_NativeEventUrl: https://perf-events.cloud.unity3d.com/symbolicate 14 | m_Enabled: 0 15 | m_CaptureEditorExceptions: 1 16 | UnityPurchasingSettings: 17 | m_Enabled: 0 18 | m_TestMode: 0 19 | UnityAnalyticsSettings: 20 | m_Enabled: 0 21 | m_InitializeOnStartup: 1 22 | m_TestMode: 0 23 | m_TestEventUrl: 24 | m_TestConfigUrl: 25 | UnityAdsSettings: 26 | m_Enabled: 0 27 | m_InitializeOnStartup: 1 28 | m_TestMode: 0 29 | m_IosGameId: 30 | m_AndroidGameId: 31 | m_GameIds: {} 32 | m_GameId: 33 | PerformanceReportingSettings: 34 | m_Enabled: 0 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityCollisionDetection 2 | Unity中实现碰撞检测 3 | 4 | AABB.cs Sphere.cs OBB.cs BVH.cs 是包围碰撞体的内部实现 5 | AABBCollider.cs SphereCollider.cs OBBCollider.cs MeshCollider.cs 为对应组件脚本 6 | 7 | BVH.cs Grid.cs 是场景管理加速结构的内部实现 8 | BVHAccelerator.cs GridAccelerator.cs 为对应组件脚本 9 | 10 | ![Grid](https://github.com/JBLRADISH/UnityCollisionDetection/blob/master/Assets/Grid.png) 11 | ![BVH](https://github.com/JBLRADISH/UnityCollisionDetection/blob/master/Assets/BVH.png) 12 | ![MeshCollider](https://github.com/JBLRADISH/UnityCollisionDetection/blob/master/Assets/MeshCollider.png) 13 | --------------------------------------------------------------------------------