Beispiel #1
0
 public virtual void Initialize(GameObject go, fMesh mesh, float radiusIn = 1)
 {
     base.Initialize(go, mesh, FGOFlags.EnablePreRender);
     radius     = radiusIn;
     bDiscValid = false;
     SetLocalScale(new Vector3f(radius, 1, radius));
 }
Beispiel #2
0
 public fDiscGameObject(GameObject go, fMesh mesh, float radiusIn = 1)
     : base(go, mesh, FGOFlags.EnablePreRender)
 {
     radius     = radiusIn;
     bDiscValid = false;
     SetLocalScale(new Vector3f(radius, 1, radius));
 }
Beispiel #3
0
        void create_sub_items(MenuItem topItem, float fParentRadius, float fParentAngleMin, float fParentAngleMax)
        {
            float fInnerRadius = fParentRadius + SubItemRadialPadding;
            float fOuterRadius = fInnerRadius + SubItemRadialWidth;

            int nItems = topItem.SubItems.Count;
            //float fParentAngleSpan = fParentAngleMax - fParentAngleMin;
            float fParentAngleMid = 0.5f * (fParentAngleMax + fParentAngleMin);
            //float fSubMenuSpan = 180.0f - (WedgePadding * (float)(nItems-1));
            //float fWedgeSpan = fSubMenuSpan / (float)nItems;
            float fWedgeSpan      = 45.0f;
            float fSubMenuSpan    = nItems * fWedgeSpan + (float)(nItems - 1) * WedgePadding;
            int   nSlicesPerWedge = 16;

            float fCurAngle = fParentAngleMid - fSubMenuSpan * 0.5f;

            for (int i = 0; i < nItems; ++i)
            {
                MenuItem item = topItem.SubItems[i];
                fMesh    m    = MeshGenerators.CreatePuncturedDisc(fInnerRadius, fOuterRadius, nSlicesPerWedge,
                                                                   fCurAngle, fCurAngle + fWedgeSpan);

                float   fMidAngleRad = (fCurAngle + fWedgeSpan * 0.5f) * Mathf.Deg2Rad;
                Vector2 vMid         = new Vector2(Mathf.Cos(fMidAngleRad), Mathf.Sin(fMidAngleRad));

                GameObject itemGO = AppendMeshGO(item.Label, m, itemMaterial, menuContainer);
                itemGO.transform.Rotate(Vector3.right, -90.0f); // ??
                topItem.SubItems[i].GO = itemGO;

                // [TODO] this is to improve font centering. Right now we do absolute centering
                //   but visually this looks wrong because weight of font is below center-y.
                //   Right thing would be to align at top of lowercase letters, rather than center-y
                //   (to fix in future)
                float fudge = 0.0f;
                if (nItems == 2 && i == 1)
                {
                    fudge = -0.1f;
                }

                TextLabelGenerator textGen = new TextLabelGenerator()
                {
                    Text      = item.Label, Scale = SubItemTextScale,
                    Translate = vMid * (fInnerRadius + (TextCenterPointFactor + fudge) * SubItemRadialWidth),
                    Align     = TextLabelGenerator.Alignment.HVCenter
                };
                List <fGameObject> vTextElems = textGen.Generate();
                AddVisualElements(vTextElems, true);
                // actually want these GOs to be parented to itemGO
                UnityUtil.AddChildren(itemGO, vTextElems, true);

                itemGO.SetVisible(false);

                if (item.SubItems != null)
                {
                    create_sub_items(item, fOuterRadius, fCurAngle, fCurAngle + fWedgeSpan);
                }

                fCurAngle += WedgePadding + fWedgeSpan;
            }
        }
Beispiel #4
0
        public static fMeshGameObject CreateMeshGO(string sName, fMesh mesh, bool bCollider = false, bool bShared = false)
        {
            GameObject go = new GameObject(sName);

            initialize_meshgo(go, mesh, bCollider, bShared);
            return(new fMeshGameObject(go, new fMesh(go.GetSharedMesh())));
        }
Beispiel #5
0
 public fRingGameObject(GameObject go, fMesh mesh, float outerRad = 1, float innerRad = 0.5f)
     : base(go, mesh, FGOFlags.EnablePreRender)
 {
     outerRadius = outerRad;
     innerRadius = innerRad;
     bDiscValid  = false;
     SetLocalScale(Vector3f.One);
 }
