Skip to content

Commit 38f7f57

Browse files
committed
readme and maxdistance for raycast
1 parent 281c696 commit 38f7f57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+32850
-414
lines changed

.idea/.idea.NativeTrees/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.NativeTrees/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Example/Bench.unity

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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.12731713, g: 0.13414736, b: 0.121078536, a: 1}
42+
m_UseRadianceAmbientProbe: 0
43+
--- !u!157 &3
44+
LightmapSettings:
45+
m_ObjectHideFlags: 0
46+
serializedVersion: 12
47+
m_GIWorkflowMode: 1
48+
m_GISettings:
49+
serializedVersion: 2
50+
m_BounceScale: 1
51+
m_IndirectOutputScale: 1
52+
m_AlbedoBoost: 1
53+
m_EnvironmentLightingMode: 0
54+
m_EnableBakedLightmaps: 1
55+
m_EnableRealtimeLightmaps: 0
56+
m_LightmapEditorSettings:
57+
serializedVersion: 12
58+
m_Resolution: 2
59+
m_BakeResolution: 40
60+
m_AtlasSize: 1024
61+
m_AO: 0
62+
m_AOMaxDistance: 1
63+
m_CompAOExponent: 1
64+
m_CompAOExponentDirect: 0
65+
m_ExtractAmbientOcclusion: 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: 512
79+
m_PVRBounces: 2
80+
m_PVREnvironmentSampleCount: 256
81+
m_PVREnvironmentReferencePointCount: 2048
82+
m_PVRFilteringMode: 1
83+
m_PVRDenoiserTypeDirect: 1
84+
m_PVRDenoiserTypeIndirect: 1
85+
m_PVRDenoiserTypeAO: 1
86+
m_PVRFilterTypeDirect: 0
87+
m_PVRFilterTypeIndirect: 0
88+
m_PVRFilterTypeAO: 0
89+
m_PVREnvironmentMIS: 1
90+
m_PVRCulling: 1
91+
m_PVRFilteringGaussRadiusDirect: 1
92+
m_PVRFilteringGaussRadiusIndirect: 5
93+
m_PVRFilteringGaussRadiusAO: 2
94+
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
95+
m_PVRFilteringAtrousPositionSigmaIndirect: 2
96+
m_PVRFilteringAtrousPositionSigmaAO: 1
97+
m_ExportTrainingData: 0
98+
m_TrainingDataDestination: TrainingData
99+
m_LightProbeSampleCountMultiplier: 4
100+
m_LightingDataAsset: {fileID: 0}
101+
m_LightingSettings: {fileID: 0}
102+
--- !u!196 &4
103+
NavMeshSettings:
104+
serializedVersion: 2
105+
m_ObjectHideFlags: 0
106+
m_BuildSettings:
107+
serializedVersion: 2
108+
agentTypeID: 0
109+
agentRadius: 0.5
110+
agentHeight: 2
111+
agentSlope: 45
112+
agentClimb: 0.4
113+
ledgeDropHeight: 0
114+
maxJumpAcrossDistance: 0
115+
minRegionArea: 2
116+
manualCellSize: 0
117+
cellSize: 0.16666667
118+
manualTileSize: 0
119+
tileSize: 256
120+
accuratePlacement: 0
121+
maxJobWorkers: 0
122+
preserveTilesOutsideBounds: 0
123+
debug:
124+
m_Flags: 0
125+
m_NavMeshData: {fileID: 0}
126+
--- !u!1 &416614298
127+
GameObject:
128+
m_ObjectHideFlags: 0
129+
m_CorrespondingSourceObject: {fileID: 0}
130+
m_PrefabInstance: {fileID: 0}
131+
m_PrefabAsset: {fileID: 0}
132+
serializedVersion: 6
133+
m_Component:
134+
- component: {fileID: 416614300}
135+
- component: {fileID: 416614299}
136+
m_Layer: 0
137+
m_Name: GameObject
138+
m_TagString: Untagged
139+
m_Icon: {fileID: 0}
140+
m_NavMeshLayer: 0
141+
m_StaticEditorFlags: 0
142+
m_IsActive: 1
143+
--- !u!114 &416614299
144+
MonoBehaviour:
145+
m_ObjectHideFlags: 0
146+
m_CorrespondingSourceObject: {fileID: 0}
147+
m_PrefabInstance: {fileID: 0}
148+
m_PrefabAsset: {fileID: 0}
149+
m_GameObject: {fileID: 416614298}
150+
m_Enabled: 1
151+
m_EditorHideFlags: 0
152+
m_Script: {fileID: 11500000, guid: 27c258eb29774eb7bbccca35c6e14722, type: 3}
153+
m_Name:
154+
m_EditorClassIdentifier:
155+
--- !u!4 &416614300
156+
Transform:
157+
m_ObjectHideFlags: 0
158+
m_CorrespondingSourceObject: {fileID: 0}
159+
m_PrefabInstance: {fileID: 0}
160+
m_PrefabAsset: {fileID: 0}
161+
m_GameObject: {fileID: 416614298}
162+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
163+
m_LocalPosition: {x: -32.01768, y: -7.225388, z: 187.28856}
164+
m_LocalScale: {x: 1, y: 1, z: 1}
165+
m_ConstrainProportionsScale: 0
166+
m_Children: []
167+
m_Father: {fileID: 0}
168+
m_RootOrder: 0
169+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

