Skip to content

Commit

Permalink
Add support for assigning custom camera properties per model group in…
Browse files Browse the repository at this point in the history
… the manifest (#355)

* Add support for assigning custom camera properties per model group in the manifest

* Add comment describing how to add additional custom cameras
  • Loading branch information
stevk authored Mar 5, 2018
1 parent eca46d0 commit d407852
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 11 deletions.
91 changes: 84 additions & 7 deletions Source/Manifest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Numerics;
using System.Text.RegularExpressions;
using System.IO;
using System;

namespace AssetGenerator
{
Expand All @@ -10,37 +9,115 @@ public class Manifest
public string folder;
public List<Model> models = new List<Model>();

// Model group, to be listed in the manifest as the folder name
public Manifest(ModelGroupName name)
{
folder = name.ToString();
}

// Model properties to be listed in the manifest
public class Model
{
public string fileName;
public string sampleImageName;
public string sampleThumbnailName;
public Camera camera;

public Model(string name, Vector3 trans, Vector4 rot)
public Model(string name, ModelGroupName modelGroupName)
{
fileName = name;
sampleImageName = "SampleImages" + '/' + name.Replace(".gltf", ".png");
sampleThumbnailName = "Thumbnails" + '/' + name.Replace(".gltf", ".png");
camera = new Camera(trans, rot);
camera = CustomCameraList.GetCamera(modelGroupName);
}
}

// Camera properties
public class Camera
{
public float[] translation = new float[3];
public float[] rotation = new float[4];

public Camera(Vector3 trans, Vector4 rot)
public Camera(Vector3 cameratranslation, Vector4 cameraRotation)
{
trans.CopyTo(translation);
rot.CopyTo(rotation);
cameratranslation.CopyTo(translation);
cameraRotation.CopyTo(rotation);
}
}

// Used to track camera properties for model groups that need a custom camera
internal static class CustomCameraList
{
internal static List<ModelCameraPairing> customCameraList;

internal class ModelCameraPairing
{
internal Camera camera;
internal ModelGroupName modelGroup;

internal ModelCameraPairing(Camera cameraSettings, ModelGroupName name)
{
camera = cameraSettings;
modelGroup = name;
}
}

internal static Camera GetCamera(ModelGroupName modelGroup)
{
// Checks if the list has been initialized, so it isn't recreated multiple times.
if (customCameraList == null)
{
BuildCameraParings();
}

// Searches the list for a matching custom camera
var custom = customCameraList.Find(e => e.modelGroup == modelGroup);
Camera camera;

// Use the custom camera if it is found, otherwise use the default camera
if (custom == null)
{
camera = customCameraList[0].camera;
}
else
{
camera = custom.camera;
}

return camera;
}

/// <summary>
/// Contains the values used for the camera when creating sample images of the models. They all use the first
/// by default, but adding in another section below will cause all models in that model group to use that camera.
/// This is the only section that will need to be changed when needing to use a custom camera for the sample images.
/// </summary>
internal static void BuildCameraParings()
{
customCameraList = new List<ModelCameraPairing>();

// Default camera position. Keep this in the first position on the list.
customCameraList.Add(
new ModelCameraPairing(
new Camera(new Vector3((float)Math.PI / 2, (float)Math.PI / 2, -1.3f), new Vector4(0, 0, 0, 1)),
ModelGroupName.Undefined)
);

// Node_Attribute
customCameraList.Add(
new ModelCameraPairing(
new Camera(new Vector3((float)Math.PI / 2, (float)Math.PI / 2, -1.3f), new Vector4(0, 0, 0, 1)),
ModelGroupName.Node_Attribute)
);

// Node_NegativeScale
customCameraList.Add(
new ModelCameraPairing(
new Camera(new Vector3((float)Math.PI / 2, (float)Math.PI / 2, -1.3f), new Vector4(0, 0, 0, 1)),
ModelGroupName.Node_NegativeScale)
);
}

}
}
}
5 changes: 1 addition & 4 deletions Source/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ private static void Main(string[] args)

readme.SetupTable(modelGroup, comboIndex, combos);
manifest.models.Add(
new Manifest.Model(
filename,
new System.Numerics.Vector3((float)Math.PI / 2, (float)Math.PI / 2, -1.3f),
new System.Numerics.Vector4(0, 0, 0, 1)));
new Manifest.Model(filename, modelGroup.modelGroupName));
}

readme.WriteOut(executingAssembly, modelGroup, assetFolder);
Expand Down

0 comments on commit d407852

Please sign in to comment.