Beispiel #6
0
 public virtual void Initialize(GameObject go, fMesh mesh, float outerRad = 1, float innerRad = 0.5f)
 {
     base.Initialize(go, mesh, FGOFlags.EnablePreRender);
     outerRadius = outerRad;
     innerRadius = innerRad;
     bDiscValid  = false;
     SetLocalScale(Vector3f.One);
 }
Beispiel #7
0
 public fBoxGameObject(GameObject go, fMesh mesh, float widthIn = 1, float heightIn = 1, float depthIn = 1) : base(go, mesh)
 {
     width     = widthIn;
     height    = heightIn;
     depth     = depthIn;
     bBoxValid = false;
     SetLocalScale(new Vector3f(width, height, depth));
 }
Beispiel #8
0
 public virtual void Initialize(GameObject go, fMesh mesh, float widthIn = 1, float heightIn = 1, float depthIn = 1)
 {
     base.Initialize(go, mesh, FGOFlags.EnablePreRender);
     width     = widthIn;
     height    = heightIn;
     depth     = depthIn;
     bBoxValid = false;
     SetLocalScale(new Vector3f(width, height, depth));
 }
        public static fDiscGameObject CreateDiscGO(string sName, float fRadius, fMaterial material, bool bShareMaterial, bool bCollider)
        {
            GameObject go       = new GameObject(sName);
            fMesh      discMesh = PrimitiveCache.GetPrimitiveMesh(fPrimitiveType.Disc);

            initialize_meshgo(go, discMesh, bCollider, true);
            go.SetMaterial(material, bShareMaterial);
            return(new fDiscGameObject(go, new fMesh(go.GetSharedMesh()), fRadius));
        }
        public static fRingGameObject CreateRingGO(string sName, float fInnerRadius, float fOuterRadius, fMaterial material, bool bShareMaterial, bool bCollider)
        {
            GameObject go       = new GameObject(sName);
            fMesh      ringMesh = MeshGenerators.CreatePuncturedDisc(fInnerRadius, fOuterRadius, 32);

            initialize_meshgo(go, ringMesh, bCollider, true);
            go.SetMaterial(material, bShareMaterial);
            return(new fRingGameObject(go, new fMesh(go.GetSharedMesh()), fOuterRadius, fInnerRadius));
        }
Beispiel #11
0
        // creates a button that is just the mesh
        public void Create(fMesh mesh, fMaterial meshMaterial, float fScale, Quaternionf transform)
        {
            button = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDButton"));

            iconMesh = AppendMeshGO("shape", mesh, meshMaterial, button);
            iconMesh.SetLocalScale(new Vector3f(fScale, fScale, fScale));
            iconMesh.SetLocalRotation(iconMesh.GetLocalRotation() * transform);
            MaterialUtil.DisableShadows(iconMesh);

            standard_mat = new fMaterial(meshMaterial);
        }
Beispiel #12
0
        public override void PreRender()
        {
            if (bBoxValid)
            {
                return;
            }

            fMesh newMesh = PrimitiveCache.GetPrimitiveMesh(fPrimitiveType.Box);

            UpdateMesh(newMesh, true, true);
            bBoxValid = true;
        }
Beispiel #13
0
        // creates a button that is just the mesh
        public void Create(fMesh mesh, Material meshMaterial, float fScale, Quaternion transform)
        {
            button = new GameObject(UniqueNames.GetNext("HUDButton"));

            GameObject meshGO = AppendMeshGO("shape", mesh, meshMaterial, button);

            meshGO.transform.localScale     = new Vector3(fScale, fScale, fScale);
            meshGO.transform.localRotation *= transform;
            MaterialUtil.DisableShadows(meshGO);

            standard_mat = new fMaterial(meshMaterial);
        }
Beispiel #14
0
 public void UpdateMesh(fMesh m, bool bShared, bool bUpdateCollider)
 {
     if (bShared)
     {
         Mesh = m;
         base.SetSharedMesh(m, bUpdateCollider);
     }
     else
     {
         base.SetMesh(m, bUpdateCollider);
         Mesh = new fMesh(base.GetSharedMesh());
     }
 }
