Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomization operations on objects within composition #213

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions GameRealisticMap.Arma3/Assets/CompositionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,49 @@
using System.Text.Json.Serialization;
using GameRealisticMap.IO.Converters;
using GameRealisticMap.Arma3.TerrainBuilder;
using GameRealisticMap.Algorithms;
using GameRealisticMap.Algorithms.Randomizations;

namespace GameRealisticMap.Arma3.Assets
{
[DebuggerDisplay("{Model} ({Transform.M41};{Transform.M43})")]
public class CompositionObject
{
[JsonConstructor]
public CompositionObject(ModelInfo model, Matrix4x4 transform)
public CompositionObject(ModelInfo model, Matrix4x4 transform, List<IRandomizationOperation>? randomizations = null)
{
Model = model;
Transform = transform;
Randomizations = randomizations;
}

public ModelInfo Model { get; }

[JsonConverter(typeof(Matrix4x4Converter))]
public Matrix4x4 Transform { get; }

public TerrainBuilderObject ToTerrainBuilderObject(Matrix4x4 matrix, ElevationMode mode)
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<IRandomizationOperation>? Randomizations { get; }

public TerrainBuilderObject ToTerrainBuilderObject(Matrix4x4 matrix, ElevationMode mode, Random? parentRandom = null)
{
if (Randomizations != null && Randomizations.Count > 0)
{
var modelCenter = new Vector3(Transform.M41, Transform.M42, Transform.M43);
var random = parentRandom ?? RandomHelper.CreateRandom(new Geometries.TerrainPoint(matrix.M41 + Transform.M41, matrix.M43 + Transform.M43));
var randomization = Randomizations[0].GetMatrix(random, modelCenter);
foreach (var operation in Randomizations.Skip(1))
{
randomization = randomization * operation.GetMatrix(random, modelCenter);
}
return new TerrainBuilderObject(Model, Transform * randomization * matrix, mode);
}
return new TerrainBuilderObject(Model, Transform * matrix, mode);
}

public TerrainBuilderObject ToTerrainBuilderObjectVerbatim()
{
return new TerrainBuilderObject(Model, Transform, ElevationMode.Absolute);
}
}
}
87 changes: 59 additions & 28 deletions GameRealisticMap.Arma3/Builtin/CentralEurope.grma3a
Original file line number Diff line number Diff line change
Expand Up @@ -4738,43 +4738,74 @@
"Objects": [
{
"Model": "a3\\vegetation_f_argo\\Bushes\\b_Vitis_vinifera_F.p3d",
"Transform": [-0.8906791,0,-0.45463243,0,1,0,0.45463243,0,-0.8906791,-2.6210938,1.058703,-0.2529297]
"Transform": [-0.8906791,0,-0.45463243,0,1,0,0.45463243,0,-0.8906791,-2.6210938,1.058703,-0.2529297],
"Randomizations": [
{
"Type": "ScaleUniform",
"Min": 0.9,
"Max": 1.1
},
{
"Type": "RotateY",
"Min": 0,
"Max": 360,
"CenterPoint": [-2.5,0,0]
},
{
"Type": "TranslateRadiusXZ",
"Min": 0,
"Max": 0.1
}
]
},
{
"Model": "a3\\structures_f_argo\\Industrial\\Agriculture\\VineyardFence_01_F.p3d",
"Transform": [0.01953125,0.60459185,0.006591797]
"Transform": [0.01953125,0.60459185,0.006591797],
"Randomizations": []
},
{
"Model": "a3\\vegetation_f_argo\\Bushes\\b_Vitis_vinifera_F.p3d",
"Transform": [0.30078125,1.058703,0.4934082]
},
{
"Model": "a3\\vegetation_f_argo\\Bushes\\b_Vitis_vinifera_F.p3d",
"Transform": [-0.7686965,0,0.6396137,0,1,0,-0.6396137,0,-0.7686965,2.3632812,1.058703,0.06591797]
}
]
},
"Size": 8.4
},
{
"Proportion": 1,
"Model": {
"Objects": [
{
"Model": "a3\\structures_f_argo\\Industrial\\Agriculture\\VineyardFence_01_F.p3d",
"Transform": [0.01953125,0.60459185,0.006591797]
},
{
"Model": "a3\\vegetation_f_argo\\Bushes\\b_Vitis_vinifera_F.p3d",
"Transform": [-1,0,1.509958E-07,0,1,0,-1.509958E-07,0,-1,-0.29296875,1.058703,-0.20776367]
},
{
"Model": "a3\\vegetation_f_argo\\Bushes\\b_Vitis_vinifera_F.p3d",
"Transform": [-4.371139E-08,0,1,0,1,0,-1,0,-4.371139E-08,2.3476562,1.058703,0.27954102]
"Transform": [0.30078125,1.058703,0.4934082],
"Randomizations": [
{
"Type": "ScaleUniform",
"Min": 0.9,
"Max": 1.1
},
{
"Type": "RotateY",
"Min": 0,
"Max": 360,
"CenterPoint": [0,0,0]
},
{
"Type": "TranslateRadiusXZ",
"Min": 0,
"Max": 0.1
}
]
},
{
"Model": "a3\\vegetation_f_argo\\Bushes\\b_Vitis_vinifera_F.p3d",
"Transform": [0.70710677,0,-0.70710677,0,1,0,0.70710677,0,0.70710677,-2.2617188,1.058703,0.21240234]
"Transform": [-0.7686968,0,0.63961333,0,1,0,-0.63961333,0,-0.7686968,2.3632812,1.058703,0.06591797],
"Randomizations": [
{
"Type": "ScaleUniform",
"Min": 0.9,
"Max": 1.1
},
{
"Type": "RotateY",
"Min": 0,
"Max": 360,
"CenterPoint": [2.8,0,0]
},
{
"Type": "TranslateRadiusXZ",
"Min": 0,
"Max": 0.1
}
]
}
]
},
Expand Down
72 changes: 72 additions & 0 deletions GameRealisticMap.Studio/Labels.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions GameRealisticMap.Studio/Labels.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1579,4 +1579,28 @@ Dernière génération le {1}</value>
<data name="GroundDetailTextureLibrary" xml:space="preserve">
<value>Bibliothèque des textures de sol</value>
</data>
<data name="RandomizationScaleUniform" xml:space="preserve">
<value>Faire varier la taille</value>
</data>
<data name="RandomizationRotateY" xml:space="preserve">
<value>Faire tourner</value>
</data>
<data name="RandomizationTranslateRadiusXZ" xml:space="preserve">
<value>Déplacer au sein d'un rayon</value>
</data>
<data name="RandomizationTranslateX" xml:space="preserve">
<value>Déplacer sur l'axe X</value>
</data>
<data name="RandomizationTranslateZ" xml:space="preserve">
<value>Déplacer sur l'axe Y</value>
</data>
<data name="RandomizationTranslateY" xml:space="preserve">
<value>Faire varier l'altitude</value>
</data>
<data name="AddRandomization" xml:space="preserve">
<value>Ajouter un aléa</value>
</data>
<data name="CenterOn" xml:space="preserve">
<value>centrée sur</value>
</data>
</root>
24 changes: 24 additions & 0 deletions GameRealisticMap.Studio/Labels.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1579,4 +1579,28 @@ Last generated on {1}</value>
<data name="GroundDetailTextureLibrary" xml:space="preserve">
<value>Ground Detail Texture Library</value>
</data>
<data name="RandomizationScaleUniform" xml:space="preserve">
<value>Scale variation</value>
</data>
<data name="RandomizationRotateY" xml:space="preserve">
<value>Rotate</value>
</data>
<data name="RandomizationTranslateRadiusXZ" xml:space="preserve">
<value>Move within radius</value>
</data>
<data name="RandomizationTranslateX" xml:space="preserve">
<value>Move on X Axis</value>
</data>
<data name="RandomizationTranslateZ" xml:space="preserve">
<value>Move on Y Axis</value>
</data>
<data name="RandomizationTranslateY" xml:space="preserve">
<value>Elevation variation</value>
</data>
<data name="AddRandomization" xml:space="preserve">
<value>Add randomization</value>
</data>
<data name="CenterOn" xml:space="preserve">
<value>centered on</value>
</data>
</root>
Loading
Loading