bool ReadData() { if (mPositions != null) { return(true); } string fileName = GetResourcePath("pressure.json"); using (StreamReader reader = File.OpenText(fileName)) { JObject obj = JObject.Parse(reader.ReadToEnd()); var postionsToken = obj["data"]["attributes"]["position"]["array"].Children().ToList(); mPositions = new Float32Buffer(0); mPositions.Reserve((uint)postionsToken.Count); foreach (var token in postionsToken) { float val = token.ToObject <float>(); mPositions.Append(val); } mColorTable = new ColorLookupTable(); mColorTable.SetMaxValue(2000); mColorTable.SetColorMap(ColorMapKeyword.Create(EnumSystemColorMap.Rainbow)); mColors = new Float32Buffer((uint)postionsToken.Count); var pressureToken = obj["data"]["attributes"]["pressure"]["array"].Children().ToList(); mPressures = new Float32Buffer(0); mPressures.Reserve((uint)pressureToken.Count); uint idx = 0; foreach (var token in pressureToken) { float val = token.ToObject <float>(); mPressures.Append(val); var clr = mColorTable.GetColor(val); mColors.SetValue(idx * 3, clr); ++idx; } } return(true); }
public override void Run(RenderControl render) { // prepare points data const int COUNT = 300; var buffer = new Float32Buffer(0); buffer.Reserve(COUNT * 3); var colors = new Float32Buffer(0); Random random = new Random(); for (int i = 0; i < COUNT; i++) { float x = 2000 * (float)random.NextDouble() - 1000; float y = 2000 * (float)random.NextDouble() - 1000; float z = 2000 * (float)random.NextDouble() - 1000; buffer.Append(x, y, z); colors.Append((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); } var primitive = GeometryBuilder.CreatePoints(new Float32Array(buffer), new Float32Array(colors)); // prepare point material var material = PointsMaterial.Create("points-material"); material.SetSizeAttenuation(false); material.SetPointSize(15.0f); material.SetColorMap(ImageTexture2D.Create(GetResourcePath("textures/snowflake7_alpha.png"))); material.SetTransparent(true); // enable vertex color material.GetTemplate().SetVertexColors(true); // add to scene var node = new PrimitiveSceneNode(primitive, material); node.SetPickable(false); render.ShowSceneNode(node); }
public override void Run(RenderControl render) { // prepare lines data const int COUNT = 300; var buffer = new Float32Buffer(0); buffer.Reserve(COUNT * 3); var colors = new Float32Buffer(0); Random random = new Random(); for (int i = 0; i < COUNT; i++) { float x = 20 * (float)random.NextDouble() - 10; float y = 20 * (float)random.NextDouble() - 10; float z = 20 * (float)random.NextDouble() - 10; buffer.Append(x, y, z); colors.Append((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble()); } var primitive = GeometryBuilder.CreateLines(new Float32Array(buffer), null, new Float32Array(colors)); GeometryBuilder.ComputeLineDistances(primitive); // prepare dashed line material var material = LineDashedMaterial.Create("dashed-line"); // enable vertex color material.SetVertexColors(true); material.SetDashSize(1.0f); // add to scene var node = new PrimitiveSceneNode(primitive, material); render.ShowSceneNode(node); }
bool ReadData() { if (mPositions != null) { return(true); } string fileName = GetResourcePath("cloud.xyz"); using (StreamReader reader = File.OpenText(fileName)) { mPositions = new Float32Buffer(0); mColors = new Float32Buffer(0); while (!reader.EndOfStream) { var line = reader.ReadLine(); var items = line.Split(' '); if (items.Length != 6) { continue; } for (int ii = 0; ii < 3; ++ii) { mPositions.Append(float.Parse(items[ii])); } for (int ii = 3; ii < 6; ++ii) { mColors.Append(float.Parse(items[ii]) / 255.0f); } } } return(true); }