Beispiel #15
0
        public void AddComponent(MeshDecomposition.Component C)
        {
            fMesh           submesh    = new fMesh(C.triangles, mesh, C.source_vertices, true, true);
            fMeshGameObject submesh_go = GameObjectFactory.CreateMeshGO("component", submesh, false);

            submesh_go.SetMaterial(new fMaterial(CurrentMaterial));
            displayComponents.Add(new DisplayMeshComponent()
            {
                go = submesh_go, source_vertices = C.source_vertices
            });

            AppendNewGO(submesh_go, parentGO, false);
        }
Beispiel #16
0
        public virtual fMeshGameObject AppendMeshGO(string name, fMesh mesh, fMaterial setMaterial, fGameObject parent, bool bCollider = true)
        {
            fMeshGameObject go = new fMeshGameObject(mesh, true, bCollider);

            go.EnableCollisions = false;
            go.SetMaterial(setMaterial);
            go.SetName(name);

            vObjects.Add(go);

            parent.AddChild(go);
            go.SetLayer(parent.GetLayer());

            return(go);
        }
        // create a subclass of fDiscGameObject
        public static T CreateDiscTypeGO <T>(string sName, float fRadius, fMaterial material, bool bShareMaterial, bool bCollider)
            where T : fDiscGameObject, new()
        {
            GameObject go       = new GameObject(sName);
            fMesh      discMesh = PrimitiveCache.GetPrimitiveMesh(fPrimitiveType.Disc);

            initialize_meshgo(go, discMesh, bCollider, true);
            go.SetMaterial(material, bShareMaterial);
            T fgo = new T();

            fgo.Initialize(go, new fMesh(go.GetSharedMesh()), fRadius);
            return(fgo);
            // this lets us do it w/o new()/Initialize, however currently it means that subclass
            // must implement the constructor that takes GameObject...
            //return (T)Activator.CreateInstance(typeof(T), go, new fMesh(go.GetSharedMesh()), fRadius);
        }
Beispiel #18
0
        // creates a button with a background shape and a foreground mesh
        public void Create(fMaterial bgMaterial, fMesh mesh, fMaterial meshMaterial, float fScale, Frame3f deltaF)
        {
            button = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDButton"));

            buttonMesh = AppendMeshGO("shape", HUDUtil.MakeBackgroundMesh(this.Shape), bgMaterial, button);
            buttonMesh.RotateD(Vector3f.AxisX, -90.0f); // ??
            MaterialUtil.DisableShadows(buttonMesh);

            iconMesh = AppendMeshGO("shape", mesh, meshMaterial, button);
            iconMesh.SetLocalScale(new Vector3f(fScale, fScale, fScale));
            iconMesh.SetLocalPosition(deltaF.Origin);
            iconMesh.SetLocalRotation(deltaF.Rotation);
            MaterialUtil.DisableShadows(iconMesh);

            standard_mat = new fMaterial(bgMaterial);
        }
Beispiel #19
0
 public fMeshGameObject(fMesh mesh, bool bCreate = true, bool bAddCollider = false) : base()
 {
     Mesh = mesh;
     if (bCreate)
     {
         GameObject go = new GameObject();
         go.AddComponent <MeshFilter>();
         go.AddComponent <MeshRenderer>();
         if (bAddCollider)
         {
             go.AddComponent <MeshCollider>();
         }
         Initialize(go, FGOFlags.NoFlags);
         UpdateMesh(Mesh, true, bAddCollider);
     }
 }
Beispiel #20
0
        public void AddComponent(MeshDecomposition.Component C)
        {
            fMesh           submesh    = new fMesh(C.triangles, mesh, C.source_vertices, true, true, true);
            fMeshGameObject submesh_go = GameObjectFactory.CreateMeshGO("component", submesh, true);

            submesh_go.SetMaterial(SourceSO.CurrentMaterial, true);
            submesh_go.SetLayer(SourceSO.RootGameObject.GetLayer());
            displayComponents.Add(new DisplayMeshComponent()
            {
                go = submesh_go, source_vertices = C.source_vertices
            });
            if (SourceSO.ShadowsEnabled == false)
            {
                MaterialUtil.DisableShadows(submesh_go, true, true);
            }
            SourceSO.AppendNewGO(submesh_go, SourceSO.RootGameObject, false);
        }
