public static string Transform(m4x4?o2w, v4?pos, bool newline = false) { return (o2w != null?Transform(o2w.Value, newline) : pos != null?Position(pos.Value, newline) : string.Empty); }
/// <summary> /// Make an orientation matrix from a direction. Note the rotation around the direction /// vector is not defined. 'axis' is the axis that 'direction' will become.</summary> public static m3x4 OriFromDir(AxisId axis, v4 dir, v4?up = null) { // Get the preferred up direction (handling parallel cases) var up_ = up == null || Parallel(up.Value, dir) ? Perpendicular(dir) : up.Value; var ori = m3x4.Identity; ori.z = Normalise(Sign(axis) * dir); ori.x = Normalise(Cross(up_, ori.z)); ori.y = Cross(ori.z, ori.x); // Permute the column vectors so +Z becomes 'axis' return(PermuteRotation(ori, Math.Abs(axis))); }
public QuadNode(string text, v4?size = null, m4x4?position = null, NodeStyle?style = null) : base(size ?? new v4(50, 50, 0, 0), Guid.NewGuid(), text, position, style) { Size = Style.AutoSize ? PreferredSize(SizeMax) : Size; // Create a texture for drawing the node content into Surf = new Surface(Size.xi, Size.yi); // Create a quad model var ldr = new LdrBuilder(); ldr.Rect("node", Colour32.White, EAxisId.PosZ, Size.x, Size.y, true, (float)Style.CornerRadius, v4.Origin); Gfx = new View3d.Object(ldr, false, null, null); Gfx.SetTexture(Surf.Surf); }
public static string Box(string name, Colour32 colour, v4 dim, m4x4?o2w = null, v4?pos = null) { return($"*Box {name} {colour} {{{dim.x} {dim.y} {dim.z} {Transform(o2w, pos)}}}\n"); }
public static string Box(string name, Colour32 colour, float size, m4x4?o2w = null, v4?pos = null) { return($"*Box {name} {colour} {{{size} {Transform(o2w, pos)}}}\n"); }
public void Box(string name, Colour32 colour, m4x4?o2w = null, v4?pos = null) { Box(name, colour, 1f, o2w, pos); }
public static string Position(v4?position, bool newline = false) { return(position != null?Position(position.Value, newline) : string.Empty); }
public LdrBuilder Cylinder(string name, Colour32 colour, AxisId axis_id, float height, float radius, m4x4?o2w = null, v4?pos = null) { return(Append("*Cylinder ", name, " ", colour, " {", height, " ", radius, " ", axis_id, " ", Ldr.Transform(o2w, pos), "}\n")); }
public LdrBuilder Box(string name, Colour32 colour, v4 dim, m4x4?o2w = null, v4?pos = null) { return(Append("*Box ", name, " ", colour, " {", dim.x, " ", dim.y, " ", dim.z, " ", Ldr.Transform(o2w, pos), "}\n")); }
public LdrBuilder Box(string name, Colour32 colour, m4x4?o2w = null, v4?pos = null) { return(Box(name, colour, 1f, o2w, pos)); }
public LdrBuilder Box(m4x4?o2w = null, v4?pos = null) { return(Box(string.Empty, Color.White, o2w, pos)); }
public static string Sphere(string name, Colour32 colour, float radius, m4x4?o2w = null, v4?pos = null) { return($"*Sphere {name} {colour} {{{radius} {Transform(o2w, pos)}}}\n"); }
/// <summary> /// Make an orientation matrix from a direction. Note the rotation around the direction /// vector is not defined. 'axis' is the axis that 'direction' will become.</summary> public static m4x4 TxfmFromDir(AxisId axis, v4 direction, v4 translation, v4?up = null) { // Notes: use 'up' = Math_.Perpendicular(direction) Debug.Assert(FEql(translation.w, 1f), "'translation' must be a position vector"); return(new m4x4(OriFromDir(axis, direction, up), translation)); }
public static void Mesh(this LdrBuilder ldr, string name, Colour32 colour, View3d.EGeom geom, IList <View3d.Vertex> verts, IList <ushort>?faces = null, IList <ushort>?lines = null, IList <ushort>?tetra = null, bool generate_normals = false, v4?position = null) { ldr.Append("*Mesh ", name, " ", colour, " {\n"); if ((geom & View3d.EGeom.Vert) != 0) { ldr.Append("*Verts {").Append(verts.Select(x => Ldr.Vec3(x.m_pos))).Append("}\n"); } if ((geom & View3d.EGeom.Norm) != 0) { ldr.Append("*Normals {").Append(verts.Select(x => Ldr.Vec3(x.m_norm))).Append("}\n"); } if ((geom & View3d.EGeom.Colr) != 0) { ldr.Append("*Colours {").Append(verts.Select(x => Ldr.Colour(x.m_col))).Append("}\n"); } if ((geom & View3d.EGeom.Tex0) != 0) { ldr.Append("*TexCoords {").Append(verts.Select(x => Ldr.Vec2(x.m_uv))).Append("}\n"); } if (faces != null) { Debug.Assert(faces.All(i => i >= 0 && i < verts.Count)); ldr.Append("*Faces {").Append(faces).Append("}\n"); } if (lines != null) { Debug.Assert(lines.All(i => i >= 0 && i < verts.Count)); ldr.Append("*Lines {").Append(lines).Append("}\n"); } if (tetra != null) { Debug.Assert(tetra.All(i => i >= 0 && i < verts.Count)); ldr.Append("*Tetra {").Append(tetra).Append("}\n"); } if (generate_normals) { ldr.Append("*GenerateNormals\n"); } if (position != null) { ldr.Append(Ldr.Position(position.Value)); } ldr.Append("}\n"); }
public Light(Colour32 ambient, Colour32 diffuse, Colour32 specular, double spec_power = 1000.0, v4?direction = null, v4?position = null) : this( direction != null ? LightInfo.Directional(direction.Value, ambient, diffuse, specular, (float)spec_power, 0) : position != null ? LightInfo.Point(position.Value, ambient, diffuse, specular, (float)spec_power, 0) : LightInfo.Ambient(ambient)) { }
public void Cylinder(Colour32 colour, AxisId axis_id, float height, float radius, m4x4?o2w = null, v4?pos = null) { Cylinder(string.Empty, colour, axis_id, height, radius, o2w, pos); }
public void Box(string name, Colour32 colour, v4 dim, m4x4?o2w = null, v4?pos = null) { Append("*Box ", name, " ", colour, " {", dim.x, " ", dim.y, " ", dim.z, " ", Ldr.Transform(o2w, pos), "}\n"); }
public void Box(string name, Colour32 colour, float size, m4x4?o2w = null, v4?pos = null) { Append("*Box ", name, " ", colour, " {", size, " ", Ldr.Transform(o2w, pos), "}\n"); }
public static string Grid(string name, Colour32 colour, float dimx, float dimy, int divx, int divy, m4x4?o2w = null, v4?pos = null) { return($"*GridWH {name} {colour} {{{dimx} {dimy} {divx} {divy} {Transform(o2w, pos)}}}\n"); }
public static string GroupEnd(m4x4?o2w = null, v4?pos = null) { return($"{Transform(o2w, pos, newline:true)}}}\n"); }
public LdrBuilder Box(Colour32 colour, float sx, float sy, float sz, m4x4?o2w = null, v4?pos = null) { return(Box(string.Empty, colour, sx, sy, sz, o2w, pos)); }
public static string Line(string name, Colour32 colour, v4 start, v4 end, m4x4?o2w = null, v4?pos = null) { return($"*Line {name} {colour} {{{Vec3(start)} {Vec3(end)} {Transform(o2w, pos)}}}\n"); }
public LdrBuilder Box(string name, Colour32 colour, float sx, float sy, float sz, m4x4?o2w = null, v4?pos = null) { return(Append("*Box ", name, " ", colour, " {", sx, " ", sy, " ", sz, " ", Ldr.Transform(o2w, pos), "}\n")); }
public static string LineD(string name, Colour32 colour, v4 start, v4 direction, m4x4?o2w = null, v4?pos = null) { return($"*LineD {name} {colour} {{{Vec3(start)} {Vec3(direction)} {Transform(o2w, pos)}}}\n"); }
public LdrBuilder Cylinder(Colour32 colour, AxisId axis_id, float height, float radius, m4x4?o2w = null, v4?pos = null) { return(Cylinder(string.Empty, colour, axis_id, height, radius, o2w, pos)); }
public static string LineStrip(string name, Colour32 colour, int width, IEnumerable <v4> points, m4x4?o2w = null, v4?pos = null) { var w = Width(width); var pts = points.Select(x => " " + Vec3(x)); return($"*LineStrip {name} {colour} {{{w} {pts} {Transform(o2w, pos)}}}"); }
public LdrBuilder Mesh(string name, Colour32 colour, IList <v4>?verts, IList <v4>?normals = null, IList <Colour32>?colours = null, IList <v2>?tex = null, IList <ushort>?faces = null, IList <ushort>?lines = null, IList <ushort>?tetra = null, bool generate_normals = false, v4?position = null) { Append("*Mesh ", name, " ", colour, " {\n"); if (verts != null) { Append("*Verts {").Append(verts.Select(x => Ldr.Vec3(x))).Append("}\n"); } if (normals != null) { Append("*Normals {").Append(normals.Select(x => Ldr.Vec3(x))).Append("}\n"); } if (colours != null) { Append("*Colours {").Append(colours.Select(x => Ldr.Colour(x))).Append("}\n"); } if (tex != null) { Append("*TexCoords {").Append(tex.Select(x => Ldr.Vec2(x))).Append("}\n"); } if (verts != null && faces != null) { Debug.Assert(faces.All(i => i >= 0 && i < verts.Count)); Append("*Faces {").Append(faces).Append("}\n"); } if (verts != null && lines != null) { Debug.Assert(lines.All(i => i >= 0 && i < verts.Count)); Append("*Lines {").Append(lines).Append("}\n"); } if (verts != null && tetra != null) { Debug.Assert(tetra.All(i => i >= 0 && i < verts.Count)); Append("*Tetra {").Append(tetra).Append("}\n"); } if (generate_normals) { Append("*GenerateNormals\n"); } if (position != null) { Append(Ldr.Position(position.Value)); } Append("}\n"); return(this); }
public static string Ellipse(string name, Colour32 colour, AxisId axis_id, float rx, float ry, m4x4?o2w = null, v4?pos = null) { return($"*Ellipse {name} {colour} {{{rx} {ry} {AxisId(axis_id)} {Transform(o2w, pos)}}}\n"); }
public static string Rect(string name, Colour32 colour, AxisId axis_id, float w, float h, bool solid, m4x4?o2w = null, v4?pos = null) { return($"*Rect {name} {colour} {{{w} {h} {AxisId(axis_id)} {Solid(solid)} {Transform(o2w, pos)}}}\n"); }
public void Box(Colour32 colour, float sx, float sy, float sz, m4x4?o2w = null, v4?pos = null) { Box(string.Empty, colour, sx, sy, sz, o2w, pos); }