private void Timer_Tick() { ++counter; counter %= 128; if (DynamicTexture) { Vector2Collection texture = null; if (!AnimateUVOffset) { texture = new Vector2Collection(Model.TextureCoordinates); var t0 = texture[0]; for (int i = 1; i < texture.Count; ++i) { texture[i - 1] = texture[i]; } texture[texture.Count - 1] = t0; } context.Send((o) => { if (!AnimateUVOffset) { Model.TextureCoordinates = texture; if (ReverseInnerRotation) { var texture1 = new Vector2Collection(texture); texture1.Reverse(); InnerModel.TextureCoordinates = texture1; } else { InnerModel.TextureCoordinates = texture; } } else { ModelMaterial.UVTransform = new UVTransform(0, Vector2.One, ModelMaterial.UVTransform.Translation + new Vector2(0.005f, -0.01f)); InnerModelMaterial.UVTransform = new UVTransform(0, Vector2.One, InnerModelMaterial.UVTransform.Translation + new Vector2(-0.01f, 0.005f)); } }, null); } if (DynamicVertices) { var positions = new Vector3Collection(initialPosition); for (int i = 0; i < positions.Count; ++i) { var off = (float)Math.Sin(Math.PI * (float)(counter + i) / 64); var p = positions[i]; p *= 0.8f + off * 0.2f; positions[i] = p; } var linePositions = new Vector3Collection(positions); linePositions.Add(Vector3.Zero); //var normals = MeshGeometryHelper.CalculateNormals(positions, initialIndicies); //var innerNormals = new Vector3Collection(normals.Select(x => { return x * -1; })); context.Send((o) => { //Model.Normals = normals; //InnerModel.Normals = innerNormals; //Model.Positions = positions; //InnerModel.Positions = positions; PointModel.Positions = positions; LineModel.Positions = linePositions; }, null); } if (DynamicTriangles) { var indices = new IntCollection(initialIndicies); if (isRemoving) { removedIndex += 3 * 8; if (removedIndex >= initialIndicies.Count) { removedIndex = initialIndicies.Count; isRemoving = false; } } else { removedIndex -= 3 * 8; if (removedIndex <= 0) { isRemoving = true; removedIndex = 0; } } indices.RemoveRange(0, removedIndex); context.Send((o) => { Model.Indices = indices; InnerModel.Indices = indices; }, null); } if (DynamicTexture) { var colors = new Color4Collection(PointModel.Colors); for (int k = 0; k < 10; ++k) { var c = colors[colors.Count - 1]; for (int i = colors.Count - 1; i > 0; --i) { colors[i] = colors[i - 1]; } colors[0] = c; } var lineColors = new Color4Collection(LineModel.Colors); for (int k = 0; k < 10; ++k) { var c = lineColors[colors.Count - 2]; for (int i = lineColors.Count - 2; i > 0; --i) { lineColors[i] = lineColors[i - 1]; } lineColors[0] = c; } context.Send((o) => { PointModel.Colors = colors; LineModel.Colors = lineColors; }, null); } }
private void Timer_Tick(object sender, EventArgs e) { if (DynamicTexture) { var texture = new Vector2Collection(Model.TextureCoordinates); for (int i = 1; i < Model.TextureCoordinates.Count; ++i) { texture[i - 1] = Model.TextureCoordinates[i]; } texture[texture.Count - 1] = Model.TextureCoordinates[0]; Model.TextureCoordinates = texture; if (ReverseInnerRotation) { var texture1 = new Vector2Collection(texture); texture1.Reverse(); InnerModel.TextureCoordinates = texture1; } else { InnerModel.TextureCoordinates = texture; } } if (DynamicVertices) { var positions = new Vector3Collection(initialPosition); for (int i = 0; i < positions.Count; ++i) { positions[i] = positions[i] * (float)rnd.Next(95, 105) / 100; } Model.Normals = MeshGeometryHelper.CalculateNormals(positions, Model.Indices); InnerModel.Normals = new Vector3Collection(Model.Normals.Select(x => { return(x * -1); })); Model.Positions = positions; InnerModel.Positions = positions; //Alternative implementation //Floor.DisablePropertyChangedEvent = true; //Floor.Positions = positions; //Floor.CalculateNormals(); //Floor.DisablePropertyChangedEvent = false; //Floor.UpdateVertex(); } if (DynamicTriangles) { var indices = new IntCollection(initialIndicies); if (isRemoving) { removedIndex += 3 * 8; if (removedIndex >= initialIndicies.Count) { removedIndex = initialIndicies.Count; isRemoving = false; } } else { removedIndex -= 3 * 8; if (removedIndex <= 0) { isRemoving = true; removedIndex = 0; } } indices.RemoveRange(0, removedIndex); Model.Indices = indices; InnerModel.Indices = indices; } }