//calculates the final layout public void prebake() { //Random.seed = 950847977; //Debug.Log("Rand seed for prebake is " + Random.seed); isAnimating = false; Entity.currentStep = 0; root = new Entity(-1, new Vector3(), new RotationAroundPoint(), 0); //Profile.StartProfile("Add entities"); int datasetId = 0; var dataInfo = SceneManager.Get.DatasetInformation[datasetId]; //Debug.Log("begin: " + dataInfo.BeginInstanceID); //Debug.Log("end: " + dataInfo.EndInstanceID); //Debug.Log("count: " + dataInfo.NumInstances); int totalNumAtomsCalculated = 0; //for (int index = dataInfo.BeginInstanceID; index < dataInfo.EndInstanceID; index++) for (int index = 0; index < SceneManager.Get.NumProteinInstances; index++) { totalNumAtomsCalculated += SceneManager.Get.ProteinAtomCount[(int)SceneManager.Get.ProteinInstanceInfos[index].x]; root.entities.Add(new Entity(index, new Vector3(SceneManager.Get.ProteinInstancePositions[index].x, SceneManager.Get.ProteinInstancePositions[index].y, SceneManager.Get.ProteinInstancePositions[index].z), new RotationAroundPoint(new Quaternion(SceneManager.Get.ProteinInstanceRotations[index].x, SceneManager.Get.ProteinInstanceRotations[index].y, SceneManager.Get.ProteinInstanceRotations[index].z, SceneManager.Get.ProteinInstanceRotations[index].w)), SceneManager.Get.ProteinRadii[(int)SceneManager.Get.ProteinInstanceInfos[index].x])); } //Debug.Log("total atom count: " + totalNumAtomsCalculated); //Profile.EndProfile("Add entities"); int numFrames = LayoutParams.Get.fps * LayoutParams.Get.duration; timeScale = 1.0f / (float)(numFrames - 1); root.calculateBoundingBox(); //calculate atom density int totalNumAtoms = 63290698; //#warning: hardcoded TODO: generate dynamically float rootVolume = (root.boundingBoxD * root.boundingBoxH * root.boundingBoxW); atomDensity = rootVolume / (float)totalNumAtoms; Debug.Log("Atom Density = " + atomDensity); //useNodeEditor = true; //node stuff starts here if (NodeGraph.Instance != null && LayoutParams.Get.useVisualEditor) { Debug.Log("loaded: " + NodeGraph.Instance); NodeGraph.Instance.evaluateNodes(NodeGraph.Instance.selectedNodes[0], null); //root.splitIntoTypes(); //root.setStageRecursive(0); //foreach (var e in root.entities) //{ // PartialLayout.layout(e, 1); //} } else Debug.Log("null"); //int testi = NodeGraph.Instance.selectedNodes.Count; if (!LayoutParams.Get.useVisualEditor) { #region layouts /*root.splitInHalf(23); root.entities[1].splitInHalf(26); SchematicLayout.radiusIndex = 1.0f; SchematicLayout.isMembrane = false; SchematicLayout.moleculeCount = 40; SchematicLayout.layout(root.entities[0], 1); root.nextStage(); SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1000; SchematicLayout.layout(root.entities[1].entities[0], 1); root.nextStage(); SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1001; SchematicLayout.layout(root.entities[1].entities[1], 1); root.nextStage();*/ if (VideoSettings.whichVideo == VideoSettings.VideoType.slice) { //root.splitInHalf(15); root.splitIntoTypes(); //root.entities[1].splitIntoTypes(); root.setStageRecursive(0); //root.entities[1].setStageRecursive(1); foreach (Entity e in root.entities) { PartialLayout.layout(e, 0); } LineLayout.layout(root, 1); root.setRotationRecursive(new RotationAroundPoint(Quaternion.identity)); root.nextStage(); /*float translateBy = 0.0f; foreach (Entity e in root.entities[0].entities) { TranslateLayout.translate = new Vector3(0.0f, 0.0f, translateBy); translateBy += e.boundingBoxD * 0.2f; foreach (Entity ee in e.entities) ee.emptyTransform(1); TranslateLayout.layout(e, 1); }*/ /*SplotionLayout.howMuch = 1000; SplotionLayout.layout(root.entities[0]);*/ /*foreach (Entity e in root.entities[1].entities) { foreach (Entity ee in e.entities) ee.emptyTransform(1); } TranslateLayout.translate = new Vector3(-1500.0f, 0.0f, 0.0f); TranslateLayout.layout(root.entities[1], 1);*/ //root.entities[1].nextStage(); /*foreach (Entity e in root.entities[1].entities) { PartialLayout.layout(e, 1); } LineLayout.layout(root.entities[1], 1);*/ //TranslateLayout.translate = new Vector3(0.0f, -3300.0f, -2700.0f); //TranslateLayout.layout(root.entities[1], 1); //root.entities[1].setRadiusRecursive(0.0f); //root.entities[1].setRotationRecursive(new RotationAroundPoint(Quaternion.identity)); //root.nextStage(); } if (VideoSettings.whichVideo == VideoSettings.VideoType.pizza) { root.splitInHalf(15); root.entities[0].planeSplitSplotionSubsets(8); root.entities[1].planeSplitSplotionSubsets(8); root.setRadiusRecursive(1.0f); root.setGammaRecursive(0.25f); foreach (Entity e in root.entities[0].entities) { foreach (Entity eq in e.entities) { Vector3 moveDir = (eq.center - root.center).normalized; Vector3 move = (eq.center + moveDir.normalized * 1000); eq.transformEntity(move, 1.0f); } } foreach (Entity e in root.entities[1].entities) { Vector3 moveDir = (e.center - root.center).normalized; Vector3 move = (e.center + moveDir.normalized * 700); e.transformEntity(move, 1.0f); } root.nextStage(); root.entities[0].setRadiusRecursive(0.0f); /*foreach (Entity e in root.entities[1].entities) { e.emptyTransform(1.0f); e.setRotation(new RotationAroundPoint(Quaternion.Euler(0, 90, 0), e.getPathAt(e.getPath().Count - 1).position * PersistantSettings.Instance.Scale)); } root.nextStage();*/ //root.entities[0].setRadiusRecursive(0.0f); //SplotionLayout.howMuch = 1000; /*foreach (Entity e in root.entities) { SplotionLayout.layout(e, 1.0f); }*/ //SplotionLayout.layout(root, 1.0f); } if (VideoSettings.whichVideo == VideoSettings.VideoType.schema) { //schematization mature root.splitInHalf(15); root.entities[1].splitInHalf(35); root.entities[1].entities[1].splitInHalf(36); //0 - 15 SchematicLayout.radiusIndex = 1.0f; SchematicLayout.isMembrane = false; SchematicLayout.moleculeCount = 16; SchematicLayout.layout(root.entities[0], 1); root.nextStage(); //16 - 34 SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1000; SchematicLayout.layout(root.entities[1].entities[0], 1); root.nextStage(); //35 - 35 SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1001; SchematicLayout.layout(root.entities[1].entities[1].entities[0], 1); root.nextStage(); //36 - ... SchematicLayout.radiusIndex = 1.0f; SchematicLayout.isMembrane = false; SchematicLayout.moleculeCount = 10; SchematicLayout.layout(root.entities[1].entities[1].entities[1], 1); root.nextStage(); } //schematization both /*root.splitInHalfByInstanceId(SceneManager.Get.DatasetInformation[0].EndInstanceID); root.entities[0].splitInHalf(25); root.entities[0].entities[1].splitInHalf(35); root.entities[0].entities[1].entities[1].splitInHalf(40); SchematicLayout.radiusIndex = 1.0f; SchematicLayout.isMembrane = false; SchematicLayout.moleculeCount = 40; SchematicLayout.layout(root.entities[0].entities[0], 1); root.entities[0].nextStage(); SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1000; SchematicLayout.layout(root.entities[0].entities[1].entities[0], 1); root.entities[0].nextStage(); SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1001; SchematicLayout.layout(root.entities[0].entities[1].entities[1].entities[0], 1); root.entities[0].nextStage(); SchematicLayout.radiusIndex = 1.0f; SchematicLayout.isMembrane = false; SchematicLayout.moleculeCount = 10; SchematicLayout.layout(root.entities[0].entities[1].entities[1].entities[1], 1); root.entities[0].nextStage();*/ //fancy explosion /*root.planeSplitSplotionSubsets(2, Vector3.zero, 0); root.entities[0].splitIntoTypes(); root.entities[1].splitIntoTypes(); BarLayout.layout(root, 0.0f); //root.setRadiusRecursive(1.0f); //root.setRotationRecursive(Quaternion.identity); root.nextStage();*/ /*root.entities[1].splitInHalf(23); root.entities[1].entities[1].splitInHalf(26); SchematicLayout.radiusIndex = 1.0f; SchematicLayout.isMembrane = false; SchematicLayout.moleculeCount = 40; SchematicLayout.layout(root.entities[1].entities[0], 1); root.entities[1].nextStage(); SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1000; SchematicLayout.layout(root.entities[1].entities[1].entities[0], 1); root.entities[1].nextStage(); SchematicLayout.radiusIndex = 0.0f; SchematicLayout.isMembrane = true; SchematicLayout.moleculeCount = 1001; SchematicLayout.layout(root.entities[1].entities[1].entities[1], 1); root.entities[1].nextStage(); root.nextStage(); */ //histogram filling /*foreach (Entity e in root.entities) { e.transformEntity(new Vector3( e.center.x, e.center.y, e.center.z ), 0.01f); }*/ if (VideoSettings.whichVideo == VideoSettings.VideoType.explosion) { TranslateLayout.center(root, 1); //debugging splitIntoCompartments() //root.splitIntoCompartments(); //.................................... root.splitInHalf(15); root.entities[1].splitInHalf(35); root.entities[1].entities[1].splitInHalf(36); ExplosionLayout.moleculeCount = 500; ExplosionLayout.layout(root.entities[0], 1.0f); ExplosionLayout.moleculeCount = 100; ExplosionLayout.layout(root.entities[1].entities[0], 1.0f); ExplosionLayout.moleculeCount = 30; ExplosionLayout.layout(root.entities[1].entities[1].entities[0], 1.0f); root.entities[0].planeSplitSplotionSubsets(2, Vector3.zero, 0); root.entities[1].entities[0].planeSplitSplotionSubsets(2, Vector3.zero, 0); root.entities[1].entities[1].entities[0].planeSplitSplotionSubsets(2, Vector3.zero, 0); root.nextStage(); root.entities[0].entities[0].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[0].boundingBoxD*1.2f))); root.entities[0].entities[1].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(-1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[1].boundingBoxD*1.2f))); root.nextStage(); TranslateLayout.translate = new Vector3(-2500.0f, 0.0f, 0.0f); TranslateLayout.layout(root.entities[1], 1.0f); root.nextStage(); root.entities[1].entities[0].entities[0].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[0].boundingBoxD))); root.entities[1].entities[0].entities[1].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(-1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[1].boundingBoxD))); TranslateLayout.translate = new Vector3(-2500.0f, 0.0f, 0.0f); TranslateLayout.layout(root.entities[1].entities[1], 1.0f); root.nextStage(); root.entities[1].entities[1].entities[0].entities[0].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[0].boundingBoxD))); root.entities[1].entities[1].entities[0].entities[1].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(-1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[1].boundingBoxD))); root.nextStage(); //root.setRotationRecursive(Quaternion.identity); //root.setRadiusRecursive(0.0f); /*ExplosionLayout.layout(root.entities[1].entities[0], 1.0f); ExplosionLayout.layout(root.entities[1].entities[1].entities[0], 1.0f);*/ //ExplosionLayout.layout(root.entities[1].entities[1].entities[1], 1.0f); //foreach (Entity e in root.entities[0].entities) //{ //ExplosionLayout.layout(root.entities[0], 1.0f); //PartialLayout.layout(e, 1); //e.nextStage(); //} //root.entities[0].markRecursive(); } if (VideoSettings.whichVideo == VideoSettings.VideoType.infovis) { //nice histograms root.splitInHalf(15); root.entities[0].splitIntoTypes(); root.entities[1].splitIntoTypes(); root.nextStage(); int cnt = 0; foreach (Entity e in root.entities[1].entities) { e.calculateAverageDistanceFromTheCenter(); BarLayout.layout(e, 1); TranslateLayout.translate = new Vector3(0.0f, -3300.0f, -2700.0f + (float)cnt * 200.0f); TranslateLayout.layout(e, 1); e.setRadiusRecursive(0.0f); e.setRotationRecursive(new RotationAroundPoint(Quaternion.identity)); cnt++; } root.nextStage(); //root.entities[1].entities.Sort(delegate (Entity x, Entity y) //{ // return (int)(y.averageDistanceFromTheCenter - x.averageDistanceFromTheCenter); //}); //for (int i = 0; i < root.entities[1].entities.Count; i++) //{ // foreach (Entity e in root.entities[1].entities[i].entities) // { // e.stage = i; // } //} /*Entity[] qe = new Entity[3]; qe[0] = root.entities[0]; qe[1] = root.entities[1].entities[0]; qe[2] = root.entities[1].entities[1]; for (int i = 0; i < 3; i++) { foreach (Entity e in qe[i].entities) { BarLayout.layout(e, 1); } LineLayout.layout(qe[i], 1); TranslateLayout.translate = new Vector3((float) i*500.0f, -3300.0f, -2700.0f); TranslateLayout.layout(qe[i], 1); qe[i].setRadiusRecursive(0.0f); qe[i].setRotationRecursive(new RotationAroundPoint(Quaternion.identity)); root.nextStage(); }*/ } //NodeGraph._instance.iterate(); //NodeGraph._instance.nodes[0]. if (VideoSettings.whichVideo == VideoSettings.VideoType.whoop) { //ivan's explosion //ExplosionLayout.layout(root, 1.0f); foreach (Entity e in root.entities) { e.transformEntity(new Vector3( e.center.x, e.center.y, e.center.z ), 1.0f); } root.splitInHalf(15); root.entities[1].splitInHalf(35); root.entities[0].planeSplitSplotionSubsets(2, Vector3.zero, 0); root.entities[1].entities[0].planeSplitSplotionSubsets(2, Vector3.zero, 0); root.entities[1].entities[1].splitIntoTypes(); root.entities[0].setStageRecursive(0); root.entities[1].entities[0].setStageRecursive(1); root.entities[1].entities[1].setStageRecursive(2); root.nextStage(); /*root.entities[0].entities[0].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[0].boundingBoxD * 1.2f))); root.entities[0].entities[1].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(45, new Vector3(-1.0f, 0.0f, 0.0f)), new Vector3(0.0f, 0.0f, root.entities[1].boundingBoxD * 1.2f)));*/ root.entities[0].entities[0].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(90, new Vector3(0.0f, 0.0f, 1.0f)), new Vector3(-700.0f, 0.0f, 0.0f))); root.entities[0].entities[1].setRotation( new RotationAroundPoint(Quaternion.AngleAxis(-90, new Vector3(0.0f, 0.0f, 1.0f)), new Vector3(-700.0f, 0.0f, 0.0f))); //root.nextStage(); root.entities[1].entities[0].setGammaRecursive(3.0f); foreach (Entity e in root.entities[1].entities[0].entities[0].entities) e.emptyTransform(1.0f); TranslateLayout.translate = new Vector3(0.0f, -800.0f, 0.0f); TranslateLayout.layout(root.entities[1].entities[0].entities[0], 1.0f); root.entities[1].entities[0].entities[0].setGammaRecursive(4.0f); foreach (Entity e in root.entities[1].entities[0].entities[1].entities) e.emptyTransform(1.0f); TranslateLayout.translate = new Vector3(0.0f, 800.0f, 0.0f); TranslateLayout.layout(root.entities[1].entities[0].entities[1], 1.0f); root.entities[1].entities[0].entities[1].setGammaRecursive(4.0f); //root.nextStage(); //root.entities[1].entities[1].setGammaRecursive(3.0f); float i = 0.0f; foreach (Entity e in root.entities[1].entities[1].entities) { float r = e.entities.Count; SphericalLayout.layout(e, 1.0f); TranslateLayout.translate = new Vector3(0.0f, 0.0f, -1200.0f + i); TranslateLayout.layout(e, 1.0f); i+= e.boundingBoxW; } //root.entities[1].entities[1].setGamma2Recursive(40.0f, 1.0f / 40.0f); /*TranslateLayout.translate = new Vector3(0.0f, 0.0f, -1200.0f); TranslateLayout.layout(root.entities[1].entities[1], 1.0f); LineLayout.layout(root.entities[1].entities[1], 1.0f);*/ /*root.entities[1].entities[1].emptyTransform(2.0f); root.entities[1].entities[1].setRotation(new RotationAroundPoint(Quaternion.AngleAxis(270, new Vector3(0.0f, 1.0f, 0.0f))));*/ root.nextStage(); } /* string[] lines = layoutScript.Split('\n'); foreach (string line in lines) { string[] parts = new string[2]; parts = line.Split(new char[] { ' ' }, 2); string command = ""; string[] p = new string[0]; float[] f = new float[0]; if (parts.Length > 1) { string[] subparts = parts[1].Split(new char[] { ' ' }, 2); if (subparts.Length > 0) { command = subparts[0]; } if (subparts.Length > 1) { p = subparts[1].Split(' '); f = new float[p.Length]; for (int i = 0; i < p.Length; i++) { f[i] = float.Parse(p[i]); } } } Debug.Log(parts[0] + "~" + command); if (parts[0] == "root") { executeLayout(root, command, f); } else if (parts[0] == "root.entities") { foreach (Entity e in root.entities) { executeLayout(e, command, f); } } } */ /*root.splitIntoTypes(); foreach (Entity e in root.entities) { BarLayout.layout(e, 1); //PartialLayout.layout(e, 1); //e.nextStage(); } LineLayout.layout(root, 1); foreach (Entity e in root.entities[1].entities) { BarLayout.layout(e, 1); //PartialLayout.layout(e, 1); //e.nextStage(); } LineLayout.layout(root.entities[1], 1); root.nextStage();*/ //root.planeSplitSplotionSubsets(4, new Vector3(0.0f, 0.0f, 0.0f)); //root.nextStage(); //SplotionLayout.layout(root, 1); //root.nextStage(); //root.createSpatialSubset(); //SplotionLayout.layout(root, 1); //root.nextStage(); ////TranslateLayout.translate = new Vector3(0.0f, 0.0f, 700.0f); ////TranslateLayout.layout(root.entities[0],1); //root.entities[0].splitIntoTypes(); //root.entities[1].splitIntoTypes(); #endregion } baked = new BakedTrannimation(root, 1, 1, false); upload = baked.frames[0].positions.ToArray(); uploadRadii = baked.frames[0].radii.ToArray(); uploadRotations = baked.frames[0].rotations.ToArray(); GPUBuffers.Instance.ProteinAnimationPositions.SetData(upload); GPUBuffers.Instance.ProteinAnimationRotations.SetData(uploadRotations); }
private void executeLayout(Entity e, string command, float [] p) { if (command == "splitintotypes") { e.splitIntoTypes(); } else if (command == "splitinhalf") { e.splitInHalf((int)p[0]); } else if (command == "next") { e.nextStage(); } else if (command == "bar") { BarLayout.layout(e, p[0]); } else if (command == "circular") { CircularLayout.layout(e, p[0]); } else if (command == "line") { LineLayout.layout(e, p[0]); } else if (command == "partial") { PartialLayout.layout(e, p[0]); } else if (command == "slice") { SliceLayout.layout(e, p[0]); } else if (command == "spherical") { SphericalLayout.layout(e, p[0]); } else if (command == "sphericalslice") { SphericalSliceLayout.layout(e, p[0]); } else if (command == "splotion") { SplotionLayout.layout(e, p[0]); } else if (command == "translate") { TranslateLayout.translate = new Vector3(p[1], p[2], p[3]); TranslateLayout.layout(e, p[0]); } else if (command == "distance") { //DistanceLayout.layout(e, p[0]); } }