Skip to content

Commit

Permalink
fixed RGLMesh and RGLTexture member variables visibility and names, f…
Browse files Browse the repository at this point in the history
…ixed some typos
  • Loading branch information
Jakub-Krakowiak committed Aug 24, 2023
1 parent 972606e commit 21bc4ce
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLMeshObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ public override bool Equals(object obj)
private void UploadToRGL()
{
// Mesh should be uploaded.
Assert.IsFalse(rglMesh.rglMeshPtr == IntPtr.Zero);
Assert.IsFalse(rglMesh.RGLMeshPtr == IntPtr.Zero);

unsafe
{
try
{
RGLNativeAPI.CheckErr(
RGLNativeAPI.rgl_entity_create(out rglEntityPtr, IntPtr.Zero, rglMesh.rglMeshPtr));
RGLNativeAPI.rgl_entity_create(out rglEntityPtr, IntPtr.Zero, rglMesh.RGLMeshPtr));
}
catch (RGLException)
{
Expand Down Expand Up @@ -185,16 +185,16 @@ private void SetIntensityTexture()
try
{
RGLNativeAPI.CheckErr(
RGLNativeAPI.rgl_entity_set_intensity_texture(rglEntityPtr, rglTexture.rglTexturePtr));
RGLNativeAPI.rgl_entity_set_intensity_texture(rglEntityPtr, rglTexture.RGLTexturePtr));
}
catch (RGLException)
{
Debug.LogError($"Cannot assign texture: {rglTexture.Identifier}, to entity: {identifier}");
Debug.LogError($"Cannot assign texture: {rglTexture.Texture.name}, to entity: {RepresentedGO.name}");
throw;
}

// Mesh should be uploaded before assigning UVs.
Assert.IsFalse(rglMesh.rglMeshPtr == IntPtr.Zero);
Assert.IsFalse(rglMesh.RGLMeshPtr == IntPtr.Zero);

rglMesh.UploadUVs();
}
Expand All @@ -212,8 +212,8 @@ public RGLMeshRendererObject(MeshRenderer meshRenderer, Func<Matrix4x4> override
meshRenderer
)
{
var rendererTransfrom = meshRenderer.transform;
getLocalToWorld = overrideGetLocalToWorld != null ? overrideGetLocalToWorld : () => rendererTransfrom.localToWorldMatrix;
var rendererTransform = meshRenderer.transform;
getLocalToWorld = overrideGetLocalToWorld != null ? overrideGetLocalToWorld : () => rendererTransform.localToWorldMatrix;
}

protected override RGLMesh GetRGLMeshFrom(MeshRenderer meshRenderer)
Expand Down Expand Up @@ -311,12 +311,12 @@ public RGLTerrainObject(Terrain terrain) :
terrainSubObjects = new List<IRGLObject>();
var treePrototypes = terrain.terrainData.treePrototypes;

List<Renderer>[] treePrototypesRenderes = new List<Renderer>[treePrototypes.Length];
bool[] treePrototypesHasLODGroup = new bool[treePrototypes.Length];
var treePrototypesRenderers = new List<Renderer>[treePrototypes.Length];
var treePrototypeHasLODGroup = new bool[treePrototypes.Length];

for (var i = 0; i < treePrototypes.Length; i++)
{
treePrototypesRenderes[i] = new List<Renderer>();
treePrototypesRenderers[i] = new List<Renderer>();
var treePrefab = treePrototypes[i].prefab;
if (treePrefab.TryGetComponent<LODGroup>(out var lodGroup))
{
Expand All @@ -330,23 +330,23 @@ public RGLTerrainObject(Terrain terrain) :
{
if (renderer.gameObject.TryGetComponent<MeshFilter>(out _))
{
treePrototypesRenderes[i].Add(renderer);
treePrototypesRenderers[i].Add(renderer);
}
}
treePrototypesHasLODGroup[i] = true;
treePrototypeHasLODGroup[i] = true;
} else if (treePrefab.TryGetComponent<MeshRenderer>(out var mr) && treePrefab.TryGetComponent<MeshFilter>(out _))
{
treePrototypesRenderes[i].Add(mr);
treePrototypesHasLODGroup[i] = false;
treePrototypesRenderers[i].Add(mr);
treePrototypeHasLODGroup[i] = false;
}
}

