|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using g3; |
| 6 | + |
| 7 | +namespace f3 |
| 8 | +{ |
| 9 | + public class TextLabelIndicator : Indicator |
| 10 | + { |
| 11 | + fGameObject measureGO; |
| 12 | + fTextGameObject textGO; |
| 13 | + string curText = ""; |
| 14 | + |
| 15 | + public fDimension TextHeight = fDimension.Scene(1.0f); |
| 16 | + |
| 17 | + public Func<bool> VisibleF = () => { return true; }; |
| 18 | + public Func<Vector3f> ScenePositionF = () => { return Vector3f.Zero; }; |
| 19 | + public Func<string> DimensionTextF = () => { return "1.0"; }; |
| 20 | + |
| 21 | + public override fGameObject RootGameObject { get { return measureGO; } } |
| 22 | + public override bool IsVisible { get { return VisibleF(); } } |
| 23 | + public override CoordSpace InSpace { get { return CoordSpace.SceneCoords; } } |
| 24 | + |
| 25 | + public fMaterial material { |
| 26 | + get { return measureGO.GetMaterial(); } |
| 27 | + set { measureGO.SetMaterial(value); } |
| 28 | + } |
| 29 | + |
| 30 | + public TextLabelIndicator() |
| 31 | + { |
| 32 | + } |
| 33 | + |
| 34 | + public override void Setup() |
| 35 | + { |
| 36 | + measureGO = GameObjectFactory.CreateParentGO("dimension"); |
| 37 | + measureGO.SetLayer(FPlatform.WidgetOverlayLayer); |
| 38 | + |
| 39 | + textGO = GameObjectFactory.CreateTextMeshGO("text", "1.0", Colorf.Black, TextHeight.SceneValuef); |
| 40 | + UnityUtil.AddChild(measureGO, textGO, false); |
| 41 | + textGO.SetLayer(FPlatform.WidgetOverlayLayer); |
| 42 | + } |
| 43 | + |
| 44 | + public override void PreRender() |
| 45 | + { |
| 46 | + Vector3f pos = ScenePositionF(); |
| 47 | + measureGO.SetLocalPosition(pos); |
| 48 | + |
| 49 | + string sLabel = DimensionTextF(); |
| 50 | + if (curText != sLabel) { |
| 51 | + textGO.SetText(sLabel); |
| 52 | + curText = sLabel; |
| 53 | + } |
| 54 | + |
| 55 | + textGO.SetHeight(TextHeight.SceneValuef); |
| 56 | + |
| 57 | + //float r = RadiusF(); |
| 58 | + //sphereGO.SetLocalScale(r); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + public override void Destroy() { |
| 63 | + GameObjectFactory.DestroyGO(measureGO); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + public class LineIndicator : Indicator |
| 72 | + { |
| 73 | + fLineGameObject lineGO; |
| 74 | + |
| 75 | + public fDimension LineWidth = fDimension.Scene(0.1f); |
| 76 | + |
| 77 | + public Func<bool> VisibleF = () => { return true; }; |
| 78 | + public Func<Vector3f> SceneStartF = () => { return Vector3f.Zero; }; |
| 79 | + public Func<Vector3f> SceneEndF = () => { return Vector3f.AxisY; }; |
| 80 | + public Func<Colorf> ColorF = () => { return Colorf.Black; }; |
| 81 | + public Func<int> LayerF = () => { return FPlatform.WidgetOverlayLayer; }; |
| 82 | + |
| 83 | + public override fGameObject RootGameObject { get { return lineGO; } } |
| 84 | + public override bool IsVisible { get { return VisibleF(); } } |
| 85 | + public override CoordSpace InSpace { get { return CoordSpace.SceneCoords; } } |
| 86 | + |
| 87 | + public fMaterial material { |
| 88 | + get { return lineGO.GetMaterial(); } |
| 89 | + set { lineGO.SetMaterial(value); } |
| 90 | + } |
| 91 | + |
| 92 | + public LineIndicator() |
| 93 | + { |
| 94 | + } |
| 95 | + |
| 96 | + public override void Setup() |
| 97 | + { |
| 98 | + lineGO = GameObjectFactory.CreateLineGO("dimension_line", ColorF(), LineWidth.WorldValuef, LineWidthType.World); |
| 99 | + lineGO.SetLayer(LayerF()); |
| 100 | + } |
| 101 | + |
| 102 | + public override void PreRender() |
| 103 | + { |
| 104 | + lineGO.SetStart(SceneStartF()); |
| 105 | + lineGO.SetEnd(SceneEndF()); |
| 106 | + lineGO.SetColor(ColorF()); |
| 107 | + // line width is set in world units! |
| 108 | + lineGO.SetLineWidth(LineWidth.WorldValuef); |
| 109 | + lineGO.SetLayer(LayerF(), true); |
| 110 | + } |
| 111 | + |
| 112 | + |
| 113 | + public override void Destroy() { |
| 114 | + GameObjectFactory.DestroyGO(lineGO); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + public class CircleIndicator : Indicator |
| 123 | + { |
| 124 | + fCircleGameObject circleGO; |
| 125 | + |
| 126 | + public fDimension LineWidth = fDimension.Scene(0.1f); |
| 127 | + |
| 128 | + public Func<bool> VisibleF = () => { return true; }; |
| 129 | + public Func<Frame3f> SceneFrameF = () => { return Frame3f.Identity; }; |
| 130 | + public Func<float> RadiusF = () => { return 1.0f; }; |
| 131 | + public Func<Colorf> ColorF = () => { return Colorf.Black; }; |
| 132 | + |
| 133 | + |
| 134 | + public override fGameObject RootGameObject { get { return circleGO; } } |
| 135 | + public override bool IsVisible { get { return VisibleF(); } } |
| 136 | + public override CoordSpace InSpace { get { return CoordSpace.SceneCoords; } } |
| 137 | + |
| 138 | + public fMaterial material { |
| 139 | + get { return circleGO.GetMaterial(); } |
| 140 | + set { circleGO.SetMaterial(value); } |
| 141 | + } |
| 142 | + |
| 143 | + public CircleIndicator() |
| 144 | + { |
| 145 | + } |
| 146 | + |
| 147 | + public override void Setup() |
| 148 | + { |
| 149 | + circleGO = GameObjectFactory.CreateCircleGO("dimension_circle", RadiusF(), ColorF(), LineWidth.WorldValuef, LineWidthType.World); |
| 150 | + circleGO.SetLayer(FPlatform.WidgetOverlayLayer); |
| 151 | + } |
| 152 | + |
| 153 | + public override void PreRender() |
| 154 | + { |
| 155 | + Frame3f f = SceneFrameF(); |
| 156 | + circleGO.SetLocalFrame(f); |
| 157 | + |
| 158 | + circleGO.SetRadius(RadiusF()); |
| 159 | + circleGO.SetColor(ColorF()); |
| 160 | + circleGO.SetLineWidth(LineWidth.WorldValuef); |
| 161 | + } |
| 162 | + |
| 163 | + |
| 164 | + public override void Destroy() { |
| 165 | + GameObjectFactory.DestroyGO(circleGO); |
| 166 | + } |
| 167 | + } |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + public class SectionPlaneIndicator : Indicator |
| 175 | + { |
| 176 | + fGameObject planeGO; |
| 177 | + fMaterial planeMaterial; |
| 178 | + |
| 179 | + public fDimension Width = fDimension.Scene(1.0f); |
| 180 | + |
| 181 | + |
| 182 | + public Func<bool> VisibleF = () => { return true; }; |
| 183 | + public Func<Frame3f> SceneFrameF = () => { return Frame3f.Identity; }; |
| 184 | + public Func<fMaterial> MaterialF = () => { return MaterialUtil.CreateTransparentMaterialF(Colorf.Green, 0.5f); }; |
| 185 | + public Func<Colorf> ColorF = () => { return new Colorf(Colorf.LightGreen, 0.5f); }; |
| 186 | + |
| 187 | + public override fGameObject RootGameObject { get { return planeGO; } } |
| 188 | + public override bool IsVisible { get { return VisibleF(); } } |
| 189 | + public override CoordSpace InSpace { get { return CoordSpace.SceneCoords; } } |
| 190 | + |
| 191 | + public fMaterial material { |
| 192 | + get { return planeMaterial; } |
| 193 | + set { planeMaterial = value; planeGO.SetMaterial(planeMaterial); } |
| 194 | + } |
| 195 | + |
| 196 | + public SectionPlaneIndicator() |
| 197 | + { |
| 198 | + } |
| 199 | + |
| 200 | + public override void Setup() |
| 201 | + { |
| 202 | + planeGO = GameObjectFactory.CreateMeshGO("section_plane", UnityUtil.GetTwoSidedPlaneMesh(), false); |
| 203 | + planeMaterial = MaterialF(); |
| 204 | + planeGO.SetMaterial(planeMaterial); |
| 205 | + planeMaterial.color = ColorF(); |
| 206 | + MaterialUtil.DisableShadows(planeGO); |
| 207 | + //planeGO.SetLayer(FPlatform.WidgetOverlayLayer); |
| 208 | + } |
| 209 | + |
| 210 | + public override void PreRender() |
| 211 | + { |
| 212 | + Frame3f f = SceneFrameF(); |
| 213 | + planeGO.SetLocalFrame(f); |
| 214 | + planeGO.SetLocalScale( Width.SceneValuef * Vector3f.One ); |
| 215 | + planeMaterial.color = ColorF(); |
| 216 | + } |
| 217 | + |
| 218 | + |
| 219 | + public override void Destroy() { |
| 220 | + GameObjectFactory.DestroyGO(planeGO); |
| 221 | + } |
| 222 | + } |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
| 227 | + |
| 228 | + public class SphereIndicator : Indicator |
| 229 | + { |
| 230 | + fGameObject sphereGO; |
| 231 | + fMaterial sphereMaterial; |
| 232 | + |
| 233 | + public fDimension Radius = fDimension.Scene(0.2f); |
| 234 | + |
| 235 | + public Func<bool> VisibleF = () => { return true; }; |
| 236 | + public Func<Frame3f> SceneFrameF = () => { return Frame3f.Identity; }; |
| 237 | + public Func<fMaterial> MaterialF = () => { return MaterialUtil.CreateDynamicTransparencyMaterialF(Colorf.Green); }; |
| 238 | + public Func<Colorf> ColorF = () => { return Colorf.ForestGreen; }; |
| 239 | + |
| 240 | + public override fGameObject RootGameObject { get { return sphereGO; } } |
| 241 | + public override bool IsVisible { get { return VisibleF(); } } |
| 242 | + public override CoordSpace InSpace { get { return CoordSpace.SceneCoords; } } |
| 243 | + |
| 244 | + public fMaterial material { |
| 245 | + get { return sphereMaterial; } |
| 246 | + set { sphereMaterial = value; sphereGO.SetMaterial(sphereMaterial); } |
| 247 | + } |
| 248 | + |
| 249 | + public SphereIndicator() |
| 250 | + { |
| 251 | + } |
| 252 | + |
| 253 | + public override void Setup() |
| 254 | + { |
| 255 | + sphereGO = GameObjectFactory.CreateMeshGO("sphere", UnityUtil.GetSphereMesh(), false); |
| 256 | + sphereMaterial = MaterialF(); |
| 257 | + sphereGO.SetMaterial(sphereMaterial); |
| 258 | + sphereMaterial.color = ColorF(); |
| 259 | + MaterialUtil.DisableShadows(sphereGO); |
| 260 | + } |
| 261 | + |
| 262 | + public override void PreRender() |
| 263 | + { |
| 264 | + Frame3f frame = SceneFrameF(); |
| 265 | + sphereGO.SetLocalFrame(frame); |
| 266 | + sphereMaterial.color = ColorF(); |
| 267 | + sphereGO.SetLocalScale(2 * Radius.SceneValuef); |
| 268 | + } |
| 269 | + |
| 270 | + |
| 271 | + public override void Destroy() |
| 272 | + { |
| 273 | + GameObjectFactory.DestroyGO(sphereGO); |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | +} |
0 commit comments