Skip to content

Commit

Permalink
Changed version to schema and removed all color variables into materials
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroHG committed Sep 27, 2022
1 parent 5285720 commit 310485b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
11 changes: 5 additions & 6 deletions unity/Assets/Scripts/ProceduralData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class Door : WallRectangularHole {
public bool openable { get; set; }
public float openness { get; set; } = 0.0f;
public string assetId { get; set; }

public MaterialProperties material { get; set; }
public Vector3? scale { get; set; } = null;
public SerializableColor color { get; set; } = null;
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public class PolygonWall {
public string roomId { get; set; }
public float thickness { get; set; }
public string layer { get; set; }
public MaterialProperties material;
public MaterialProperties material { get; set; }
public bool empty { get; set; } = false;
public bool unlit;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public class Window : WallRectangularHole {
public List<VectorXZ> axesXZ { get; set; }
public string type { get; set; }
public string assetId { get; set; }

public MaterialProperties material { get; set; }
public Vector3? scale { get; set; } = null;
public SerializableColor color { get; set; } = null;
}
Expand Down Expand Up @@ -325,7 +325,6 @@ public class HouseObject {
public bool? isDirty { get; set; } = null;

public bool unlit;
public SerializableColor color { get; set; } = null;
public MaterialProperties material;
}

Expand All @@ -339,7 +338,6 @@ public class Roof {
[Serializable]
[MessagePackObject(keyAsPropertyName: true)]
public class ProceduralHouse {
public string version;
public ProceduralParameters proceduralParameters { get; set; }
public string id { get; set; }
public List<RoomHierarchy> rooms { get; set; } = new List<RoomHierarchy>();
Expand All @@ -355,6 +353,7 @@ public class ProceduralHouse {
[MessagePackObject(keyAsPropertyName: true)]
public class HouseMetadata {
public Dictionary<string, AgentPose> agentPoses { get; set; }
public string schema { get; set; } = null;
}

[Serializable]
Expand Down Expand Up @@ -393,7 +392,7 @@ public interface WallRectangularHole {
float openness { get; set; }

Vector3? scale { get; set; }
SerializableColor color { get; set; }
MaterialProperties material { get; set; }
}

[Serializable]
Expand Down
4 changes: 2 additions & 2 deletions unity/Assets/Scripts/ProceduralTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Thor.Procedural {
public class HouseTemplate {
public string id;
public string layout;
public string version;
public string schema;
public IEnumerable<string> objectsLayouts;
public Dictionary<string, RoomTemplate> rooms;
public Dictionary<string, Thor.Procedural.Data.Door> doors;
Expand Down Expand Up @@ -418,7 +418,7 @@ public static class Templates {
});

return new ProceduralHouse() {
version = houseTemplate.version,
metadata = new HouseMetadata() { schema=houseTemplate.schema },
proceduralParameters = houseTemplate.proceduralParameters.DeepClone(),
id = !string.IsNullOrEmpty(houseTemplate.id) ? houseTemplate.id : houseId(),
rooms = roomsWithWalls.Select(p => p.room).ToList(),
Expand Down
36 changes: 24 additions & 12 deletions unity/Assets/Scripts/ProceduralTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class RoomCreatorFactory {
}

public static class ProceduralTools {
public const string CURRENT_HOUSE_VERSION = "1_0_0";
public const string CURRENT_HOUSE_SCHEMA = "1.0.0";
public class Rectangle {
public Vector3 center;
public float width;
Expand Down Expand Up @@ -1142,7 +1142,7 @@ Collider collider
return (0, 0, 0);
}
else {
var versionSplit = version.Split('_');
var versionSplit = version.Split('.');
Debug.Log(string.Join(", ", versionSplit));
var versionResult = new int[] {0, 0, 0 }.Select((x, i) => {
if (versionSplit.Length > i) {
Expand Down Expand Up @@ -1171,15 +1171,22 @@ Collider collider
AssetMap<Material> materialDb,
Vector3? position = null
) {
var version = parseHouseVersion(house.version);
var latestVersion = parseHouseVersion(CURRENT_HOUSE_VERSION);

if (house.metadata == null || house.metadata.schema == null) {
throw new ArgumentException(
$"House metadata schema not specified! Should be under house['metadata']['schema']." +
$" The current schema for this THOR version is '{CURRENT_HOUSE_SCHEMA}'"
);
}

var versionCompare = compareVersion(version, latestVersion);
var schema = parseHouseVersion(house.metadata?.schema);
var latestSchema = parseHouseVersion(CURRENT_HOUSE_SCHEMA);
var versionCompare = compareVersion(schema, latestSchema);

if (versionCompare != 0) {
var message = versionCompare < 0 ?
$"Incompatible house version '{version}', please upgrade to latest '{latestVersion}' using the 'procthor' package's 'scripts/upgrade_house.py'." :
$"Invalid house version: '{version}'. Supported version: '{latestVersion}'";
$"Incompatible house schema version '{schema}', please upgrade to latest '{latestSchema}' using the 'procthor' package's 'scripts/upgrade_house.py'." :
$"Invalid house version: '{schema}'. Supported version: '{latestSchema}'";
throw new ArgumentException(message, "house.version");
}

Expand Down Expand Up @@ -1379,7 +1386,7 @@ Collider collider
position: pos,
rotation: rotation,
kinematic: true,
color: holeCover.color,
materialProperties: holeCover.material,
positionBoundingBoxCenter: positionFromCenter,
scale: holeCover.scale
);
Expand Down Expand Up @@ -1636,7 +1643,6 @@ HouseObject ho
// ho.rotation,
rotation: Quaternion.AngleAxis(ho.rotation.degrees, ho.rotation.axis),
kinematic: ho.kinematic,
color: ho.color,
positionBoundingBoxCenter: true,
unlit: ho.unlit,
materialProperties: ho.material,
Expand All @@ -1660,7 +1666,6 @@ HouseObject ho
Quaternion rotation,
// FlexibleRotation rotation,
bool kinematic = false,
SerializableColor color = null,
bool positionBoundingBoxCenter = false,
bool unlit = false,
MaterialProperties materialProperties = null,
Expand Down Expand Up @@ -1739,12 +1744,19 @@ HouseObject ho
unlitShader = Shader.Find("Unlit/Color");
}

if (color != null) {
if (materialProperties != null) {
var materials = toSpawn.GetComponentsInChildren<MeshRenderer>().Select(
mr => mr.material
);
foreach (var mat in materials) {
mat.color = new Color(color.r, color.g, color.b, color.a);
if (materialProperties.color != null) {
mat.color = new Color(
materialProperties.color.r,
materialProperties.color.g,
materialProperties.color.b,
materialProperties.color.a
);
}
if (unlit) {
mat.shader = unlitShader;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Tests {
public class TestRendering : TestBaseProcedural {
protected HouseTemplate houseTemplate = new HouseTemplate() {
version = "1_0_0",
schema = "1_0_0",
id = "house_0",
// TODO, some assumptions can be done to place doors and objects in `layout`
// and use `objectsLayouts` for any possible inconsistencies or layering instead of being mandatory for objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TestProceduralTemplates : TestBaseProcedural
{

protected HouseTemplate houseTemplate = new HouseTemplate() {
version = ProceduralTools.CURRENT_HOUSE_VERSION,
schema = ProceduralTools.CURRENT_HOUSE_SCHEMA,
id = "house_0",
// TODO, some assumptions can be done to place doors and objects in `layout`
// and use `objectsLayouts` for any possible inconsistencies or layering instead of being mandatory for objects
Expand Down Expand Up @@ -301,8 +301,8 @@ public class TestProceduralTemplates : TestBaseProcedural
public IEnumerator TestHouseNullVersion() {
Assert.That(() => {
var house = createTestHouse();
house.version = null;
Debug.Log(house.version);
house.metadata.schema = null;
Debug.Log(house.metadata.schema);
ProceduralTools.CreateHouse(house, ProceduralTools.GetMaterials());
}, Throws.ArgumentException);
yield return true;
Expand All @@ -312,8 +312,8 @@ public class TestProceduralTemplates : TestBaseProcedural
public IEnumerator TestHouseLowerVersion() {
Assert.That(() => {
var house = createTestHouse();
house.version = "0_0_0";
Debug.Log(house.version);
house.metadata.schema = "0.0.1";
Debug.Log(house.metadata.schema);
ProceduralTools.CreateHouse(house, ProceduralTools.GetMaterials());
}, Throws.ArgumentException);
yield return true;
Expand Down
2 changes: 1 addition & 1 deletion unity/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ PlayerSettings:
webGLThreadsSupport: 0
webGLDecompressionFallback: 0
scriptingDefineSymbols:
1:
1: UNITY_POST_PROCESSING_STACK_V2
4: CROSS_PLATFORM_INPUT;MOBILE_INPUT;UNITY_POST_PROCESSING_STACK_V2
7: CROSS_PLATFORM_INPUT;MOBILE_INPUT;UNITY_POST_PROCESSING_STACK_V2
13: UNITY_POST_PROCESSING_STACK_V2
Expand Down

0 comments on commit 310485b

Please sign in to comment.