public static PointSet CreateFromVertexSet(List <Vertex> verticies) { PointSet ps; Coordinate coord; Color colors; Vector3[] points; ps = new PointSet(); coord = new Coordinate(); colors = new Color(); points = verticies.Select(v => v.Position).ToArray(); colors.color = X3DTypeConverters.ToString(verticies.Select(v => v.Color.Xyz).ToArray()); coord.point = X3DTypeConverters.ToString(points); coord.Parent = ps; colors.Parent = ps; ps.Children.Add(colors); ps.Children.Add(coord); ps.PrimativeType = PrimitiveType.Points; return(ps); }
public static IndexedLineSet CreateFromVertexSet(List <Vertex> verticies) { IndexedLineSet ils; Coordinate coord; Vector3[] points; int[] indicies; int i; ils = new IndexedLineSet(); coord = new Coordinate(); points = verticies.Select(v => v.Position).ToArray(); i = -1; indicies = verticies.Select(v => ++ i).ToArray(); coord.point = X3DTypeConverters.ToString(points); ils.coordIndex = X3DTypeConverters.ToString(indicies); ils.Children.Add(coord); ils.PrimativeType = PrimitiveType.Lines; return(ils); }
public ElevationGrid BuildVaryingHeightMap(int xDimension, int zDimension, float xSpacing, float zSpacing, bool colorPerVertex, ElevationColorSequencerDelegate colorSequencer, HeightComputationDelegate geometrySequencer) { ElevationGrid g = new ElevationGrid(); Color colorNode = new Color(); int numHeights = xDimension * zDimension; int faceIndex = 0; Vector3 color; int coordIndex = 0; g.colorPerVertex = colorPerVertex; g.xDimension = xDimension.ToString(); g.zDimension = zDimension.ToString(); g.xSpacing = xSpacing; g.zSpacing = zSpacing; g.height = string.Empty; colorNode.color = string.Empty; Console.WriteLine("Building varying height map (this could take a while)"); for (int x = 0; x < xDimension; x++) { for (int z = 0; z < zDimension; z++) { if (coordIndex % 4 == 0 && coordIndex > 0) { faceIndex++; } g.height += string.Format(" {0}", geometrySequencer(x, z)); if (colorSequencer != null) { color = colorSequencer(faceIndex, coordIndex, x, z); colorNode.color += X3DTypeConverters.ToString(color) + ", "; } updateProgress(coordIndex, numHeights); coordIndex++; } } colorNode.color = colorNode.color.TrimStart(); colorNode.color = colorNode.color.Substring(0, colorNode.color.Length - 2); g.height = g.height.TrimStart(); g.Children.Add(colorNode); return(g); }
public string ToFriendlyString() { return(string.Format( "Material <ambientIntensity=\"{0}\", diffuse=\"{1}\", emissive=\"{2}\", shininess=\"{3}\", specular=\"{4}\", transparency=\"{5}\">", ambientIntensity, X3DTypeConverters.ToString(this._diffuseColor), X3DTypeConverters.ToString(this._emissiveColor), this._shininess, X3DTypeConverters.ToString(this._specularColor), this._transparency )); }
/// <summary> /// Updates the field with a new value just in the SceneGraph. /// (Changes in the field are picked up by a currrently running X3DProgrammableShaderObject) /// </summary> public void setFieldValue(string name, object value) { field field = (field)this.Children .FirstOrDefault(n => n.GetType() == typeof(field) && n.getAttribute("name").ToString() == name); Type type; object convValue; Type conv; try { type = X3DTypeConverters.X3DSimpleTypeToManagedType(field.type); convValue = Convert.ChangeType(value, type); conv = convValue.GetType(); if (conv == typeof(int)) { UpdateField(name, X3DTypeConverters.ToString((int)convValue)); } if (conv == typeof(float)) { UpdateField(name, X3DTypeConverters.ToString((float)convValue)); } if (conv == typeof(Vector3)) { UpdateField(name, X3DTypeConverters.ToString((Vector3)convValue)); } if (conv == typeof(Vector4)) { UpdateField(name, X3DTypeConverters.ToString((Vector4)convValue)); } if (conv == typeof(Matrix3)) { UpdateField(name, X3DTypeConverters.ToString((Matrix3)convValue)); } if (conv == typeof(Matrix4)) { UpdateField(name, X3DTypeConverters.ToString((Matrix4)convValue)); } } catch { Console.WriteLine("error"); } }
public static LineSet CreateFromVertexSet(List<Vertex> verticies, int vertexStride) { LineSet ils; Coordinate coord; Vector3[] points; int[] indicies; int i; ils = new LineSet(); coord = new Coordinate(); points = verticies.Select(v => v.Position).ToArray(); i = -1; indicies = verticies.Select(v => ++i).ToArray(); coord.point = X3DTypeConverters.ToString(points); ils.vertexCount = vertexStride; ils.Children.Add(coord); ils.PrimativeType = PrimitiveType.LineLoop; return ils; }
public ElevationGrid BuildHeightmapFromTexture( float xSpacing, float zSpacing, Bitmap texture, float maxHeight = 1.0f) { ElevationGrid g = new ElevationGrid(); Color colorNode = new Color(); int xDimension, zDimension; int numHeights; int faceIndex = 0; int coordIndex = 0; float height; System.Drawing.Color color; Vector3 vColor; Vector3 vNTSCConversionWeight; float grayscale; g.colorPerVertex = true; g.xSpacing = xSpacing; g.zSpacing = zSpacing; g.height = string.Empty; colorNode.color = string.Empty; xDimension = texture.Width; zDimension = texture.Height; numHeights = xDimension * zDimension; g.xDimension = xDimension.ToString(); g.zDimension = zDimension.ToString(); Console.WriteLine("Building height map from texture (this could take a while)"); for (int x = 0; x < xDimension; x++) { for (int z = 0; z < zDimension; z++) { if (coordIndex % 4 == 0 && coordIndex > 0) { faceIndex++; } color = texture.GetPixel(x, z); // Convert to grayscale using NTSC conversion weights vColor = new Vector3(color.R / 255f, color.G / 255f, color.B / 255f); vNTSCConversionWeight = new Vector3(0.299f, 0.587f, 0.114f); grayscale = Vector3.Dot(vColor, vNTSCConversionWeight); // Convert color to height value height = (float)(grayscale) * maxHeight; g.height += string.Format(" {0}", height); colorNode.color += X3DTypeConverters.ToString(vColor) + ", "; updateProgress(coordIndex, numHeights); coordIndex++; } } colorNode.color = colorNode.color.Trim(); colorNode.color = colorNode.color.Substring(0, colorNode.color.Length - 2); g.height = g.height.TrimStart(); g.Children.Add(colorNode); return(g); }