Skip to content

Instantly share code, notes, and snippets.

@lukaspj
Last active August 25, 2015 21:51
Show Gist options
  • Save lukaspj/37775bf98ffe09cc2611 to your computer and use it in GitHub Desktop.
Save lukaspj/37775bf98ffe09cc2611 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Reflection;
using HorribleHackz.CustomAttributes;
using Torque6_Bridge.Namespaces;
using Torque6_Bridge.SimObjects;
using Console = Torque6_Bridge.Namespaces.Console;
using Version = Torque6_Bridge.Namespaces.Version;
namespace HorribleHackz
{
internal class MainClass
{
public static ModuleManager ModuleDatabase;
public static AssetManager AssetDatabase;
[ScriptEntryPoint]
public static void EntryPoint()
{
RunMaterialsProjects();
}
private static void RunMaterialsProjects()
{
// Mandatory initialization, since these can't be set based on the non-existant main.cs
string CSDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
CSDir = "E:\\GitHub\\Torque6\\projects\\06-Materials";
Engine.SetMainDotCsDir(CSDir);
Engine.SetCurrentDirectory(CSDir);
// Logging settings
Console.SetLogMode(2);
Console.PrintEchoFileLoads(true);
Script.Trace(false);
// Not really necessary, but shows how globals work
Globals.SetBool("Scripts::ignoreDSOs", true);
// This is my realm!
Version.SetCompanyAndProduct("LukasPJ", "Torque6");
// Find the Databases by name
ModuleDatabase = new ModuleManager("ModuleDatabase");
AssetDatabase = new AssetManager("AssetDatabase");
// Make sure they have been created
if (ModuleDatabase.IsDead())
throw new Exception("ModuleDatabase not found");
if (AssetDatabase.IsDead())
throw new Exception("AssetDatabase not found");
ModuleDatabase.EchoInfo = true;
AssetDatabase.EchoInfo = true;
AssetDatabase.IgnoreAutoUnload = true;
// Scan modules.
ModuleDatabase.ScanModules("modules");
ModuleDatabase.ScanModules("../shared-modules");
// Load AppCore module.
ModuleDatabase.LoadExplicit("AppCore");
// Load the modules needed for this example
ModuleDatabase.LoadExplicit("Console");
ModuleDatabase.LoadExplicit("FreeViewCamera");
ModuleDatabase.LoadExplicit("ExampleRoom");
ModuleDatabase.LoadExplicit("Skybox");
// Editor is not required, but try to load it anyway.
ModuleDatabase.LoadExplicit("Editor");
// Load the example itself.
ModuleDatabase.LoadExplicit("MaterialExample");
}
[ConsoleFunction]
public static void onExit()
{
// Unload the AppCore module.
ModuleDatabase.UnloadExplicit("AppCore");
}
[ConsoleFunction]
public static void androidBackButton(string val)
{
// Quit on button down
if (val == "1")
Engine.Quit();
}
}
}
using HorribleHackz.CustomAttributes;
using Torque6_Bridge.Namespaces;
using Torque6_Bridge.SimObjects;
using Torque6_Bridge.SimObjects.Scene;
using Torque6_Bridge.Types;
namespace HorribleHackz
{
[ConsoleClass]
internal class MaterialExample
{
public static void create()
{
// Create some dwarfs!
SceneEntity spheres = new SceneEntity
{
Template = "MaterialExample:TestSpheres",
Position = Point3F.Zero(),
Rotation = Point3F.Zero()
};
// Register the object! (Similar to how you do it in C++)
spheres.RegisterObject();
// Add it to the scene!
Scene.AddEntity(spheres, "Spheres");
float metal = 0.0f;
float rough = 0.0f;
for (int i = 0; i < 25; i++)
{
MeshComponent mesh = spheres.FindComponent("TestSphere" + i).As<MeshComponent>();
mesh.SetUniformVec4("sphereMetalVal", new Point4F(metal, 0, 0, 0));
mesh.SetUniformVec4("sphereRoughVal", new Point4F(rough, 0, 0, 0));
metal += 0.25f;
if (metal > 1.0f)
{
metal = 0.0f;
rough += 0.25f;
}
}
// More lights I guess
Scene.SetDirectionalLight(new Point3F(1, 1, -1), new Color(1.0f, 1.0f, 1.0f), new Color(0.2f, 0.2f, 0.2f));
Script.Eval("Skybox::load(expandPath(\"^Skybox/textures/pisa_lod.dds\"));");
Script.Eval("Skybox::enable();");
}
public static void destroy()
{
Console.Print("DESTROYED MaterialExample MODULE");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment