Skip to content

Commit

Permalink
Enable DynamicBatching
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7c13 committed Aug 19, 2023
1 parent 94a3bc6 commit 89aba47
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Assets/Scripts/Pal3/Effect/FireEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void Init(GameResourceProvider resourceProvider, uint effectParameter)
_sceneObjectRenderer = gameObject.AddComponent<PolyModelRenderer>();
_sceneObjectRenderer.Render(polFile,
textureProvider,
materialFactory);
materialFactory,
isStaticObject: false);
}

if (!string.IsNullOrEmpty(info.TexturePathFormat))
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Pal3/Rendering/Renderer/Mv3ModelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void Init(Mv3File mv3File,
tagNodeRenderer.Render(tagNodePolFile,
tagNodeTextureProvider,
_materialFactory,
isStaticObject: false,
tagNodeTintColor);

_tagNodes[i].transform.SetParent(transform, true);
Expand Down
8 changes: 7 additions & 1 deletion Assets/Scripts/Pal3/Rendering/Renderer/PolyModelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class PolyModelRenderer : MonoBehaviour, IDisposable
private readonly List<Coroutine> _waterAnimations = new ();
private Dictionary<string, Texture2D> _textureCache = new ();

private bool _isStaticObject;
private Color _tintColor;
private bool _isWaterSurfaceOpaque;

Expand All @@ -41,11 +42,13 @@ public class PolyModelRenderer : MonoBehaviour, IDisposable
public void Render(PolFile polFile,
ITextureResourceProvider textureProvider,
IMaterialFactory materialFactory,
bool isStaticObject,
Color? tintColor = default,
bool isWaterSurfaceOpaque = default)
{
_textureProvider = textureProvider;
_materialFactory = materialFactory;
_isStaticObject = isStaticObject;
_tintColor = tintColor ?? Color.white;
_isWaterSurfaceOpaque = isWaterSurfaceOpaque;
_textureCache = BuildTextureCache(polFile, textureProvider);
Expand Down Expand Up @@ -149,7 +152,10 @@ private void RenderMeshInternal(PolGeometryNode meshNode, PolMesh mesh)
return;
}

var meshObject = new GameObject(meshNode.Name);
GameObject meshObject = new (meshNode.Name)
{
isStatic = _isStaticObject
};

// Attach BlendFlag and GameBoxMaterial to the GameObject for better debuggability
#if UNITY_EDITOR
Expand Down
7 changes: 6 additions & 1 deletion Assets/Scripts/Pal3/Scene/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,18 @@ public bool IsPositionInsideJumpableArea(int layerIndex, Vector2Int tilePosition
private void RenderMesh()
{
// Render mesh
_mesh = new GameObject($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}");
_mesh = new GameObject($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}")
{
isStatic = true // Scene mesh is static
};

var polyMeshRenderer = _mesh.AddComponent<PolyModelRenderer>();
_mesh.transform.SetParent(_parent.transform, false);

polyMeshRenderer.Render(ScenePolyMesh.PolFile,
ScenePolyMesh.TextureProvider,
_materialFactory,
isStaticObject: true, // Scene mesh is static
Color.white,
IsWaterSurfaceOpaque());

Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Pal3/Scene/SceneObjects/ImpulsiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public override GameObject Activate(GameResourceProvider resourceProvider, Color
subObjectModelRenderer.Render(polFile,
textureProvider,
resourceProvider.GetMaterialFactory(),
isStaticObject: false,
subObjectTintColor);

_subObjectController = _subObjectGameObject.AddComponent<ImpulsiveMechanismSubObjectController>();
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Pal3/Scene/SceneObjects/SceneObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public virtual GameObject Activate(GameResourceProvider resourceProvider,
_polyModelRenderer.Render(polFile,
textureProvider,
materialFactory,
isStaticObject: false,
tintColor);
}
else if (ModelType == SceneObjectModelType.CvdModel)
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/ResourceViewer/GameResourceViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ private bool LoadPol(string filePath)
meshRenderer.Render(polyFile,
textureProvider,
_resourceProvider.GetMaterialFactory(),
isStaticObject: true,
Color.white);

consoleTextUI.text = $"{filePath}";
Expand Down
6 changes: 3 additions & 3 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,16 @@ PlayerSettings:
m_BuildTargetBatching:
- m_BuildTarget: Standalone
m_StaticBatching: 0
m_DynamicBatching: 0
m_DynamicBatching: 1
- m_BuildTarget: tvOS
m_StaticBatching: 0
m_DynamicBatching: 0
- m_BuildTarget: Android
m_StaticBatching: 0
m_DynamicBatching: 0
m_DynamicBatching: 1
- m_BuildTarget: iPhone
m_StaticBatching: 0
m_DynamicBatching: 0
m_DynamicBatching: 1
- m_BuildTarget: WebGL
m_StaticBatching: 0
m_DynamicBatching: 0
Expand Down

0 comments on commit 89aba47

Please sign in to comment.