Beispiel #21
0
        // creates a button with a background shape and a foreground mesh
        public void Create(Material bgMaterial, fMesh mesh, Material meshMaterial, float fScale, Frame3f deltaF)
        {
            button = new GameObject(UniqueNames.GetNext("HUDButton"));

            buttonMesh = AppendMeshGO("shape", HUDUtil.MakeBackgroundMesh(this.Shape), bgMaterial, button);
            buttonMesh.transform.Rotate(Vector3.right, -90.0f); // ??
            MaterialUtil.DisableShadows(buttonMesh);

            GameObject meshGO = AppendMeshGO("shape", mesh, meshMaterial, button);

            meshGO.transform.localScale    = new Vector3(fScale, fScale, fScale);
            meshGO.transform.localPosition = deltaF.Origin;
            meshGO.transform.localRotation = deltaF.Rotation;
            MaterialUtil.DisableShadows(meshGO);

            standard_mat = new fMaterial(bgMaterial);
        }
Beispiel #22
0
        public override void PreRender()
        {
            if (bDiscValid)
            {
                return;
            }

            TrivialDiscGenerator discGen = new TrivialDiscGenerator()
            {
                StartAngleDeg = startAngleDeg, EndAngleDeg = endAngleDeg, Clockwise = false
            };

            discGen.Generate();
            fMesh newMesh = new fMesh(discGen.MakeUnityMesh());

            UpdateMesh(newMesh, true, true);

            bDiscValid = true;
        }
Beispiel #23
0
        public virtual void ValidateViewMeshes()
        {
            if (decomp_valid)
            {
                return;
            }

            fMesh unityMesh = UnityUtil.DMeshToUnityMesh(mesh, false, true);

            viewMeshGO = GameObjectFactory.CreateMeshGO("component", unityMesh, false, true);
            viewMeshGO.SetMaterial(SourceSO.CurrentMaterial, true);
            viewMeshGO.SetLayer(SourceSO.RootGameObject.GetLayer());
            if (SourceSO.ShadowsEnabled == false)
            {
                MaterialUtil.DisableShadows(viewMeshGO, true, true);
            }
            SourceSO.AppendNewGO(viewMeshGO, SourceSO.RootGameObject, false);

            decomp_valid = true;
        }
Beispiel #24
0
        public List <fGameObject> Generate()
        {
            fMesh           mesh    = FResources.LoadMesh(Path);
            fMeshGameObject fMeshGO = GameObjectFactory.CreateMeshGO("iconMesh", mesh, false, true);

            fMeshGO.SetMaterial(MaterialUtil.CreateStandardMaterial(this.Color), true);

            // apply orientation
            fMeshGO.SetLocalScale(new Vector3f(Scale, Scale, Scale));
            fMeshGO.SetLocalPosition(fMeshGO.GetLocalPosition() + Translate);
            fMeshGO.SetLocalRotation(Rotate);

            // ignore material changes when we add to GameObjectSet
            fMeshGO.AddComponent <IgnoreMaterialChanges>();

            return(new List <fGameObject>()
            {
                fMeshGO
            });
        }
Beispiel #25
0
        public override void PreRender()
        {
            if (bDiscValid)
            {
                return;
            }

            PuncturedDiscGenerator discGen = new PuncturedDiscGenerator()
            {
                OuterRadius   = outerRadius, InnerRadius = innerRadius,
                StartAngleDeg = startAngleDeg, EndAngleDeg = endAngleDeg, Clockwise = false
            };

            discGen.Generate();
            fMesh newMesh = new fMesh(discGen.MakeUnityMesh());

            UpdateMesh(newMesh, true, true);

            bDiscValid = true;
        }
Beispiel #26
0
        public static HUDButton CreateMeshClickButton(
            fMesh mesh, Color color, float fMeshScale, Quaternion meshRotation,
            float fHUDRadius, float fAngleHorz, float fAngleVert,
            IGameObjectGenerator addGeometry = null)
        {
            Material mat = (color.a < 1.0f) ?
                           MaterialUtil.CreateTransparentMaterial(color, color.a) :
                           MaterialUtil.CreateStandardMaterial(color);

            HUDButton button = new HUDButton();

            button.Create(mesh, mat, fMeshScale, meshRotation);

            if (addGeometry != null)
            {
                button.AddVisualElements(addGeometry.Generate(), true);
            }
            HUDUtil.PlaceInSphere(button, fHUDRadius, fAngleHorz, fAngleVert);
            return(button);
        }