Assets/Scenes.meta renamed to Assets/Example/Bench.unity.meta

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Example/NativeOctreeExample.cs

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public void Execute()
2424
{
2525
for (int i = 0; i < actualTriangles.Length; i++)
2626
octree.Insert(actualTriangles[i], actualBounds[i]);
27-
28-
//for (int i = 0; i < actualTriangles.Length; i++)
29-
// octree.InsertPoint(actualTriangles[i], actualBounds[i].min);
3027
}
3128
}
3229

@@ -47,58 +44,38 @@ private void Start()
4744
list = new NativeList<Triangle>(Allocator.Persistent);
4845
query = new NativeOctree<Triangle>.NearestNeighbourCache(Allocator.Persistent);
4946

50-
var triangles = mesh.triangles;
51-
var vertices = mesh.vertices;
47+
var meshTriangles = mesh.triangles;
48+
var meshVertices = mesh.vertices;
5249

5350
var sw = Stopwatch.StartNew();
54-
var tris = new NativeArray<Triangle>(triangles.Length / 3, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
55-
var actualBounds = new NativeArray<AABB>(tris.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
51+
var triangles = new NativeArray<Triangle>(meshTriangles.Length / 3, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
52+
var bounds = new NativeArray<AABB>(triangles.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
5653

5754
int n = 0;
58-
for (int i = 0; i < triangles.Length; i += 3)
55+
for (int i = 0; i < meshTriangles.Length; i += 3)
5956
{
6057
Triangle tri = new Triangle(
61-
vertices[triangles[i]],
62-
vertices[triangles[i + 1]],
63-
vertices[triangles[i + 2]], n);
58+
meshVertices[meshTriangles[i]],
59+
meshVertices[meshTriangles[i + 1]],
60+
meshVertices[meshTriangles[i + 2]], n);
6461

65-
actualBounds[n] = tri.GetAABB();
66-
tris[n++] = tri;
62+
bounds[n] = tri.GetAABB();
63+
triangles[n++] = tri;
6764
}
6865
Debug.Log($"Triangles converted in {sw.Elapsed.TotalMilliseconds}ms");
6966
sw.Restart();
70-
71-
72-
// Insert a bunch of triangles
73-
for (int i = 0; i < tris.Length; i++)
74-
{
75-
var triangle = tris[i];
76-
octree.Insert(triangle, triangle.GetAABB());
77-
}
78-
79-
// Insert entities that are 'points'
80-
for (int i = 0; i < entities.Length; i++)
81-
{
82-
var entity = entities[i];
83-
octree.InsertPoint(entities[i], positions[i]);
84-
}
85-
86-
//
87-
88-
/*
8967
var job = new PopulateJob()
9068
{
9169
octree = octree,
92-
actualBounds = actualBounds,
93-
actualTriangles = actualTriangles
70+
actualBounds = bounds,
71+
actualTriangles = triangles
9472
};
9573
job.Run();
96-
*/
97-
74+
9875
Debug.Log($"Octree constructed in {sw.Elapsed.TotalMilliseconds}ms");
9976

100-
tris.Dispose();
101-
actualBounds.Dispose();
77+
triangles.Dispose();
78+
bounds.Dispose();
10279
}
10380

10481
private void OnDestroy()
@@ -132,6 +109,7 @@ private void Update()
132109
}
133110

134111
// Pick a random point for our NN query
112+
/*
135113
float3 point = new float3(
136114
Random.Range(octree.Bounds.min.x, octree.Bounds.max.x),
137115
Random.Range(octree.Bounds.min.y, octree.Bounds.max.y),
@@ -159,8 +137,10 @@ private void Update()
159137
newJob.Run();
160138
Debug.Log($"(Burst) nearest performed in {sw.Elapsed.TotalMilliseconds}ms");
161139
tempResult.Dispose();
140+
*/
162141
}
163142

143+
/*
164144
[BurstCompile]
165145
struct NewNearestJob : IJob
166146
{
@@ -175,4 +155,14 @@ public void Execute()
175155
nearest.Value = nearestTri;
176156
}
177157
}
158+
*/
159+
160+
private void OnDrawGizmos()
161+
{
162+
if (Application.isPlaying)
163+
{
164+
Gizmos.color = Color.black;
165+
octree.DrawGizmos();
166+
}
167+
}
178168
}

0 commit comments

Comments
 (0)