public void Derivation(DataTable ddd, ref DataTable result, bool tt, int K)//平滑并求导,tt为真则是对土壤库求导,否则是对样本库求导,K为放大倍数 { DataTable temp = new DataTable(); Smooth sth = new Smooth(); sth.PlotStore(ref ddd, temp); if (tt) { for (int i = 1; i < T /*ddd.Rows.Count*/; i++) { for (int j = 8; j < temp.Columns.Count; j++) { //计算曲线各个位置上的一阶导数(用差分代替微分) result.Rows[i][j] = K * (Convert.ToDouble(temp.Rows[i][j]) - Convert.ToDouble(temp.Rows[i][j - 1])); } result.Rows[i][7] = 0;//单独给第一个点赋值 } } else { for (int i = 0; i < ddd.Rows.Count; i++) { for (int j = 1; j < temp.Columns.Count; j++) { //计算曲线各个位置上的一阶导数(用差分代替微分并放大) result.Rows[i][j] = K * ((Convert.ToDouble(temp.Rows[i][j]) - Convert.ToDouble(temp.Rows[i][j - 1]))); } result.Rows[i][0] = 0;//单独给第一个点赋值 } } }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Black; float[,] map = new float[40, 40]; float[,] map2 = new float[40, 40]; map = Generator.PureRandom(40, 40, "asd"); map2 = Generator.PureRandom(40, 40, "aaa"); //map = GoniometricGenerator.sinWave(50, 50, 0.5f); map = TerrainMath.Multiply(map, 10); map = Smooth.SquareSmooth(map); map = Mountains.RemoveSmall(map, 6, 9); map = Water.RemoveSmall(map, 4, 7); map2 = TerrainMath.Multiply(map2, 10); map2 = Smooth.SquareSmooth(map); map2 = Mountains.RemoveSmall(map, 6, 9); map2 = Water.RemoveSmall(map, 4, 7); map = TerrainMath.Mix(map, map2); //map = TerrainMath.Clamp(map, 0, 9); map = Rounder.RoundDown(map); //map = Rounder.Round(map); VisualizeColor(map); Console.ReadLine(); }
private void LateUpdate() { transform.position = Vector3.Lerp(transform.position, _player.transform.position + _cameraOffset, Time.deltaTime * 5); transform.localScale = Smooth.SmoothDamp(transform.localScale, _desiredCameraDistance, ref _sVelocity, 0.3f); transform.rotation = Smooth.SmoothDamp(transform.rotation, _desiredCameraRotation, ref _rVelocity, 0.3f); }
public void SmoothTerrain(int iterations) { float[,] heightmap = GetTerrainHeight(); Smooth.Apply(heightmap, iterations); UpdateTerrainHeight(heightmap); }
public void CalRaw() { Derivation(Raw, ref RawAfter1, true, 100); DataTable temp = new DataTable(); Smooth sth = new Smooth(); sth.PlotStore(ref RawAfter1, temp);; Derivation(RawAfter1, ref RawAfter2, true, 10); FindPeak(RawAfter2, ref temp, pRawcharacter, true); }
public void CalExample() { Derivation(Example, ref ExampleAfter1, false, 100); DataTable temp = new DataTable(); Smooth sth = new Smooth(); sth.PlotStore(ref ExampleAfter1, temp);; Derivation(ExampleAfter1, ref ExampleAfter2, true, 10); FindPeak(ExampleAfter2, ref temp, pexamplecharacter, false); }
public NoiseGenerator(int seed, int octaves = 8, double amplitude = 1, double persistence = 0.65, double frequency = 0.015) { Seed = seed; Octaves = octaves; Amplitude = amplitude; Persistence = persistence; Frequency = frequency; smooth = CrossSmooth; }
private void UpdateForSmooth(Vector3 wpos) { reticleSpherical.EnableRenderer(true); reticleSpherical.SetPositionAndSize(wpos, BrushSize); if (clicking && Terrain.OperationsManager.IsReadyToComputeAsync) { Terrain.OperationsManager .Add(Smooth.CreateFromUnityWorld(Terrain, wpos, BrushSize, Math.Max(1.0, BrushSize / 3.0)), true) .PerformAll(asyncOperations); } }
public void Smooth_ShouldBeEqualSmoothedHeighmap(string originalHeightmap, string smoothedHeightmap) { // Arrange float[,] actualHeighmap = ReadHeightMap(originalHeightmap); float[,] expectedHeighmap = ReadHeightMap(smoothedHeightmap); // Act Smooth.Apply(actualHeighmap, iterations); // Assert AreEqual(actualHeighmap, expectedHeighmap, allowedDifference).Should().Be(true); }
public void Init( float rotation_around_x_stick_time_to_reach_target, float rotation_around_y_time_to_reach_target ) { // Rotation Around X rotation_around_x = new Smooth <float>(0, rotation_around_x_stick_tick); this.rotation_around_x_time_to_reach_target = rotation_around_x_stick_time_to_reach_target; // Rotation Around Y rotation_around_y = new Smooth <float>(0, rotation_around_y_tick); this.rotation_around_y_time_to_reach_target = rotation_around_y_time_to_reach_target; }
public void MoveCamera(Vector3 dir) { Smooth sm = MainCamera.GetComponent <Smooth>(); if (dir == Vector3.zero) { sm.Reset(); } else { sm.MoveDir(dir); } }
static private void add(Object info) { lock (locker) { Smooth.sliding_rms(info); if (Validator.invalid != 0) { Validator.invalid--; return; } AccumNoise[0] += Smooth.output[0]; AccumNoise[1] += Smooth.output[1]; } }
private void OnUpdate() { this.CursorCanvasGroup.set_alpha(Smooth.Damp(this.CursorCanvasGroup.get_alpha(), !this.EnabledInput || this.FocusLevel != Singleton <Input> .Instance.FocusLevel || !Object.op_Inequality((Object)this.SelectedOption, (Object)null) ? 0.0f : 1f, ref this._alphaVelocity, this._alphaAccelerationTime)); if (Object.op_Inequality((Object)this.SelectedOption, (Object)null)) { CursorFrame.Set(((Graphic)this._cursorFrame).get_rectTransform(), (RectTransform)((Component)this.SelectedOption).GetComponent <RectTransform>(), ref this._velocity, new float?(), new float?(this._followAccelerationTime)); } if (Object.op_Equality((Object)this.CurrentOption, (Object)null)) { ((Component)this._selectedCursorFrame).get_gameObject().SetActive(false); } else { ((Component)this._selectedCursorFrame).get_gameObject().SetActive(true); CursorFrame.Set(((Graphic)this._selectedCursorFrame).get_rectTransform(), (RectTransform)((Component)this.CurrentOption).GetComponent <RectTransform>(), ref this._selectedvelocity, new float?(), new float?(this._followAccelerationTime)); } }
/// <summary> /// Set display, width, color and fill of borders and data (line, bar etc.) in chart. /// </summary> public ChartShapeProperties SetChartShapeProperties(OpenXmlCompositeElement chartSeries, bool visible = true, uint colorPoints = 0) { ChartShapeProperties chartShapeProperties1 = new ChartShapeProperties(); Outline outline1 = new Outline() { Width = 28575, CapType = LineCapValues.Round }; Round round1 = new Round(); outline1.Append(new NoFill()); outline1.Append(round1); EffectList effectList1 = new EffectList(); if (!visible) { chartShapeProperties1.Append(new NoFill()); } chartShapeProperties1.Append(outline1); chartShapeProperties1.Append(effectList1); Marker marker1 = new Marker(); Symbol symbol1 = new Symbol() { Val = MarkerStyleValues.None }; marker1.Append(symbol1); Smooth smooth1 = new Smooth() { Val = false }; chartSeries.Append(chartShapeProperties1); chartSeries.Append(marker1); chartSeries.Append(smooth1); for (uint i = 0; i < colorPoints; i++) { chartSeries.Append(colorChartLines(i)); } return(chartShapeProperties1); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < 2) { MACD.Set(0); Smooth.Set(0); Hist.Set(0); return; } MACD.Set(fast[0] - slow[0]); Smooth.Set(Smooth[1] + 0.25 * (MACD[0] - Smooth[1])); Hist.Set(MACD[0] - Smooth[0]); if ((Hist[0] > Hist[1]) || ((Hist[0] == Hist[1]) && (Hist[1] > Hist[2]))) { PlotColors[2][0] = Color.MidnightBlue; } }
//temporary calibration which tracks maximum amplitude public static void AmpCal(Object info) { lock (locker) { Smooth.sliding_rms(info); // should be called by add EMG_Socket.add instead if (invalid != 0) { --invalid; return; } if (max[0] < Smooth.output[0]) { max[0] = Smooth.output[0]; } if (max[1] < Smooth.output[1]) { max[1] = Smooth.output[1]; } } }
//function use to calculate percentage of muscle activity. public static void evaluate(Object info) { lock (locker) { Smooth.sliding_rms(info); //process EMG Data flex_norm = Math.Abs((Smooth.output[0] - rest_Avg[0]) / (flex_Max[0] - rest_Avg[0])); ext_norm = Math.Abs((Smooth.output[1] - rest_Avg[1]) / (ext_Max[1] - rest_Avg[1])); data[0] = flex_norm; data[1] = ext_norm; if (0.5 * flex_Max[0] <= Smooth.output[0]) { } //valid.Set(); else if (0.5 * ext_Max[1] <= Smooth.output[1]) { } //valid.Set(); } m_LSLOutlet.push_sample(data); }
public void Derivation(DataTable ddd, ref DataTable result, int K, ref double[, ,] p, double Y)//平滑并求导,tt为真则是对土壤库求导,否则是对样本库求导,K为放大倍数,Y为=0的阈值 { DataTable temp = new DataTable(); Smooth sth = new Smooth(); sth.Plot5(ddd, ref temp); for (int i = 1; i < ddd.Rows.Count; i++) { int TEMP = 0;//计算有多少个极大值点 for (int j = 13; j < temp.Columns.Count - 5; j++) { //计算曲线各个位置上的一阶导数(用差分代替微分) result.Rows[i][j] = K * (Convert.ToDouble(temp.Rows[i][j]) - Convert.ToDouble(temp.Rows[i][j - 1])); if (Math.Abs(Convert.ToDouble(result.Rows[i][j])) < Y && (Convert.ToDouble(temp.Rows[i][j - 5]) < Convert.ToDouble(temp.Rows[i][j])) && (Convert.ToDouble(temp.Rows[i][j + 5]) < Convert.ToDouble(temp.Rows[i][j]))) { p[i, TEMP, 0] = j; p[i, TEMP, 1] = Convert.ToDouble(temp.Rows[i][j]); TEMP++; } } result.Rows[i][7] = 0;//单独给第一个点赋值 } }
public static void makeCube(int i, int x, int y, int z, List <Vector3> vertices, List <int> indices, List <Vector2> UVs, Block[] adjacentBlocks, Block[,,] blockGrid) { if (instance == null) { instance = new Smooth(); } Block[] adjacentBlocksNoRot = getAdjacentBlocks(blockGrid, x, y, z, 0); Block left = adjacentBlocksNoRot[(int)Directions.Left]; Block front = adjacentBlocksNoRot[(int)Directions.Front]; Block right = adjacentBlocksNoRot[(int)Directions.Right]; Block back = adjacentBlocksNoRot[(int)Directions.Back]; Block middle = adjacentBlocksNoRot[(int)Directions.Middle]; Block NE = blockGrid[x + 1, y, z + 1]; Block SE = blockGrid[x + 1, y, z - 1]; Block SW = blockGrid[x - 1, y, z - 1]; Block NW = blockGrid[x - 1, y, z + 1]; //Make middlecube Cube.makeCube(i, x, y, z, vertices, indices, UVs, adjacentBlocks); //SIDES AND CORNER INS if (left.texture != middle.texture) { if (NW.texture == middle.texture) { } else if (SW.texture == middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 0, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.innerCorner.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.innerCorner.subMeshCount; n++) { foreach (int indice in instance.innerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.innerCorner.uv) { UVs.Add(uv); } blockGrid[x - 1, y, z] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } else { //STRAIGHT int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); foreach (Vector3 vertice in instance.side.vertices) { vertices.Add(position + vertice); } for (int n = 0; n < instance.side.subMeshCount; n++) { foreach (int indice in instance.side.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.side.uv) { UVs.Add(uv); } blockGrid[x - 1, y, z] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } } if (front.texture != middle.texture) { if (NW.texture == middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 90, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.innerCorner.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.innerCorner.subMeshCount; n++) { foreach (int indice in instance.innerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.innerCorner.uv) { UVs.Add(uv); } blockGrid[x, y, z + 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } else if (NE.texture == middle.texture) { } else { //STRAIGHT int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 90, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.side.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.side.subMeshCount; n++) { foreach (int indice in instance.side.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.side.uv) { UVs.Add(uv); } blockGrid[x, y, z + 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } } if (right.texture != middle.texture) { if (NE.texture == middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 180, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.innerCorner.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.innerCorner.subMeshCount; n++) { foreach (int indice in instance.innerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.innerCorner.uv) { UVs.Add(uv); } blockGrid[x + 1, y, z] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } else if (SE.texture == middle.texture) { } else { //STRAIGHT int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 180, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.side.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.side.subMeshCount; n++) { foreach (int indice in instance.side.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.side.uv) { UVs.Add(uv); } blockGrid[x + 1, y, z] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } } if (back.texture != middle.texture) { if (SE.texture == middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 270, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.innerCorner.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.innerCorner.subMeshCount; n++) { foreach (int indice in instance.innerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.innerCorner.uv) { UVs.Add(uv); } blockGrid[x, y, z - 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } else if (SW.texture == middle.texture) { } else { //STRAIGHT int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 270, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.side.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.side.subMeshCount; n++) { foreach (int indice in instance.side.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.side.uv) { UVs.Add(uv); } blockGrid[x, y, z - 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } } //CORNER OUTS if (NW.texture != middle.texture && front.texture != middle.texture && left.texture != middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); foreach (Vector3 vertice in instance.outerCorner.vertices) { vertices.Add(position + vertice); } for (int n = 0; n < instance.outerCorner.subMeshCount; n++) { foreach (int indice in instance.outerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.outerCorner.uv) { UVs.Add(uv); } blockGrid[x - 1, y, z + 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } if (NE.texture != middle.texture && front.texture != middle.texture && right.texture != middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 90, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.outerCorner.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.outerCorner.subMeshCount; n++) { foreach (int indice in instance.outerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.outerCorner.uv) { UVs.Add(uv); } blockGrid[x + 1, y, z + 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } if (SE.texture != middle.texture && back.texture != middle.texture && right.texture != middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 180, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.outerCorner.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.outerCorner.subMeshCount; n++) { foreach (int indice in instance.outerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.outerCorner.uv) { UVs.Add(uv); } blockGrid[x + 1, y, z - 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } if (SW.texture != middle.texture && back.texture != middle.texture && left.texture != middle.texture) { int vertexIndex = vertices.Count; Vector3 position = new Vector3(x, y, z); Quaternion rot = Quaternion.Euler(0, 270, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); foreach (Vector3 vertice in instance.outerCorner.vertices) { vertices.Add(rot * ((position + vertice) - middlePoint) + middlePoint); } for (int n = 0; n < instance.outerCorner.subMeshCount; n++) { foreach (int indice in instance.outerCorner.GetIndices(n)) { indices.Add(indice + vertexIndex); } } foreach (Vector2 uv in instance.outerCorner.uv) { UVs.Add(uv); } blockGrid[x - 1, y, z - 1] = new Block(ObjectController.SMOOTHBORDER, 0, 0); } }
private void trackBarSmooth_ValueChanged(object sender, EventArgs e) { Smooth = trackBarSmooth.Value; tbSmooth.Text = Smooth.ToString();; }
//reset variables involved with processing public static void reset() { filter.reset(); Smooth.reset(); }
public override void Load() { PreLoad(); var list = ReadHpglCommandList(); RemoveFirstPenUp(list); RemoveLastPenUp(list); Smooth.CalculateAngles(list, null); if (LoadOptions.AutoScale) { var autoScale = new AutoScale { LoadOptions = LoadOptions, LoadX = this }; autoScale.AutoScaleList(list); } if (LoadOptions.SmoothType != LoadOptions.SmoothTypeEnum.NoSmooth) { var smooth = new Smooth { LoadOptions = LoadOptions, LoadX = this }; list = smooth.SmoothList(list); } if (LoadOptions.ConvertType != LoadOptions.ConvertTypeEnum.NoConvert) { var invert = new InvertLine { LoadOptions = LoadOptions, LoadX = this }; list = invert.ConvertInvert(list); } AddComment("PenMoveType", LoadOptions.PenMoveType.ToString()); switch (LoadOptions.PenMoveType) { case LoadOptions.PenType.CommandString: AddCommentForLaser(); break; case LoadOptions.PenType.ZMove: AddComment("PenDownSpeed", LoadOptions.EngraveDownSpeed); AddComment("PenUpPos", LoadOptions.EngravePosUp); AddComment("PenDownPos", LoadOptions.EngravePosDown); break; } AddComment("Speed", LoadOptions.MoveSpeed.ToString()); if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove) { AddCommands("M3"); if (LoadOptions.EngravePosInParameter) { Commands.AddCommand( new SetParameterCommand { ParameterNo = 1, GCodeAdd = LoadOptions.EngravePosUp.ToString(CultureInfo.InvariantCulture) }); Commands.AddCommand( new SetParameterCommand { ParameterNo = 2, GCodeAdd = LoadOptions.EngravePosDown.ToString(CultureInfo.InvariantCulture) }); } } if (LoadOptions.MoveSpeed.HasValue) { var setSpeed = new G01Command(); setSpeed.AddVariable('F', LoadOptions.MoveSpeed.Value); Commands.Add(setSpeed); } foreach (var cmd in list) { if (!Command(cmd)) { Commands.Clear(); break; } } if (!_lastIsPenUp) { LoadPenUp(); } if (LoadOptions.PenMoveType == LoadOptions.PenType.ZMove) { AddCommands("M5"); } PostLoad(); }
protected virtual IOperation CreateOperationFromEditor(Vector3 worldPosition, TerrainToolEditor editor) { return(Smooth.CreateFromUnityWorld(editor.Terrain, worldPosition, Radius, Math.Max(1.0, Radius / SamplingAccuracy))); }
public static List <Mesh>[] getMeshes(List <GameObject>[] chunks, Block[,,] blockGrid) { //Array of each texture //List of each chunk for texture //List of each vertex/index/UV List <List <Vector3> >[] vertices = new List <List <Vector3> > [chunks.Length]; List <List <int> >[] indices = new List <List <int> > [chunks.Length]; List <List <Vector2> >[] UVs = new List <List <Vector2> > [chunks.Length]; for (int x = 0; x < ChunkMap.SizeX; x++) { for (int y = 0; y < ChunkMap.SizeY; y++) { for (int z = 0; z < ChunkMap.SizeZ; z++) { Block block = blockGrid[x, y, z]; if (block.texture != 0) { int i = block.texture - 1; //choose the Chunk if (chunks.Length == 1) { i = 0; } if (vertices[i] == null) { vertices[i] = new List <List <Vector3> >(); indices[i] = new List <List <int> >(); UVs[i] = new List <List <Vector2> >(); } int verticeCountInStart = 0; if (vertices[i].Count != 0) { verticeCountInStart = vertices[i].Last().Count(); } //Create new list for chunk if (vertices[i].Count == 0 || verticeCountInStart > 50000) { vertices[i].Add(new List <Vector3>()); indices[i].Add(new List <int>()); UVs[i].Add(new List <Vector2>()); } Block[] adjacentBlocks = getAdjacentBlocks(blockGrid, x, y, z, block.rotation); List <Vector3> verts = vertices[i].Last(); List <int> inds = indices[i].Last(); List <Vector2> uvs = UVs[i].Last(); int rotation = block.rotation; switch (block.shape) { case 0: Cube.makeCube(i, x, y, z, verts, inds, uvs, adjacentBlocks); break; case 1: rotation = Stairs.makeStairs(i, x, y, z, verts, inds, uvs, adjacentBlocks, blockGrid); break; case 2: rotation = Slope.makeSlope(i, x, y, z, verts, inds, uvs, adjacentBlocks, blockGrid, 0, 1); break; case 3: Smooth.makeCube(i, x, y, z, verts, inds, uvs, adjacentBlocks, blockGrid); break; case 4: Cube.makeSlab(i, x, y, z, verts, inds, uvs, adjacentBlocks); break; case 5: rotation = Slope.makeSlope(i, x, y, z, verts, inds, uvs, adjacentBlocks, blockGrid, 0, 0.5f); break; } //ROTATE for (int n = verticeCountInStart; n < verts.Count; n++) { Quaternion rot = Quaternion.Euler(0, 90 * rotation, 0); Vector3 middlePoint = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f); verts[n] = rot * (verts[n] - middlePoint) + middlePoint; } } } } } List <Mesh>[] meshes = new List <Mesh> [chunks.Length]; for (int i = 0; i < chunks.Length; i++) { meshes[i] = new List <Mesh>(); if (vertices[i] != null) { for (int j = 0; j < vertices[i].Count; j++) { meshes[i].Add(new Mesh()); meshes[i][j].vertices = vertices[i][j].ToArray(); meshes[i][j].triangles = indices[i][j].ToArray(); meshes[i][j].uv = UVs[i][j].ToArray(); } } else { meshes[i].Add(new Mesh()); } } return(meshes); }
private void Update(EvaluationContext context) { var needsRecalcAverage = false; var filePath = FilePath.GetValue(context); if (filePath != _filepath) { _filepath = filePath; if (File.Exists(_filepath)) { using (var reader = new StreamReader(filePath)) { var jsonString = reader.ReadToEnd(); _upLevels = JsonConvert.DeserializeObject <float[]>(jsonString); if (_upLevels == null || _upLevels.Length == 0) { Log.Warning("Loading sound levels failed"); return; } } } else { Log.Warning("File doesn't exist: " + _filepath); } needsRecalcAverage = true; } var smoothWindow = (int)Clamp(Smooth.GetValue(context), 1, MaxSmoothWindow); needsRecalcAverage |= smoothWindow != _smoothWindow; if (needsRecalcAverage) { _minTimeBetweenPeaks = MinTimeBetweenPeaks.GetValue(context); _smoothWindow = smoothWindow; _maxLevel = 0f; _averageLevels = new float[_upLevels.Length]; _averageLevels2 = new float[_upLevels.Length]; foreach (var l in _upLevels) { _maxLevel = Math.Max(l, _maxLevel); } SmoothBuffer(ref _upLevels, ref _averageLevels2, _smoothWindow, 1); SmoothBuffer(ref _averageLevels2, ref _averageLevels, _smoothWindow, 2); SmoothBuffer(ref _averageLevels, ref _averageLevels2, _smoothWindow, 4); SmoothBuffer(ref _averageLevels2, ref _averageLevels, _smoothWindow, 8); } bool needsRescanBeats = needsRecalcAverage; var threshold = Threshold.GetValue(context); needsRescanBeats |= threshold != _threshold; var minTimeBetweenPeaks = MinTimeBetweenPeaks.GetValue(context); needsRescanBeats |= minTimeBetweenPeaks != _minTimeBetweenPeaks; if (needsRescanBeats) { _threshold = threshold; _minTimeBetweenPeaks = minTimeBetweenPeaks; UpdateAllBeatNumbers(); } //var index = (int)(Time.GetValue(context) * SampleResolutionPerSecond); var index = (int)(Playback.Current.TimeInBars * SampleResolutionPerSecond); // Log.Debug("INdex:" + index); var needToFindNewBoundaries = (index <= _beatStartIndex || index >= _beatEndIndex); needToFindNewBoundaries |= needsRescanBeats; if (needToFindNewBoundaries) { FindBoundarysFromBeatNumbers(index, out _beatStartIndex, out _beatEndIndex); } //FindBeatBoundaries(index, ref _beatStartIndex, ref _beatEndIndex); if (_upLevels == null || index >= _upLevels.Length || index <= 0 || !(_maxLevel > 0.001f)) { return; } Level.Value = _upLevels[index]; // Peaks... // BeatTime.Value = (float)Math.Max(0, _uplevels[index] - _averageLevels[index]); // Flashes: var t = ((float)index - _beatStartIndex) / SampleResolutionPerSecond; BeatTime.Value = (float)Math.Pow(2.71f, -FlashDecay.GetValue(context) * t); // FlashesWithIntensity... // var t2 = ((float)index - _beatStartIndex) / (float)SAMPLE_RESOLUTION_PER_SECOND; // BeatTime.Value = (float)Math.Pow(2.71f, -FlashDecay* t2) * _uplevels[_beatStartIndex]; // TimeSincePeak... // BeatTime.Value = ((float)index - _beatStartIndex) / (float)SAMPLE_RESOLUTION_PER_SECOND; // TimeToPeak... // BeatTime.Value = (_beatEndIndex - (float)index) / (float)SAMPLE_RESOLUTION_PER_SECOND; // BeatIndex.Value = (float)_beatStartIndex; BeatIndex.Value = _beatNumbers[index]; Loudness.Value = _averageLevels[index]; }
/// <summary> /// Returns the name of this indicator. /// </summary> /// <returns>The name of this indicator</returns> public override string ToString() { return("Ppo," + Fast.ToString() + "," + Slow.ToString() + "," + Smooth.ToString()); }