Newer
Older
Marco Zimmer
committed
using System.Collections.Generic;
Marco Zimmer
committed
public class GenerateDemoFiles
{
public static void GenerateAll()
{
if (UnityEngine.Object.FindObjectOfType<GadgetBehaviour>(true) == null)
Debug.LogError("Cannot GenerateDemoFiles without populated GadgetManager");
return;
}
Marco Zimmer
committed
Debug.LogWarning("Generating and Overwriting Stage Files");
Action[] DemoGeneration = new Action[]{
GenerateTreeStage,
GenerateRiverStage,
MaZiFAU
committed
GenerateCanonBallStage2D,
GenerateCanonBallStage3D,
};
foreach (Action action in DemoGeneration)
try
{
action();
Debug.Log("Successfully executed " + action.Method.Name);
}
catch (Exception ex)
{
Debug.LogError("Exception while executing " + action.Method.Name);
Debug.LogException(ex);
}
Marco Zimmer
committed
}
Marco Zimmer
committed
{
// Params
float minimalSolutionHight = 6;
// Generate Stage
category: "Demo Category",
name: "TechDemo A",
scene: "RiverWorld",
description: "Tree Stage",
local: false
);
Marco Zimmer
committed
// Populate Solution
PointFact
buttom = new PointFact(Vector3.zero, Vector3.up),
top = new PointFact(Vector3.zero + Vector3.up * minimalSolutionHight, Vector3.up);
Marco Zimmer
committed
StageStatic.stage.solution.Add(buttom, out _, false, null, null);
StageStatic.stage.solution.Add(top, out _, true, null, null);
Marco Zimmer
committed
LineFact target = new LineFact(buttom.Id, top.Id);
var target_Id = StageStatic.stage.solution.Add(target, out _, true, null, null);
Marco Zimmer
committed
// Set Solution
Marco Zimmer
committed
StageStatic.stage.solution.ValidationSet =
new List<SolutionRecorder.SubSolution>
{ new SolutionRecorder.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()) };
Marco Zimmer
committed
StageStatic.stage.AllowedGadgets = null;
Marco Zimmer
committed
// Save
Marco Zimmer
committed
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
Marco Zimmer
committed
}
{
// Params
float minimalSolutionHight = 6;
// Generate Stage
category: "Demo Category",
name: "TechDemo B",
scene: "RiverWorld",
description: "River Stage",
local: false
);
buttom = new PointFact(Vector3.zero, Vector3.up),
top = new PointFact(Vector3.zero + Vector3.up * minimalSolutionHight, Vector3.up);
StageStatic.stage.solution.Add(buttom, out _, false, null, null);
StageStatic.stage.solution.Add(top, out _, true, null, null);
LineFact target = new LineFact(buttom.Id, top.Id);
var target_Id = StageStatic.stage.solution.Add(target, out _, true, null, null);
// Set Solution
StageStatic.stage.solution.ValidationSet =
new List<SolutionRecorder.SubSolution> {
new SolutionRecorder.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
new SolutionRecorder.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
new SolutionRecorder.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
StageStatic.stage.AllowedGadgets = new() { new Pointer(), new Tape(), new AngleTool(), new LineTool(), new LotTool(), new Pendulum(), new Remover() }; //, new EqualCircleGadget(), new TestMiddlePoint() };
StageStatic.stage.AllowedScrolls = new() {
"http://mathhub.info/FrameIT/frameworld?OppositeLen",
//"http://mathhub.info/FrameIT/frameworld?SupplementaryAngles",
//"http://mathhub.info/FrameIT/frameworld?AngleSum",
//"http://mathhub.info/FrameIT/frameworld?Pythagoras",
//"http://mathhub.info/FrameIT/frameworld?CylinderVolumeScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleLineAngleToAngleScroll",
//"http://mathhub.info/FrameIT/frameworld?Midpoint",
//"http://mathhub.info/FrameIT/frameworld?CircleScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleLineAngleScroll",
//"http://mathhub.info/FrameIT/frameworld?CircleAreaScroll",
//"http://mathhub.info/FrameIT/frameworld?ConeVolumeScroll",
//"http://mathhub.info/FrameIT/frameworld?TruncatedConeVolumeScroll",
};
Marco Zimmer
committed
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
MaZiFAU
committed
public static void GenerateCanonBallStage2D()
{
// Params //List<Wall> walls, T starPos, T starVec, T gravity, int dimension
int
dim_const = 0,
MaZiFAU
committed
dim_A = 1,
dim_B = 2;
float Py_factor = 0.04905f;
float Py_bounce = 0.8f;
MaZiFAU
committed
float3 StartPos_py = new(0.0f, 300.0f, 380.0f);
float3 StartVec_py = new(0.0f, 150.0f, -490.0f);
float3 Gravity_py = new(0.0f, -200f, 0.0f);
(double x1, double x2, double y1, double y2)[] PythonParams = {
(-1.0, 0.0, 401.0, 0.0 ),
(0.0, -1.0, 0.01, 401.0 ),
(400.0, -1.0, 400.01, 401.0),
(-1.0, 400.0, 401.0, 400.0),
(50.0, 200.0, 120.0, 270.0),
(150.0, 100.0, 200.0, 100.0),
(150.0, 285.0, 200.0, 200.0),
(230.0, 360.0, 300.0, 300.0),
(300.0, 100.0, 385.0, 150.0),
(50.0, 50.0, 100.0, 135.0),
};
//Parse PythonParams
Vector3
StartPos = Vector3.zero,
StartVec = Vector3.zero,
Gravity = Vector3.zero;
MaZiFAU
committed
StartPos[0] = StartPos_py[0] * Py_factor;
StartPos[1] = StartPos_py[1] * Py_factor;
StartPos[2] = StartPos_py[2] * Py_factor;
MaZiFAU
committed
StartVec[0] = StartVec_py[0] * Py_factor;
StartVec[1] = StartVec_py[1] * Py_factor;
StartVec[2] = StartVec_py[2] * Py_factor;
MaZiFAU
committed
Gravity[0] = Gravity_py[0] * Py_factor;
Gravity[1] = Gravity_py[1] * Py_factor;
Gravity[2] = Gravity_py[2] * Py_factor;
float[,,] Wall_parameter = new float[PythonParams.Length, 2, 2];
for (uint i = 0; i < PythonParams.Length; i++)
{
MaZiFAU
committed
Wall_parameter[i, 0, 0] = (float)(Py_factor * (PythonParams[i].x1));
Wall_parameter[i, 0, 1] = (float)(Py_factor * (PythonParams[i].x2));
MaZiFAU
committed
Wall_parameter[i, 1, 0] = (float)(Py_factor * (PythonParams[i].y1));
Wall_parameter[i, 1, 1] = (float)(Py_factor * (PythonParams[i].y2));
MaZiFAU
committed
category: "CanonBall",
name: "CanonBall 2D",
MaZiFAU
committed
description: "CanonBall 2D Test",
local: false
);
// Populate Solution
MaZiFAU
committed
string BallURI = StageStatic.stage.solution.Add(
new PointFact(StartPos, Vector3.up),
MaZiFAU
committed
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI);
string VecURI = StageStatic.stage.solution.Add(
new PointFact(StartVec, StartVec.normalized),
MaZiFAU
committed
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(VecURI);
string GravURI = StageStatic.stage.solution.Add(
new PointFact(Gravity, Gravity.normalized),
MaZiFAU
committed
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(GravURI);
string BounceURI = StageStatic.stage.solution.Add(
new RealLitFact(Py_bounce),
MaZiFAU
committed
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BounceURI);
List<LineFact> Walls = new();
for (int i = 0; i < PythonParams.Length; i++)
{
Vector3 tmpVec = Vector3.zero;
MaZiFAU
committed
tmpVec[dim_A] = Wall_parameter[i, 0, 1];
tmpVec[dim_B] = Wall_parameter[i, 0, 0];
PointFact topA = new(tmpVec, Vector3.up);
string topAURI = StageStatic.stage.solution.Add(topA, out _, false, null, null);
MaZiFAU
committed
tmpVec[dim_A] = Wall_parameter[i, 1, 1];
tmpVec[dim_B] = Wall_parameter[i, 1, 0];
PointFact topB = new(tmpVec, Vector3.up);
string topBURI = StageStatic.stage.solution.Add(topB, out _, true, null, null);
LineFact topology = new(topAURI, topBURI);
MaZiFAU
committed
string lineURI = StageStatic.stage.solution.Add(topology, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(lineURI);
MaZiFAU
committed
Walls.Add(topology);
MaZiFAU
committed
//StageStatic.stage.solution.Add( // for CannonBallScroll
// new ListFact(Walls.Select(w => w.Topology.Id).ToArray(), null, new OMS(MMTConstants.TYPE_TO_OMS[typeof(LineFact)]), StageStatic.stage.solution),
// out bool _, true, null, null
//);
SOMDoc[] RRRRTupel = new SOMDoc[Walls.Count];
RRRRTupel[i] =
SOMDoc.MakeTupel(
SOMDoc.MakeTupel(new OMLIT<float>[] { new((float)PythonParams[i].x1), new((float)PythonParams[i].x2) }),
SOMDoc.MakeTupel(new OMLIT<float>[] { new((float)PythonParams[i].y1), new((float)PythonParams[i].y2) }),
new ListFact(null, RRRRTupel, null),
out bool _, true, null, null
);
#endregion CannonBallScroll
MaZiFAU
committed
CanonBallProblemCalculator2D calc = new(Walls, StartPos, StartVec, Gravity, Py_bounce, dim_const, dim_A, dim_B, StageStatic.stage.solution);
StageStatic.stage.solution.ExposedSolutionFacts.AddRange(calc.Result_FuncCall_Id);
MaZiFAU
committed
//string attacheFactURI = StageStatic.stage.solution.Add(
// new AttachedPositionFunction(BallURI, calc.Result_FuncCall_Id.ToArray(), StageStatic.stage.solution),
// out _, true, null, null);
//StageStatic.stage.solution.ExposedSolutionFacts.Add(attacheFactURI);
MaZiFAU
committed
//TODO: ~attach funcs + ~cheat?
//StageStatic.stage.solution.ValidationSet =
// new List<SolutionOrganizer.SubSolution> {
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
// new SolutionOrganizer.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
// };
// Set Gadgets/ Scrolls
StageStatic.stage.AllowedGadgets = null;
StageStatic.stage.AllowedScrolls = new() { MMTConstants.ScrollCannonBall2D };
StageStatic.stage.solution.ScrollOverwrites.Add(MMTConstants.ScrollCannonBall2D, new[] {
(BallURI, 0, true),
(VecURI, 1, true),
(GravURI, 2, true),
(BounceURI, 3, true),
(RRRRURI, 4, true),
});
MaZiFAU
committed
// Save
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
}
public static void GenerateCanonBallStage3D()
{
// Params //List<Wall> walls, T starPos, T starVec, T gravity, int dimension
int
dim_G = 1,
dim_A = 2,
dim_B = 0;
float Py_factor = 0.04905f;
float Py_bounce = 0.8f;
MaZiFAU
committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
float3 StartPos_py = new(380, 0, 300);
float3 StartVec_py = new(-490, 100, 150);
float3 Gravity_py = new(0, 0, -200);
double[,,] PythonWalls = new double[,,] {
{
{ 0, 0, 0 },
{ 400, 0, 0 },
{ 400, 0, 400 },
{ 0, 0, 400 },
},{
{ 0, 400, 0 },
{ 400, 400, 0 },
{ 400, 400, 400 },
{ 0, 400, 400 },
},{
{ 250, 0, 0 },
{ 300, 0, 0 },
{ 300, 400, 0 },
{ 250, 400, 0 },
},{
{ 0, 0, 0 },
{ 0, 0, 400 },
{ 0, 400, 400 },
{ 0, 400, 0 },
},{
{ 400, 0, 0 },
{ 400, 0, 400 },
{ 400, 400, 400 },
{ 400, 400, 0 },
},{
{ 0, 0, 400 },
{ 400, 0, 400 },
{ 400, 400, 400 },
{ 0, 400, 400 },
},{
{ 300, 0, 0 },
{ 400, 0, 0 },
{ 400, 400, 0},
{ 300, 400, 0},
},{
{ 0, 0, 0 },
{ 250, 0, 0 },
{ 250, 400, 0 },
{ 0, 400, 0 },
},{
{ 50, 0, 200 },
{ 120.7, 0, 270.7 },
{ 120.7, 200, 270.7 },
{ 50, 200, 200 },
},{
{ 150, 0, 100 },
{ 200, 0, 100 },
{ 200, 200, 100 },
{ 150, 200, 100 },
},{
{ 150, 0, 286.6 },
{ 200, 0, 200 },
{ 200, 200, 200 },
{ 150, 200, 286.6 },
},{
{ 230.7, 0, 340 },
{ 300, 0, 300 },
{ 300, 200, 300 },
{ 230.7, 200, 340 },
},{
{ 300, 0, 100 },
{ 386.6, 0, 150 },
{ 386.6, 200, 150 },
{ 300, 200, 100 },
},{
{ 50, 0, 50 },
{ 100, 0, 136.6 },
{ 100, 200, 136.6 },
{ 50, 200, 50 },
}};
//Parse PythonParams
Vector3
StartPos = Vector3.zero,
StartVec = Vector3.zero,
Gravity = Vector3.zero;
StartPos[dim_A] = StartPos_py[0] * Py_factor;
StartPos[dim_B] = StartPos_py[1] * Py_factor;
StartPos[dim_G] = StartPos_py[2] * Py_factor;
StartVec[dim_A] = StartVec_py[0] * Py_factor;
StartVec[dim_B] = StartVec_py[1] * Py_factor;
StartVec[dim_G] = StartVec_py[2] * Py_factor;
Gravity[dim_A] = Gravity_py[0] * Py_factor;
Gravity[dim_B] = Gravity_py[1] * Py_factor;
Gravity[dim_G] = Gravity_py[2] * Py_factor;
float[,,] Wall_parameter = new float[PythonWalls.GetLength(0), PythonWalls.GetLength(1), PythonWalls.GetLength(2)];
for (int i = 0; i < PythonWalls.GetLength(0); i++)
for (int j = 0; j < PythonWalls.GetLength(1); j++)
for (int k = 0; k < PythonWalls.GetLength(2); k++)
Wall_parameter[i, j, k] = (float)(PythonWalls[i, j, k] * Py_factor);
// Generate Stage
MaZiFAU
committed
(
MaZiFAU
committed
category: "CanonBall",
name: "CanonBall 3D",
scene: "RiverWorld",
description: "CanonBall 3D Test",
local: false
);
// Populate Solution
string BallURI = StageStatic.stage.solution.Add(
new PointFact(StartPos, Vector3.up),
MaZiFAU
committed
StageStatic.stage.solution.ExposedSolutionFacts.Add(BallURI);
string VecURI = StageStatic.stage.solution.Add(
new PointFact(StartVec, StartVec.normalized),
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(VecURI);
MaZiFAU
committed
string GravURI = StageStatic.stage.solution.Add(
new PointFact(Gravity, Gravity.normalized),
MaZiFAU
committed
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(GravURI);
string BounceURI = StageStatic.stage.solution.Add(
new RealLitFact(Py_bounce),
MaZiFAU
committed
out _, false, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(BounceURI);
List<QuadFact> Walls = new();
List<TriangleFact> Trieangles = new();
MaZiFAU
committed
for (int i = 0; i < Wall_parameter.GetLength(0); i++)
{
Vector3[] corners = new Vector3[4];
MaZiFAU
committed
string[] edge = new string[4];
for (int j = 0; j < Wall_parameter.GetLength(1); j++)
{
MaZiFAU
committed
tmpVec[dim_A] = Wall_parameter[i, j, 0];
tmpVec[dim_B] = Wall_parameter[i, j, 1];
tmpVec[dim_G] = Wall_parameter[i, j, 2];
MaZiFAU
committed
PointFact edge_point = new(tmpVec, Vector3.up);
MaZiFAU
committed
edge[j] = StageStatic.stage.solution.Add(edge_point, out _, false, null, null);
}
QuadFact topology = new(edge);
MaZiFAU
committed
string quadURI = StageStatic.stage.solution.Add(topology, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(quadURI);
TriangleFact top0 = new(new[] { corners[0], corners[1], corners[2] });
string top0URI = StageStatic.stage.solution.Add(top0, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(top0URI);
TriangleFact top1 = new(new[] { corners[2], corners[3], corners[0] });
string top1URI = StageStatic.stage.solution.Add(top1, out _, true, null, null);
StageStatic.stage.solution.ExposedSolutionFacts.Add(top1URI);
MaZiFAU
committed
Walls.Add(topology);
Trieangles.Add(top0);
Trieangles.Add(top1);
MaZiFAU
committed
}
// Set Solution
#region CannonBallScroll
string TriangleURI = StageStatic.stage.solution.Add( // for CannonBallScroll
new ListFact(Trieangles.Select(q => q.Id).ToArray(), null, new OMS(MMTConstants.TYPE_TO_OMS[typeof(TriangleFact)])),
out bool _, true, null, null
);
MaZiFAU
committed
// special case for Prototype
SOMDoc[] RRRRTupel = new SOMDoc[Walls.Count];
for (int i = 0; i < Walls.Count; i++)
{
RRRRTupel[i] = SOMDoc.MakeTupel(
Walls[i].Pids.Select(p => new OMS(p)).ToArray()
);
}
new ListFact(null, RRRRTupel, null),
MaZiFAU
committed
out bool _, true, null, null
);
#endregion CannonBallScroll
CanonBallProblemCalculator3D calc = new(Walls, StartPos, StartVec, Gravity, Py_bounce, dim_G, dim_A, dim_B, StageStatic.stage.solution);
//StageStatic.stage.solution.Add( // for reference
// new ListFact(calc.Result_FuncCall_Id.ToArray(), null, new OMS("Tuple((txt)x(t->t^)x(t^->fact))"), StageStatic.stage.solution),
// out bool _, true, null, null
//);
StageStatic.stage.solution.ExposedSolutionFacts.AddRange(calc.Result_FuncCall_Id);
//string attacheFactURI = StageStatic.stage.solution.Add(
// new AttachedPositionFunction(BallURI, calc.Result_FuncCall_Id.ToArray(), StageStatic.stage.solution),
// out _, true, null, null);
//StageStatic.stage.solution.ExposedSolutionFacts.Add(attacheFactURI);
//StageStatic.stage.solution.ValidationSet =
// new List<SolutionOrganizer.SubSolution> {
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineFactHightDirectionComparer()),
// new SolutionOrganizer.SubSolution(new HashSet<string> { target_Id }, null, null, new LineSpanningOverRiverWorldComparer()),
// new SolutionOrganizer.SubSolution(null, new List<int> { 1 }, new List<int> { 0 }, new LineFactHightComparer()),
// };
// Set Gadgets/ Scrolls
StageStatic.stage.AllowedGadgets = null;
StageStatic.stage.AllowedScrolls = new() { MMTConstants.ScrollCannonBall3D, MMTConstants.ScrollCannonBallT3D };
StageStatic.stage.solution.ScrollOverwrites.Add(MMTConstants.ScrollCannonBall3D, new[] {
(BallURI, 0, true),
(VecURI, 1, true),
(GravURI, 2, true),
(BounceURI, 3, true),
(QuadURI, 4, true),
});
StageStatic.stage.solution.ScrollOverwrites.Add(MMTConstants.ScrollCannonBallT3D, new[] {
(BallURI, 0, true),
(VecURI, 1, true),
(GravURI, 2, true),
(BounceURI, 3, true),
(TriangleURI, 4, true),
});
// Save
StageStatic.SetMode(StageStatic.Mode.Create);
StageStatic.stage.store(false, true);
}