public override Module GetModule() { int octaves = 2 + (int)Mathf.Log(_height, 2); var clouds = new Perlin() { Seed = _seed, Frequency = _frequency, Persistence = 0.5f, Lacunarity = _lacunarity, OctaveCount = octaves, }; var displacement = new ScalePoint() { Source0 = clouds, XScale = _spin, YScale = 1f, ZScale = _spin, }; var turbulence = new Turbulence() { Source0 = displacement, //Seed = rng.Next(), Frequency = 2, Power = 0.7f, Roughness = 2 }; return(turbulence); }
public CavesCarver() : base() { var stretched = new Curve { ControlPoints = new List <ControlPoint>() { new Curve.ControlPoint(-1, -1), new Curve.ControlPoint(-0.7, -0.5), new Curve.ControlPoint(-0.4, -0.5), new Curve.ControlPoint(1, 1), }, Source0 = new Billow { Frequency = 18.12345, Seed = settings.Seed + 1, Quality = SharpNoise.NoiseQuality.Fast, OctaveCount = 6, Lacunarity = 1.2234, Persistence = 1.23 } }; result = new ScalePoint { XScale = 1 / 1024.0, YScale = 1 / 384.0, ZScale = 1 / 1024.0, Source0 = stretched }; }
private void SetUpRidgedMultiFractal3DModule() { // make a 3d ridged multifractal module PrimitiveModule pModule = null; pModule = new SimplexPerlin(); primitiveModule = pModule; pModule.Seed = 123; ScaleBias scale = null; filterModule = new Billow(); // new RidgedMultiFractal(); //new Pipe(); // filterModule.Primitive3D = (IModule3D)pModule; // Used to show the difference with our gradient color (-1 + 1) scale = new ScaleBias(filterModule, 1f, 0f); // 0.9f, -1.25f); float rmfScale = .75f; ScalePoint scalePoint = new ScalePoint(filterModule, rmfScale, rmfScale * 1f, rmfScale); noiseModule = scalePoint; // scale; }
public static T[,] CreateTileDistribution <T>(int width, int height, float scale, float coverage) { T[,] output = new T[width, height]; //generate noise ImprovedPerlin perlin = new ImprovedPerlin(); MultiFractal fractal = new MultiFractal(); fractal.Primitive2D = perlin; fractal.Primitive3D = perlin; //scale the noise ScalePoint scaledNoise = new ScalePoint(fractal, scale, scale, scale); //create output distribution map from scaled noise + coverage for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float val = scaledNoise.GetValue(x, y, 0.1f); if (val < coverage) { output[x, y] = (T)Activator.CreateInstance(typeof(T)); } } } return(output); }
// Generates the plains terrain. // Outputs will be between -0.3 and -0.1 public RiverTerrain() : base() { result = new ScalePoint() { XScale = 4.0, ZScale = 4.0, Source0 = new ScaleBias() { Bias = -0.05, Scale = 0.2, Source0 = new PlainsTerrain() } }; }
private void SetUpAltNoise2D() { PrimitiveModule pModule2D = new SimplexPerlin(); pModule2D.Seed = primitiveModule.Seed + 6789; altFilterModule = new Pipe(); // RidgedMultiFractal(); altFilterModule.Primitive3D = (IModule3D)pModule2D; float alt_module_scale = 2.4f; ScalePoint scalePoint_alt = new ScalePoint(altFilterModule, alt_module_scale, alt_module_scale, alt_module_scale); altNoise2DModule = (IModule3D)scalePoint_alt; }
public void ScalePointTest() { double x = 1D, y = 2D, z = 3D; double scaleX = 1D, scaleY = 2D, scaleZ = 3D; var source = new Perlin(); var module = new ScalePoint() { Source0 = source, XScale = scaleX, YScale = scaleY, ZScale = scaleZ }; Assert.AreEqual(source.GetValue(x * scaleX, y * scaleY, z * scaleZ), module.GetValue(x, y, z)); }
private void SetUpNoise2D() { //noise character should vary PrimitiveModule pModule2D = new SimplexPerlin(); // new ImprovedPerlin(); // pModule2D.Seed = primitiveModule.Seed + 1234; // noise2DModule = (IModule3D) pModule2D; FilterModule fModule = new SumFractal(); // new Billow(); // fModule.Primitive3D = (IModule3D)pModule2D; float rmfScale = .2f; ScalePoint scalePoint = new ScalePoint(fModule, rmfScale, rmfScale, rmfScale); noise2DModule = (IModule3D)scalePoint; }
private SimpleMatrix GetAdjustment(ScalePoint point, int level, int x, int y, out double dp) { dp = 0.0; if (point.Level <= 0 || point.Level >= (spaces.Length - 1)) { throw (new ArgumentException("point.Level is not within [bottom-1;top-1] range")); } ImageMap below = spaces[level - 1]; ImageMap current = spaces[level]; ImageMap above = spaces[level + 1]; SimpleMatrix H = new SimpleMatrix(3, 3); H[0, 0] = below[x, y] - 2 * current[x, y] + above[x, y]; H[0, 1] = H[1, 0] = 0.25 * (above[x, y + 1] - above[x, y - 1] - (below[x, y + 1] - below[x, y - 1])); H[0, 2] = H[2, 0] = 0.25 * (above[x + 1, y] - above[x - 1, y] - (below[x + 1, y] - below[x - 1, y])); H[1, 1] = current[x, y - 1] - 2 * current[x, y] + current[x, y + 1]; H[1, 2] = H[2, 1] = 0.25 * (current[x + 1, y + 1] - current[x - 1, y + 1] - (current[x + 1, y - 1] - current[x - 1, y - 1])); H[2, 2] = current[x - 1, y] - 2 * current[x, y] + current[x + 1, y]; SimpleMatrix d = new SimpleMatrix(3, 1); d[0, 0] = 0.5 * (above[x, y] - below[x, y]); d[1, 0] = 0.5 * (current[x, y + 1] - current[x, y - 1]); d[2, 0] = 0.5 * (current[x + 1, y] - current[x - 1, y]); SimpleMatrix b = (SimpleMatrix)d.Clone(); b.Negate(); H.SolveLinear(b); dp = b.Dot(d); return(b); }
/// <summary> /// Конструктор. /// </summary> /// <param name="parent">План.</param> /// <param name="image">Изображение.</param> /// <param name="sign">Идентификатор.</param> /// <param name="size">Размер.</param> /// <param name="scalePoint">Относительная точка.</param> /// <param name="textLabel">Текст под иконкой.</param> public IconOnPlan(Plan parent, EntitySign sign, Size size, ScalePoint scalePoint, Image image, string textLabel) { Sign = sign; Parent = parent; this.scalePoint = scalePoint; Image = image; Size = size; BorderStyle = BorderStyle.FixedSingle; SizeMode = PictureBoxSizeMode.Zoom; Left = (int)(scalePoint.PercentLeft * parent.Width); Top = (int)(scalePoint.PercentTop * parent.Height); BringToFront(); MouseDown += Icon_DragDropMove; MouseMove += Icon_MouseMove; MouseClick += Icon_MouseClick; MouseDoubleClick += new MouseEventHandler((s2, e2) => Dialogs.EditDialog(sign)); Resize += (s, e) => LabelRedraw(); Move += (s, e) => LabelRedraw(); LabelInit(textLabel); }
public void ScalePointTest(double sx, double sy, double sz) { var source = new Perlin(); var module = new ScalePoint { XScale = sx, YScale = sy, ZScale = sz, Source0 = source, }; for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { for (int z = -1; z < 2; z++) { var expected = source.GetValue(x * sx, y * sy, z * sz); var actual = module.GetValue(x, y, z); Assert.Equal(expected, actual); } } } }
private ArrayList GenerateKeypointSingle(double imgScale, ScalePoint point, int binCount, double peakRelThresh, int scaleCount, double octaveSigma) { double kpScale = octaveSigma * Math.Pow(2.0, (point.Level + point.Local.ScaleAdjust) / scaleCount); double sigma = 3.0 * kpScale; int radius = (int)(3.0 * sigma / 2.0 + 0.5); int radiusSq = radius * radius; ImageMap magnitude = magnitudes[point.Level]; ImageMap direction = directions[point.Level]; int xMin = Math.Max(point.X - radius, 1); int xMax = Math.Min(point.X + radius, magnitude.XDim - 1); int yMin = Math.Max(point.Y - radius, 1); int yMax = Math.Min(point.Y + radius, magnitude.YDim - 1); double gaussianSigmaFactor = 2.0 * sigma * sigma; double[] bins = new double[binCount]; for (int y = yMin; y < yMax; ++y) { for (int x = xMin; x < xMax; ++x) { int relX = x - point.X; int relY = y - point.Y; if (IsInCircle(relX, relY, radiusSq) == false) { continue; } double gaussianWeight = Math.Exp (-((relX * relX + relY * relY) / gaussianSigmaFactor)); int binIdx = FindClosestRotationBin(binCount, direction[x, y]); bins[binIdx] += magnitude[x, y] * gaussianWeight; } } AverageWeakBins(bins, binCount); double maxGrad = 0.0; int maxBin = 0; for (int b = 0; b < binCount; ++b) { if (bins[b] > maxGrad) { maxGrad = bins[b]; maxBin = b; } } double maxPeakValue, maxDegreeCorrection; InterpolateOrientation(bins[maxBin == 0 ? (binCount - 1) : (maxBin - 1)], bins[maxBin], bins[(maxBin + 1) % binCount], out maxDegreeCorrection, out maxPeakValue); bool[] binIsKeypoint = new bool[binCount]; for (int b = 0; b < binCount; ++b) { binIsKeypoint[b] = false; if (b == maxBin) { binIsKeypoint[b] = true; continue; } if (bins[b] < (peakRelThresh * maxPeakValue)) { continue; } int leftI = (b == 0) ? (binCount - 1) : (b - 1); int rightI = (b + 1) % binCount; if (bins[b] <= bins[leftI] || bins[b] <= bins[rightI]) { continue; } binIsKeypoint[b] = true; } ArrayList keypoints = new ArrayList(); double oneBinRad = (2.0 * Math.PI) / binCount; for (int b = 0; b < binCount; ++b) { if (binIsKeypoint[b] == false) { continue; } int bLeft = (b == 0) ? (binCount - 1) : (b - 1); int bRight = (b + 1) % binCount; double peakValue; double degreeCorrection; if (InterpolateOrientation(bins[bLeft], bins[b], bins[bRight], out degreeCorrection, out peakValue) == false) { throw (new InvalidOperationException("BUG: Parabola fitting broken")); } double degree = (b + degreeCorrection) * oneBinRad - Math.PI; if (degree < -Math.PI) { degree += 2.0 * Math.PI; } else if (degree > Math.PI) { degree -= 2.0 * Math.PI; } Keypoint kp = new Keypoint(imgScaled[point.Level], point.X + point.Local.FineX, point.Y + point.Local.FineY, imgScale, kpScale, degree); keypoints.Add(kp); } return(keypoints); }
public static List<BoneCurves> Load(string file) { Debug.Log("loading"); List<BoneCurves> BClist = new List<BoneCurves>(); XmlDocument doc = new XmlDocument(); doc.Load(file); string curvetype = ""; XmlNode BoneData = doc.SelectSingleNode("AnimeName/BoneData"); foreach (XmlNode Bone in BoneData.ChildNodes) { int keyvalue = 0; BoneCurves BC = new BoneCurves { name = Bone.Attributes["Text"].Value }; //Debug.Log(Bone.Name); XmlNodeList childs = Bone.ChildNodes; for (int i = 0; i < childs.Count; i++) { switch (childs[i].Name) { case "RotateKey": curvetype = "RotateKey"; break; case "ScaleKey": curvetype = "Scalekey"; break; case "PosKey": curvetype = "PosKey"; break; case "Time": switch (curvetype) { case "RotateKey": RotPoint RP = new RotPoint(); RP.Frame = int.Parse(childs[i].Attributes["Value"].Value); XmlNode Rota = childs[i].ChildNodes[0]; RP.Value = new Quaternion(float.Parse(Rota.Attributes["x"].Value), float.Parse(Rota.Attributes["y"].Value), float.Parse(Rota.Attributes["z"].Value), float.Parse(Rota.Attributes["w"].Value)); RP.calctype = int.Parse(childs[i].ChildNodes[1].Attributes["Value"].Value); if (RP.calctype == 1) RP.PowVal = int.Parse(childs[i].ChildNodes[2].Attributes["Value"].Value); BC.RotCurve.Add(RP); break; case "ScaleKey": ScalePoint SP = new ScalePoint(); SP.Frame = int.Parse(childs[i].Attributes["Value"].Value); XmlNode Scale = childs[i].ChildNodes[0]; SP.Value = new Vector3(float.Parse(Scale.Attributes["x"].Value), float.Parse(Scale.Attributes["y"].Value), float.Parse(Scale.Attributes["z"].Value)); SP.calctype = int.Parse(childs[i].ChildNodes[1].Attributes["Value"].Value); if (SP.calctype == 1) SP.PowVal = int.Parse(childs[i].ChildNodes[2].Attributes["Value"].Value); BC.ScaleCurve.Add(SP); break; case "PosKey": PosPoint PP = new PosPoint(); PP.Frame = int.Parse(childs[i].Attributes["Value"].Value); XmlNode Pos = childs[i].ChildNodes[0]; PP.Value = new Vector3(float.Parse(Pos.Attributes["x"].Value), float.Parse(Pos.Attributes["y"].Value), float.Parse(Pos.Attributes["z"].Value)); PP.calctype = int.Parse(childs[i].ChildNodes[1].Attributes["Value"].Value); if (PP.calctype == 1) PP.PowVal = int.Parse(childs[i].ChildNodes[2].Attributes["Value"].Value); BC.PosCurve.Add(PP); break; } break; } } BClist.Add(BC); } return BClist; }
private void HandleGraphGUIEvents() { //mouse drag event handling. switch (Event.current.type) { // draw line while dragging. case EventType.MouseDrag: { switch (modifyMode) { case ModifyMode.NONE: { switch (Event.current.button) { case 0:{// left click if (Event.current.command) { scalePoint = new ScalePoint(Event.current.mousePosition, NodeGUI.scaleFactor, 0); modifyMode = ModifyMode.SCALING; break; } selection = new AssetBundleGraphSelection(Event.current.mousePosition); modifyMode = ModifyMode.SELECTING; break; } case 2:{// middle click. scalePoint = new ScalePoint(Event.current.mousePosition, NodeGUI.scaleFactor, 0); modifyMode = ModifyMode.SCALING; break; } } break; } case ModifyMode.SELECTING: { // do nothing. break; } case ModifyMode.SCALING: { var baseDistance = (int)Vector2.Distance(Event.current.mousePosition, new Vector2(scalePoint.x, scalePoint.y)); var distance = baseDistance / NodeGUI.SCALE_WIDTH; var direction = (0 < Event.current.mousePosition.y - scalePoint.y); if (!direction) distance = -distance; // var before = NodeGUI.scaleFactor; NodeGUI.scaleFactor = scalePoint.startScale + (distance * NodeGUI.SCALE_RATIO); if (NodeGUI.scaleFactor < NodeGUI.SCALE_MIN) NodeGUI.scaleFactor = NodeGUI.SCALE_MIN; if (NodeGUI.SCALE_MAX < NodeGUI.scaleFactor) NodeGUI.scaleFactor = NodeGUI.SCALE_MAX; break; } } HandleUtility.Repaint(); Event.current.Use(); break; } } // mouse up event handling. // use rawType for detect for detectiong mouse-up which raises outside of window. switch (Event.current.rawType) { case EventType.MouseUp: { switch (modifyMode) { /* select contained nodes & connections. */ case ModifyMode.SELECTING: { var x = 0f; var y = 0f; var width = 0f; var height = 0f; if (Event.current.mousePosition.x < selection.x) { x = Event.current.mousePosition.x; width = selection.x - Event.current.mousePosition.x; } if (selection.x < Event.current.mousePosition.x) { x = selection.x; width = Event.current.mousePosition.x - selection.x; } if (Event.current.mousePosition.y < selection.y) { y = Event.current.mousePosition.y; height = selection.y - Event.current.mousePosition.y; } if (selection.y < Event.current.mousePosition.y) { y = selection.y; height = Event.current.mousePosition.y - selection.y; } var activeObjectIds = new List<string>(); var selectedRect = new Rect(x, y, width, height); foreach (var node in nodes) { var nodeRect = new Rect(node.GetRect()); nodeRect.x = nodeRect.x * NodeGUI.scaleFactor; nodeRect.y = nodeRect.y * NodeGUI.scaleFactor; nodeRect.width = nodeRect.width * NodeGUI.scaleFactor; nodeRect.height = nodeRect.height * NodeGUI.scaleFactor; // get containd nodes, if (nodeRect.Overlaps(selectedRect)) { activeObjectIds.Add(node.Id); } } foreach (var connection in connections) { // get contained connection badge. if (connection.GetRect().Overlaps(selectedRect)) { activeObjectIds.Add(connection.Id); } } if (Event.current.shift) { // add current active object ids to new list. foreach (var alreadySelectedObjectId in activeObject.idPosDict.ReadonlyDict().Keys) { if (!activeObjectIds.Contains(alreadySelectedObjectId)) activeObjectIds.Add(alreadySelectedObjectId); } } else { // do nothing, means cancel selections if nodes are not contained by selection. } Undo.RecordObject(this, "Select Objects"); activeObject = RenewActiveObject(activeObjectIds); UpdateActivationOfObjects(activeObject); selection = new AssetBundleGraphSelection(Vector2.zero); modifyMode = ModifyMode.NONE; HandleUtility.Repaint(); Event.current.Use(); break; } case ModifyMode.SCALING: { modifyMode = ModifyMode.NONE; break; } } break; } } }
private bool LocalizeIsWeak(ScalePoint point, int steps, int[,] processed) { bool needToAdjust = true; int adjusted = steps; while (needToAdjust) { int x = point.X; int y = point.Y; if (point.Level <= 0 || point.Level >= (spaces.Length - 1)) { return(true); } ImageMap space = spaces[point.Level]; if (x <= 0 || x >= (space.XDim - 1)) { return(true); } if (y <= 0 || y >= (space.YDim - 1)) { return(true); } double dp; SimpleMatrix adj = GetAdjustment(point, point.Level, x, y, out dp); double adjS = adj[0, 0]; double adjY = adj[1, 0]; double adjX = adj[2, 0]; if (Math.Abs(adjX) > 0.5 || Math.Abs(adjY) > 0.5) { if (adjusted == 0) { return(true); } adjusted -= 1; double distSq = adjX * adjX + adjY * adjY; if (distSq > 2.0) { return(true); } point.X = (int)(point.X + adjX + 0.5); point.Y = (int)(point.Y + adjY + 0.5); continue; } if (processed[point.X, point.Y] != 0) { return(true); } processed[point.X, point.Y] = 1; PointLocalInformation local = new PointLocalInformation(adjS, adjX, adjY); local.DValue = space[point.X, point.Y] + 0.5 * dp; point.Local = local; needToAdjust = false; } return(false); }
public void OnGUI() { using (new EditorGUILayout.HorizontalScope(GUI.skin.box)) { if (GUILayout.Button(reloadButtonTexture, GUILayout.Height(18))) { Setup(); } if (GUILayout.Button("Build (active build target is " + EditorUserBuildSettings.activeBuildTarget + ")", GUILayout.Height(18))) { Run(); } } /* scroll view. */ // var scaledScrollPos = Node.ScaleEffect(scrollPos); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); // scrollPos = scrollPos + (movedScrollPos - scaledScrollPos); { // draw node window x N. { BeginWindows(); nodes.ForEach(node => node.DrawNode()); EndWindows(); } // draw connection input point marks. foreach (var node in nodes) { node.DrawConnectionInputPointMark(currentEventSource, modifyMode == ModifyMode.CONNECT_STARTED); } // draw connections. foreach (var con in connections) { if (connectionThroughputs.ContainsKey(con.connectionId)) { var throughputListDict = connectionThroughputs[con.connectionId]; con.DrawConnection(nodes, throughputListDict); } else { con.DrawConnection(nodes, new Dictionary<string, List<ThroughputAsset>>()); } } // draw connection output point marks. foreach (var node in nodes) { node.DrawConnectionOutputPointMark(currentEventSource, modifyMode == ModifyMode.CONNECT_STARTED, Event.current); } /* draw connecting line if modifing connection. */ switch (modifyMode) { case ModifyMode.CONNECT_STARTED: { // from start node to mouse. DrawStraightLineFromCurrentEventSourcePointTo(Event.current.mousePosition, currentEventSource); break; } case ModifyMode.CONNECT_ENDED: { // do nothing break; } case ModifyMode.SELECTION_STARTED: { GUI.DrawTexture(new Rect(selection.x, selection.y, Event.current.mousePosition.x - selection.x, Event.current.mousePosition.y - selection.y), selectionTex); break; } } /* mouse drag event handling. */ switch (Event.current.type) { // draw line while dragging. case EventType.MouseDrag: { switch (modifyMode) { case ModifyMode.CONNECT_ENDED: { switch (Event.current.button) { case 0:{// left click if (Event.current.command) { scalePoint = new ScalePoint(Event.current.mousePosition, Node.scaleFactor, 0); modifyMode = ModifyMode.SCALING_STARTED; break; } selection = new AssetBundleGraphSelection(Event.current.mousePosition); modifyMode = ModifyMode.SELECTION_STARTED; break; } case 2:{// middle click. scalePoint = new ScalePoint(Event.current.mousePosition, Node.scaleFactor, 0); modifyMode = ModifyMode.SCALING_STARTED; break; } } break; } case ModifyMode.SELECTION_STARTED: { // do nothing. break; } case ModifyMode.SCALING_STARTED: { var baseDistance = (int)Vector2.Distance(Event.current.mousePosition, new Vector2(scalePoint.x, scalePoint.y)); var distance = baseDistance / Node.SCALE_WIDTH; var direction = (0 < Event.current.mousePosition.y - scalePoint.y); if (!direction) distance = -distance; // var before = Node.scaleFactor; Node.scaleFactor = scalePoint.startScale + (distance * Node.SCALE_RATIO); if (Node.scaleFactor < Node.SCALE_MIN) Node.scaleFactor = Node.SCALE_MIN; if (Node.SCALE_MAX < Node.scaleFactor) Node.scaleFactor = Node.SCALE_MAX; break; } } HandleUtility.Repaint(); Event.current.Use(); break; } } /* mouse up event handling. use rawType for detect for detectiong mouse-up which raises outside of window. */ switch (Event.current.rawType) { case EventType.MouseUp: { switch (modifyMode) { /* select contained nodes & connections. */ case ModifyMode.SELECTION_STARTED: { var x = 0f; var y = 0f; var width = 0f; var height = 0f; if (Event.current.mousePosition.x < selection.x) { x = Event.current.mousePosition.x; width = selection.x - Event.current.mousePosition.x; } if (selection.x < Event.current.mousePosition.x) { x = selection.x; width = Event.current.mousePosition.x - selection.x; } if (Event.current.mousePosition.y < selection.y) { y = Event.current.mousePosition.y; height = selection.y - Event.current.mousePosition.y; } if (selection.y < Event.current.mousePosition.y) { y = selection.y; height = Event.current.mousePosition.y - selection.y; } var activeObjectIds = new List<string>(); var selectedRect = new Rect(x, y, width, height); foreach (var node in nodes) { var nodeRect = new Rect(node.GetRect()); nodeRect.x = nodeRect.x * Node.scaleFactor; nodeRect.y = nodeRect.y * Node.scaleFactor; nodeRect.width = nodeRect.width * Node.scaleFactor; nodeRect.height = nodeRect.height * Node.scaleFactor; // get containd nodes, if (nodeRect.Overlaps(selectedRect)) { activeObjectIds.Add(node.nodeId); } } foreach (var connection in connections) { // get contained connection badge. if (connection.GetRect().Overlaps(selectedRect)) { activeObjectIds.Add(connection.connectionId); } } if (Event.current.shift) { // add current active object ids to new list. foreach (var alreadySelectedObjectId in activeObject.idPosDict.ReadonlyDict().Keys) { if (!activeObjectIds.Contains(alreadySelectedObjectId)) activeObjectIds.Add(alreadySelectedObjectId); } } else { // do nothing, means cancel selections if nodes are not contained by selection. } Undo.RecordObject(this, "Select Objects"); activeObject = RenewActiveObject(activeObjectIds); UpdateActivationOfObjects(activeObject); selection = new AssetBundleGraphSelection(Vector2.zero); modifyMode = ModifyMode.CONNECT_ENDED; HandleUtility.Repaint(); Event.current.Use(); break; } case ModifyMode.SCALING_STARTED: { modifyMode = ModifyMode.CONNECT_ENDED; break; } } break; } } // set rect for scroll. if (nodes.Any()) { GUILayoutUtility.GetRect(new GUIContent(string.Empty), GUIStyle.none, GUILayout.Width(spacerRectRightBottom.x), GUILayout.Height(spacerRectRightBottom.y)); } } EditorGUILayout.EndScrollView(); /* detect dragging some script into window. right click. connection end mouse up. command(Delete, Copy, and more) */ switch (Event.current.type) { // detect dragging script then change interface to "(+)" icon. case EventType.DragUpdated: { var refs = DragAndDrop.objectReferences; foreach (var refe in refs) { if (refe.GetType() == typeof(UnityEditor.MonoScript)) { var type = ((MonoScript)refe).GetClass(); var inherited = IsAcceptableScriptType(type); if (inherited != null) { // at least one asset is script. change interface. DragAndDrop.visualMode = DragAndDropVisualMode.Copy; break; } } } break; } // script drop on editor. case EventType.DragPerform: { var pathAndRefs = new Dictionary<string, object>(); for (var i = 0; i < DragAndDrop.paths.Length; i++) { var path = DragAndDrop.paths[i]; var refe = DragAndDrop.objectReferences[i]; pathAndRefs[path] = refe; } var shouldSave = false; foreach (var item in pathAndRefs) { var path = item.Key; var refe = (MonoScript)item.Value; if (refe.GetType() == typeof(UnityEditor.MonoScript)) { var type = refe.GetClass(); var inherited = IsAcceptableScriptType(type); if (inherited != null) { var dropPos = Event.current.mousePosition; var scriptName = refe.name; var scriptType = scriptName;// name = type. var scriptPath = path; AddNodeFromCode(scriptName, scriptType, scriptPath, inherited, Guid.NewGuid().ToString(), dropPos.x, dropPos.y); shouldSave = true; } } } if (shouldSave) SaveGraphWithReload(); break; } // show context menu case EventType.ContextClick: { var rightClickPos = Event.current.mousePosition; var menu = new GenericMenu(); foreach (var menuItemStr in AssetBundleGraphSettings.GUI_Menu_Item_TargetGUINodeDict.Keys) { var targetGUINodeNameStr = AssetBundleGraphSettings.GUI_Menu_Item_TargetGUINodeDict[menuItemStr]; menu.AddItem( new GUIContent(menuItemStr), false, () => { AddNodeFromGUI(string.Empty, targetGUINodeNameStr, Guid.NewGuid().ToString(), rightClickPos.x, rightClickPos.y); SaveGraphWithReload(); Repaint(); } ); } menu.ShowAsContext(); break; } /* handling mouse up -> drag released -> release modifyMode. */ case EventType.MouseUp: { modifyMode = ModifyMode.CONNECT_ENDED; HandleUtility.Repaint(); if (activeObject.idPosDict.ReadonlyDict().Any()) { Undo.RecordObject(this, "Unselect"); foreach (var activeObjectId in activeObject.idPosDict.ReadonlyDict().Keys) { // unselect all. foreach (var node in nodes) { if (activeObjectId == node.nodeId) node.SetInactive(); } foreach (var connection in connections) { if (activeObjectId == connection.connectionId) connection.SetInactive(); } } activeObject = RenewActiveObject(new List<string>()); } break; } /* scale up or down by command & + or command & -. */ case EventType.KeyDown: { if (Event.current.command) { if (Event.current.shift && Event.current.keyCode == KeyCode.Semicolon) { Node.scaleFactor = Node.scaleFactor + 0.1f; if (Node.scaleFactor < Node.SCALE_MIN) Node.scaleFactor = Node.SCALE_MIN; if (Node.SCALE_MAX < Node.scaleFactor) Node.scaleFactor = Node.SCALE_MAX; Event.current.Use(); break; } if (Event.current.keyCode == KeyCode.Minus) { Node.scaleFactor = Node.scaleFactor - 0.1f; if (Node.scaleFactor < Node.SCALE_MIN) Node.scaleFactor = Node.SCALE_MIN; if (Node.SCALE_MAX < Node.scaleFactor) Node.scaleFactor = Node.SCALE_MAX; Event.current.Use(); break; } } break; } case EventType.ValidateCommand: { switch (Event.current.commandName) { // Delete active node or connection. case "Delete": { if (!activeObject.idPosDict.ReadonlyDict().Any()) break; Undo.RecordObject(this, "Delete Selection"); foreach (var targetId in activeObject.idPosDict.ReadonlyDict().Keys) { DeleteNode(targetId); DeleteConnectionById(targetId); } SaveGraphWithReload(); InitializeGraph(); activeObject = RenewActiveObject(new List<string>()); UpdateActivationOfObjects(activeObject); Event.current.Use(); break; } case "Copy": { if (!activeObject.idPosDict.ReadonlyDict().Any()) { break; } Undo.RecordObject(this, "Copy Selection"); var targetNodeIds = activeObject.idPosDict.ReadonlyDict().Keys.ToList(); var targetNodeJsonRepresentations = JsonRepresentations(targetNodeIds); copyField = new CopyField(targetNodeJsonRepresentations, CopyType.COPYTYPE_COPY); Event.current.Use(); break; } case "Cut": { if (!activeObject.idPosDict.ReadonlyDict().Any()) { break; } Undo.RecordObject(this, "Cut Selection"); var targetNodeIds = activeObject.idPosDict.ReadonlyDict().Keys.ToList(); var targetNodeJsonRepresentations = JsonRepresentations(targetNodeIds); copyField = new CopyField(targetNodeJsonRepresentations, CopyType.COPYTYPE_CUT); foreach (var targetId in activeObject.idPosDict.ReadonlyDict().Keys) { DeleteNode(targetId); DeleteConnectionById(targetId); } SaveGraphWithReload(); InitializeGraph(); activeObject = RenewActiveObject(new List<string>()); UpdateActivationOfObjects(activeObject); Event.current.Use(); break; } case "Paste": { var nodeNames = nodes.Select(node => node.name).ToList(); var duplicatingData = new List<Node>(); if (copyField.datas.Any()) { var pasteType = copyField.type; foreach (var copyFieldData in copyField.datas) { var nodeJsonDict = Json.Deserialize(copyFieldData) as Dictionary<string, object>; var pastingNode = NodeFromJsonDict(nodes.Count, nodeJsonDict); var pastingNodeName = pastingNode.name; var nameOverlapping = nodeNames.Where(name => name == pastingNodeName).ToList(); switch (pasteType) { case CopyType.COPYTYPE_COPY: { if (2 <= nameOverlapping.Count) continue; break; } case CopyType.COPYTYPE_CUT: { if (1 <= nameOverlapping.Count) continue; break; } } duplicatingData.Add(pastingNode); } } if (!duplicatingData.Any()) break; Undo.RecordObject(this, "Paste"); foreach (var newNode in duplicatingData) { DuplicateNode(newNode); } SaveGraphWithReload(); InitializeGraph(); Event.current.Use(); break; } case "SelectAll": { Undo.RecordObject(this, "Select All Objects"); var nodeIds = nodes.Select(node => node.nodeId).ToList(); activeObject = RenewActiveObject(nodeIds); // select all. foreach (var node in nodes) { node.SetActive(); } foreach (var connection in connections) { connection.SetActive(); } Event.current.Use(); break; } default: { break; } } break; } } }
public static void Load(ref ScriptKeys sKeys, ref List<BoneCurves> rBC, string file) { Debug.Log("loading"); XmlDocument doc = new XmlDocument(); doc.Load(file); XmlNode AnimeName = doc.SelectSingleNode("AnimeName"); sKeys.AnimeName = AnimeName.Attributes["Name"].Value; sKeys.ID = int.Parse(AnimeName.Attributes["ID"].Value); foreach (XmlNode node in AnimeName.ChildNodes) { switch (node.Name) { case "Windom_TopScript": sKeys.TopScript = node.InnerText; break; case "Time": scriptKey key; key.Frame = int.Parse(node.Attributes["Value"].Value); key.script = node.FirstChild.InnerText; sKeys.SK.Add(key); break; case "BoneData": string curvetype = ""; XmlNode BoneData = node; foreach (XmlNode Bone in BoneData.ChildNodes) { BoneCurves BC = new BoneCurves { name = Bone.Attributes["Text"].Value }; //Debug.Log(Bone.Name); XmlNodeList childs = Bone.ChildNodes; for (int i = 0; i < childs.Count; i++) { switch (childs[i].Name) { case "RotateKey": curvetype = "RotateKey"; break; case "ScaleKey": curvetype = "Scalekey"; break; case "PosKey": curvetype = "PosKey"; break; case "Time": switch (curvetype) { case "RotateKey": RotPoint RP = new RotPoint(); RP.Frame = int.Parse(childs[i].Attributes["Value"].Value); XmlNode Rota = childs[i].ChildNodes[0]; RP.Value = new Quaternion(float.Parse(Rota.Attributes["x"].Value), float.Parse(Rota.Attributes["y"].Value), float.Parse(Rota.Attributes["z"].Value), float.Parse(Rota.Attributes["w"].Value)); RP.calctype = int.Parse(childs[i].ChildNodes[1].Attributes["Value"].Value); if (RP.calctype == 1) RP.PowVal = int.Parse(childs[i].ChildNodes[2].Attributes["Value"].Value); BC.RotCurve.Add(RP); break; case "ScaleKey": ScalePoint SP = new ScalePoint(); SP.Frame = int.Parse(childs[i].Attributes["Value"].Value); XmlNode Scale = childs[i].ChildNodes[0]; SP.Value = new Vector3(float.Parse(Scale.Attributes["x"].Value), float.Parse(Scale.Attributes["y"].Value), float.Parse(Scale.Attributes["z"].Value)); SP.calctype = int.Parse(childs[i].ChildNodes[1].Attributes["Value"].Value); if (SP.calctype == 1) SP.PowVal = int.Parse(childs[i].ChildNodes[2].Attributes["Value"].Value); BC.ScaleCurve.Add(SP); break; case "PosKey": PosPoint PP = new PosPoint(); PP.Frame = int.Parse(childs[i].Attributes["Value"].Value); XmlNode Pos = childs[i].ChildNodes[0]; PP.Value = new Vector3(float.Parse(Pos.Attributes["x"].Value), float.Parse(Pos.Attributes["y"].Value), float.Parse(Pos.Attributes["z"].Value)); PP.calctype = int.Parse(childs[i].ChildNodes[1].Attributes["Value"].Value); if (PP.calctype == 1) PP.PowVal = int.Parse(childs[i].ChildNodes[2].Attributes["Value"].Value); BC.PosCurve.Add(PP); break; } break; } } rBC.Add(BC); } break; } } }
public static void CreateTestModuleTree(TestContext context) { var baseWood = new Cylinders { Frequency = 16, }; var woodGrainNoise = new Perlin { Seed = 2135, Frequency = 48, Persistence = 0.5, Lacunarity = 2.20703125, OctaveCount = 3, Quality = NoiseQuality.Standard, }; var scaledBaseWoodGrain = new ScalePoint { Source0 = woodGrainNoise, YScale = 0.25, }; var woodGrain = new ScaleBias { Source0 = scaledBaseWoodGrain, Scale = 0.25, Bias = 0.125, }; var combinedWood = new Add { Source0 = baseWood, Source1 = woodGrain, }; var perturbedWood = new Turbulence { Source0 = combinedWood, Seed = 1, Frequency = 4, Power = 1.0 / 256.0, Roughness = 4, }; var translatedWood = new TranslatePoint { Source0 = perturbedWood, ZTranslation = 1.48, }; var rotatedWood = new RotatePoint { Source0 = translatedWood, }; rotatedWood.SetAngles(84, 0, 0); var finalWood = new Turbulence { Source0 = rotatedWood, Seed = 2, Frequency = 2, Power = 1.0 / 64.0, Roughness = 4, }; testModule = finalWood; }
void GUI_BoneMenu() { //content box GUI.Box(new Rect(10, Screen.height / 2 - 200, 275, 400), "Animation Editor"); //transform data GUI.Label(new Rect(30, Screen.height / 2 - 180, 50, 20), elist[editmode]); GUI.Label(new Rect(30, Screen.height / 2 - 160, 20, 20), " X"); PositionText.x = GUI.TextField(new Rect(50, Screen.height / 2 - 160, 50, 20), PositionText.x); GUI.Label(new Rect(100, Screen.height / 2 - 160, 20, 20), " Y"); PositionText.y = GUI.TextField(new Rect(120, Screen.height / 2 - 160, 50, 20), PositionText.y); GUI.Label(new Rect(170, Screen.height / 2 - 160, 20, 20), " Z"); PositionText.z = GUI.TextField(new Rect(190, Screen.height / 2 - 160, 50, 20), PositionText.z); editmode = GUI.SelectionGrid(new Rect(30, Screen.height / 2 - 130, 235, 20), editmode, elist, 3); if (editmode != editModeChange) { UpdateTransformValues(); UpdateCalcType(); } editModeChange = editmode; ApplyTransformValues(); try { if (selection == 1) { GUI.Box(new Rect(30, Screen.height / 2 - 100, 235, 205), RB.parts[selectedPiece].name + " Frames"); GUI_Framelist(); GUI.Label(new Rect(35, Screen.height / 2 + 115, 60, 20), "CalcType"); calctype = GUI.TextField(new Rect(95, Screen.height / 2 + 115, 50, 20), calctype); GUI.Label(new Rect(160, Screen.height / 2 + 115, 60, 20), "PowVal"); powval = GUI.TextField(new Rect(210, Screen.height / 2 + 115, 50, 20), powval); ApplyCalcType(); if (GUI.Button(new Rect(30, Screen.height / 2 + 140, 116, 20), "Add")) { bool hasFrames = false; for (int i = 0; i < RB.BC.Count; i++) { if (RB.BC[i].GO == RB.parts[selectedPiece]) { hasFrames = true; break; } } if (!hasFrames) { RB.BC.Add(new BoneCurves()); indexBC = RB.BC.Count - 1; RB.BC[indexBC].GO = RB.parts[selectedPiece]; RB.BC[indexBC].name = RB.parts[selectedPiece].name; Debug.Log("test"); } switch (elist[editmode]) { case "Position": if (RB.BC[indexBC].PosCurve.Count == 0) { PosPoint PP = new PosPoint(); PP.Frame = 0; PP.Value = Vector3.zero; PP.calctype = 0; PP.PowVal = 1; RB.BC[indexBC].PosCurve.Add(PP); } else { if (!isFrameOccupied(Mathf.RoundToInt(FrameSlider))) { int newFramePos = Mathf.RoundToInt(FrameSlider); int insertFrame = -1; for (int i = 0; i < RB.BC[indexBC].PosCurve.Count; i++) { if (RB.BC[indexBC].PosCurve[i].Frame > newFramePos && (insertFrame == -1 || RB.BC[indexBC].PosCurve[i].Frame < RB.BC[indexBC].PosCurve[insertFrame].Frame)) insertFrame = i; } if (insertFrame == -1) { PosPoint FPP = RB.BC[indexBC].PosCurve[RB.BC[indexBC].PosCurve.Count - 1]; FPP.Frame = newFramePos; RB.BC[indexBC].PosCurve.Add(FPP); } else { PosPoint FPP = RB.BC[indexBC].PosCurve[insertFrame - 1]; FPP.Frame = newFramePos; RB.BC[indexBC].PosCurve.Insert(insertFrame, FPP); } } } break; case "Rotation": if (RB.BC[indexBC].RotCurve.Count == 0) { RotPoint RP = new RotPoint(); RP.Frame = 0; RP.Value = Quaternion.identity; RP.calctype = 0; RP.PowVal = 1; RB.BC[indexBC].RotCurve.Add(RP); } else { if (!isFrameOccupied(Mathf.RoundToInt(FrameSlider))) { int newFramePos = Mathf.RoundToInt(FrameSlider); int insertFrame = -1; for (int i = 0; i < RB.BC[indexBC].RotCurve.Count; i++) { if (RB.BC[indexBC].RotCurve[i].Frame > newFramePos && (insertFrame == -1 || RB.BC[indexBC].RotCurve[i].Frame < RB.BC[indexBC].RotCurve[insertFrame].Frame)) insertFrame = i; } if (insertFrame == -1) { RotPoint FPP = RB.BC[indexBC].RotCurve[RB.BC[indexBC].RotCurve.Count - 1]; FPP.Frame = newFramePos; RB.BC[indexBC].RotCurve.Add(FPP); } else { RotPoint FPP = RB.BC[indexBC].RotCurve[insertFrame - 1]; FPP.Frame = newFramePos; RB.BC[indexBC].RotCurve.Insert(insertFrame, FPP); } } } break; case "Scale": if (RB.BC[indexBC].ScaleCurve.Count == 0) { ScalePoint SP = new ScalePoint(); SP.Frame = 0; SP.Value = Vector3.zero; SP.calctype = 0; SP.PowVal = 1; RB.BC[indexBC].ScaleCurve.Add(SP); } else { if (!isFrameOccupied(Mathf.RoundToInt(FrameSlider))) { int newFramePos = Mathf.RoundToInt(FrameSlider); int insertFrame = -1; for (int i = 0; i < RB.BC[indexBC].ScaleCurve.Count; i++) { if (RB.BC[indexBC].ScaleCurve[i].Frame > newFramePos && (insertFrame == -1 || RB.BC[indexBC].ScaleCurve[i].Frame < RB.BC[indexBC].ScaleCurve[insertFrame].Frame)) insertFrame = i; } if (insertFrame == -1) { ScalePoint FPP = RB.BC[indexBC].ScaleCurve[RB.BC[indexBC].ScaleCurve.Count - 1]; FPP.Frame = newFramePos; RB.BC[indexBC].ScaleCurve.Add(FPP); } else { ScalePoint FPP = RB.BC[indexBC].ScaleCurve[insertFrame - 1]; FPP.Frame = newFramePos; RB.BC[indexBC].ScaleCurve.Insert(insertFrame, FPP); } } } break; } } if (GUI.Button(new Rect(150, Screen.height / 2 + 140, 115, 20), "Remove")) { switch (elist[editmode]) { case "Position": RB.BC[indexBC].PosCurve.RemoveAt(selectedFrame); break; case "Rotation": RB.BC[indexBC].RotCurve.RemoveAt(selectedFrame); break; case "Scale": RB.BC[indexBC].ScaleCurve.RemoveAt(selectedFrame); break; } } if (selectedFrame != prevSelectedFrame) RB.AnimeFrameGo(frameNum); prevSelectedFrame = selectedFrame; UpdateTransformValues(); if (checkIfEmpty()) indexBC = 0; } else { GUI.Box(new Rect(30, Screen.height / 2 - 100, 235, 260), "Parts"); string[] Piecelist = listModels(); ScrollPositions[1] = GUI.BeginScrollView(new Rect(30, Screen.height / 2 - 75, 235, 235), ScrollPositions[1], new Rect(0, 0, 219, Piecelist.Length * 25)); try { selectedPiece = GUI.SelectionGrid(new Rect(0, 0, 219, (float)25 * (float)Piecelist.Length), selectedPiece, Piecelist, 1); } catch { } GUI.EndScrollView(); } } catch { } selection = GUI.SelectionGrid(new Rect(30, Screen.height / 2 + 165, 235, 20), selection, slist, 2); if (selection != prevselection) UpdateCalcType(); prevselection = selection; }