for (var treeIndex = 0; treeIndex < terrain.terrainData.treeInstanceCount; treeIndex++)
{
int prototypeIndex = terrain.terrainData.GetTreeInstance(treeIndex).prototypeIndex;
foreach (var renderer in treePrototypesRenderes[prototypeIndex])
var prototypeIndex = terrain.terrainData.GetTreeInstance(treeIndex).prototypeIndex;
foreach (var renderer in treePrototypesRenderers[prototypeIndex])
{
var treePose = TerrainUtilities.GetTreePose(terrain, treeIndex, treePrototypesHasLODGroup[prototypeIndex]);
var treePose = TerrainUtilities.GetTreePose(terrain, treeIndex, treePrototypeHasLODGroup[prototypeIndex]);
if (renderer is MeshRenderer mr)
{
terrainSubObjects.Add(new RGLMeshRendererObject(mr,() =>
Expand Down Expand Up @@ -400,9 +400,9 @@ protected override void DestroyRGLMesh()
public class RGLMesh
{
public int Identifier;
public Mesh Mesh;
protected Mesh Mesh;

public IntPtr rglMeshPtr = IntPtr.Zero;
public IntPtr RGLMeshPtr = IntPtr.Zero;

public RGLMesh(int identifier, Mesh mesh)
{
Expand All @@ -419,10 +419,10 @@ public RGLMesh(int identifier, Mesh mesh)

public void DestroyInRGL()
{
if (rglMeshPtr != IntPtr.Zero)
if (RGLMeshPtr != IntPtr.Zero)
{
RGLNativeAPI.CheckErr(RGLNativeAPI.rgl_mesh_destroy(rglMeshPtr));
rglMeshPtr = IntPtr.Zero;
RGLNativeAPI.CheckErr(RGLNativeAPI.rgl_mesh_destroy(RGLMeshPtr));
RGLMeshPtr = IntPtr.Zero;
}
}

Expand Down Expand Up @@ -451,13 +451,13 @@ protected void UploadToRGL()
try
{
RGLNativeAPI.CheckErr(
RGLNativeAPI.rgl_mesh_create(out rglMeshPtr,
RGLNativeAPI.rgl_mesh_create(out RGLMeshPtr,
(IntPtr) pVertices, vertices.Length,
(IntPtr) pIndices, indices.Length / 3));
}
catch (RGLException)
{
if (rglMeshPtr != IntPtr.Zero) RGLNativeAPI.rgl_mesh_destroy(rglMeshPtr);
if (RGLMeshPtr != IntPtr.Zero) RGLNativeAPI.rgl_mesh_destroy(RGLMeshPtr);
throw;
}
}
Expand All @@ -477,13 +477,13 @@ public void UploadUVs()
else
{
unsafe
{
{
fixed(Vector2* pUVs = UVs)
{
try
{
RGLNativeAPI.CheckErr(
RGLNativeAPI.rgl_mesh_set_texture_coords(rglMeshPtr,
RGLNativeAPI.rgl_mesh_set_texture_coords(RGLMeshPtr,
(IntPtr)pUVs,
UVs.Length));
}
Expand All @@ -493,7 +493,7 @@ public void UploadUVs()
throw;
}
}
}
}
}
}
}
Expand All @@ -503,20 +503,20 @@ public void UploadUVs()
/// </summary>
public class RGLSkinnedMesh : RGLMesh
{
public SkinnedMeshRenderer SkinnedMeshRenderer;
private readonly SkinnedMeshRenderer skinnedMeshRenderer;

public RGLSkinnedMesh(int identifier, SkinnedMeshRenderer smr)
{
Identifier = identifier;
Mesh = new Mesh();
SkinnedMeshRenderer = smr;
SkinnedMeshRenderer.BakeMesh(Mesh, true);
skinnedMeshRenderer = smr;
skinnedMeshRenderer.BakeMesh(Mesh, true);
UploadToRGL();
}

public void UpdateSkinnedMesh()
{
SkinnedMeshRenderer.BakeMesh(Mesh, true);
skinnedMeshRenderer.BakeMesh(Mesh, true);
unsafe
{
// Accessing .vertices perform a CPU copy!
Expand All @@ -527,7 +527,7 @@ public void UpdateSkinnedMesh()
fixed (Vector3* pVertices = Mesh.vertices)
{
RGLNativeAPI.CheckErr(
RGLNativeAPI.rgl_mesh_update_vertices(rglMeshPtr, (IntPtr) pVertices, Mesh.vertices.Length));
RGLNativeAPI.rgl_mesh_update_vertices(RGLMeshPtr, (IntPtr) pVertices, Mesh.vertices.Length));
}
}
}
Expand All @@ -539,9 +539,9 @@ public void UpdateSkinnedMesh()
/// </summary>
public class RGLTexture
{
public int Identifier;
public Texture2D Texture;
public IntPtr rglTexturePtr = IntPtr.Zero;
public readonly int Identifier;
public readonly Texture2D Texture;
public IntPtr RGLTexturePtr = IntPtr.Zero;

public RGLTexture(){}

Expand All @@ -559,10 +559,10 @@ public RGLTexture(Texture2D texture, int identifier)

public void DestroyInRGL()
{
if (rglTexturePtr != IntPtr.Zero)
if (RGLTexturePtr != IntPtr.Zero)
{
RGLNativeAPI.CheckErr(RGLNativeAPI.rgl_texture_destroy(rglTexturePtr));
rglTexturePtr = IntPtr.Zero;
RGLNativeAPI.CheckErr(RGLNativeAPI.rgl_texture_destroy(RGLTexturePtr));
RGLTexturePtr = IntPtr.Zero;
}
}

Expand Down Expand Up @@ -591,21 +591,21 @@ protected void UploadToRGL()
{
RGLNativeAPI.CheckErr(
RGLNativeAPI.rgl_texture_create(
out rglTexturePtr,
out RGLTexturePtr,
(IntPtr) textureDataPtr,
Texture.width,
Texture.height));
}
catch (RGLException)
{
if (rglTexturePtr != IntPtr.Zero)
if (RGLTexturePtr != IntPtr.Zero)
{
RGLNativeAPI.rgl_texture_destroy(rglTexturePtr);
rglTexturePtr = IntPtr.Zero;
RGLNativeAPI.rgl_texture_destroy(RGLTexturePtr);
RGLTexturePtr = IntPtr.Zero;
}
throw;
}
}
}
}
}
}
Expand Down

0 comments on commit 21bc4ce

Please sign in to comment.