Beispiel #27
0
        public static HUDButton CreateMeshClickButton(
            fMesh mesh, Color color, float fMeshScale, Quaternion meshRotation,
            HUDSurface hudSurf, float dx, float dy,
            IGameObjectGenerator addGeometry = null)
        {
            Material mat = (color.a < 1.0f) ?
                           MaterialUtil.CreateTransparentMaterial(color, color.a) :
                           MaterialUtil.CreateStandardMaterial(color);

            HUDButton button = new HUDButton();

            button.Create(mesh, mat, fMeshScale, meshRotation);

            if (addGeometry != null)
            {
                button.AddVisualElements(addGeometry.Generate(), true);
            }
            hudSurf.Place(button, dx, dy);
            return(button);
        }
Beispiel #28
0
 static void initialize_meshgo(GameObject go, fMesh mesh, bool bCollider, bool bShared)
 {
     go.AddComponent <MeshFilter>();
     if (mesh != null)
     {
         if (bShared)
         {
             go.SetSharedMesh(mesh);
         }
         else
         {
             go.SetMesh(mesh);
         }
     }
     go.AddComponent <MeshRenderer>();
     if (bCollider)
     {
         var collider = go.AddComponent <MeshCollider>();
         collider.enabled = false;
     }
 }
Beispiel #29
0
        // creates a button with a floating primitive in front of the button shape
        public void CreateMeshIconButton(float fRadius, string sMeshPath, Material bgMaterial,
                                         float fMeshScaleFudge)
        {
            Shape = new HUDShape(HUDShapeType.Disc, fRadius);

            fMesh    iconmesh     = null;
            Material meshMaterial = null;

            try {
                iconmesh     = FResources.LoadMesh(sMeshPath);
                meshMaterial = MaterialUtil.CreateStandardVertexColorMaterial(Color.white);
            } catch { }
            if (iconmesh == null)
            {
                iconmesh     = UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere);
                meshMaterial = MaterialUtil.CreateStandardMaterial(Color.red);
            }

            float fMeshRadius = fRadius * fMeshScaleFudge;

            base.Create(bgMaterial, iconmesh, meshMaterial, fMeshRadius,
                        Frame3f.Identity.Translated(-fMeshRadius * 0.25f, 2).Rotated(-15.0f, 1));
        }
Beispiel #30
0
        // creates a button in the desired geometry shape
        public void Create()
        {
            entry = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDTextEntry"));
            fMesh mesh = MeshGenerators.CreateTrivialRect(Width, Height, MeshGenerators.UVRegionType.FullUVSquare);

            backgroundMaterial       = MaterialUtil.CreateFlatMaterialF(BackgroundColor);
            activeBackgroundMaterial = MaterialUtil.CreateFlatMaterialF(ActiveBackgroundColor);
            bgMesh = AppendMeshGO("background", mesh, backgroundMaterial, entry);
            bgMesh.RotateD(Vector3f.AxisX, -90.0f); // ??

            BoxPosition horzAlign = BoxPosition.CenterLeft;

            if (AlignmentHorz == HorizontalAlignment.Center)
            {
                horzAlign = BoxPosition.Center;
            }
            else if (AlignmentHorz == HorizontalAlignment.Right)
            {
                horzAlign = BoxPosition.CenterRight;
            }

            textMesh = GameObjectFactory.CreateTextMeshGO(
                "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset);

            Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign);

            BoxModel.Translate(textMesh, Vector2f.Zero, toPos);

            AppendNewGO(textMesh, entry, false);

            cursor = GameObjectFactory.CreateRectangleGO("cursor", Height * 0.1f, Height * 0.8f, Colorf.VideoBlack, false);
            BoxModel.Translate(cursor, Vector2f.Zero, this.Bounds2D.CenterLeft, -Height * 0.1f);
            cursor.RotateD(Vector3f.AxisX, -90.0f);
            AppendNewGO(cursor, entry, false);
            cursor.SetVisible(false);
        }