コード例 #1
0
 public void OnResourceLoaded(IResourceHandle handle)
 {
     if (Resource != null && Resource.TryLock())
     {
         CreateSubmeshes();
         OnWorldMatrixChanged();
         Renderer.AddBackgroundUploadTask((d, cl) =>
         {
             if (Submeshes != null && Resource.TryLock())
             {
                 foreach (var sm in Submeshes)
                 {
                     sm.CreateDeviceObjects(d, cl, null);
                 }
                 if (AutoRegister)
                 {
                     RegisterWithScene(RenderScene);
                 }
                 Created = true;
                 Resource.Unlock();
             }
         });
         Resource.Unlock();
     }
 }
コード例 #2
0
 public void FillBuffer(IntPtr data, uint size, Action completionHandler)
 {
     Renderer.AddBackgroundUploadTask((device, cl) =>
     {
         cl.UpdateBuffer(_allocator._backingBuffer, AllocationStart, data, size);
         completionHandler.Invoke();
     });
 }
コード例 #3
0
 public void FillBuffer <T>(T data, Action completionHandler = null) where T : struct
 {
     Renderer.AddBackgroundUploadTask((device, cl) =>
     {
         cl.UpdateBuffer(_allocator._backingBuffer, AllocationStart, ref data);
         if (completionHandler != null)
         {
             completionHandler.Invoke();
         }
     });
 }
コード例 #4
0
        public DbgPrimGizmoTranslateSquare(MsbEditor.Gizmos.Axis axis)
        {
            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 a, b, c, d;
                switch (axis)
                {
                case MsbEditor.Gizmos.Axis.PosX:
                    a = new Vector3(0.0f, StartOffset, StartOffset);
                    b = new Vector3(0.0f, StartOffset + Length, StartOffset);
                    c = new Vector3(0.0f, StartOffset, StartOffset + Length);
                    d = new Vector3(0.0f, StartOffset + Length, StartOffset + Length);
                    break;

                case MsbEditor.Gizmos.Axis.PosY:
                    a = new Vector3(StartOffset, 0.0f, StartOffset);
                    b = new Vector3(StartOffset + Length, 0.0f, StartOffset);
                    c = new Vector3(StartOffset, 0.0f, StartOffset + Length);
                    d = new Vector3(StartOffset + Length, 0.0f, StartOffset + Length);
                    break;

                case MsbEditor.Gizmos.Axis.PosZ:
                    a = new Vector3(StartOffset, StartOffset, 0.0f);
                    b = new Vector3(StartOffset + Length, StartOffset, 0.0f);
                    c = new Vector3(StartOffset, StartOffset + Length, 0.0f);
                    d = new Vector3(StartOffset + Length, StartOffset + Length, 0.0f);
                    break;

                default:
                    throw new ArgumentException("Select valid axis");
                }

                var color = Color.FromArgb(0x86, 0xC8, 0x15);
                AddQuad(a, b, d, c, color);
                AddColQuad(Tris, a, b, d, c);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };

                Renderer.AddBackgroundUploadTask((d, cl) =>
                {
                    UpdatePerFrameResources(d, cl, null);
                });
            }
        }
コード例 #5
0
        public DbgPrimGizmoTranslateArrow(MsbEditor.Gizmos.Axis axis)
        {
            if (GeometryData != null)
            {
                SetBuffers(GeometryData.GeomBuffer);
            }
            else
            {
                Vector3 GetPoint(MsbEditor.Gizmos.Axis axis, int segmentIndex, float radius, float depth)
                {
                    float horizontalAngle = (1.0f * segmentIndex / Segments) * Utils.Pi * 2.0f;
                    float x = (float)Math.Cos(horizontalAngle);
                    float y = (float)Math.Sin(horizontalAngle);

                    if (axis == MsbEditor.Gizmos.Axis.PosZ)
                    {
                        return(new Vector3(x * radius, y * radius, depth));
                    }
                    if (axis == MsbEditor.Gizmos.Axis.PosX)
                    {
                        return(new Vector3(depth, x * radius, y * radius));
                    }
                    return(new Vector3(x * radius, depth, y * radius));
                }

                void Arrow(MsbEditor.Gizmos.Axis axis, Color color)
                {
                    Vector3 tip = Vector3.Zero;

                    if (axis == MsbEditor.Gizmos.Axis.PosX)
                    {
                        tip = Vector3.UnitX * TotalLength;
                    }
                    if (axis == MsbEditor.Gizmos.Axis.PosY)
                    {
                        tip = Vector3.UnitY * TotalLength;
                    }
                    if (axis == MsbEditor.Gizmos.Axis.PosZ)
                    {
                        tip = Vector3.UnitZ * TotalLength;
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptBase = GetPoint(axis, i, StemRadius, 0);

                        var prevPtBase = GetPoint(axis, i - 1, StemRadius, 0);

                        //Face: Part of Bottom
                        AddTri(Vector3.Zero, prevPtBase, ptBase, color);
                        AddColTri(Tris, Vector3.Zero, prevPtBase, ptBase);
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptBase             = GetPoint(axis, i, StemRadius, 0);
                        var ptTipStartInner    = GetPoint(axis, i, StemRadius, TotalLength - TipLength);
                        var ptBaseCol          = GetPoint(axis, i, TipRadius * 1.25f, 0);
                        var ptTipStartInnerCol = GetPoint(axis, i, TipRadius * 1.25f, TotalLength - TipLength);

                        var prevPtBase             = GetPoint(axis, i - 1, StemRadius, 0);
                        var prevPtTipStartInner    = GetPoint(axis, i - 1, StemRadius, TotalLength - TipLength);
                        var prevPtBaseCol          = GetPoint(axis, i - 1, TipRadius * 1.25f, 0);
                        var prevPtTipStartInnerCol = GetPoint(axis, i - 1, TipRadius * 1.25f, TotalLength - TipLength);

                        // Face: Base to Tip Inner
                        AddQuad(prevPtBase, prevPtTipStartInner, ptTipStartInner, ptBase, color);
                        AddColQuad(Tris, prevPtBaseCol, prevPtTipStartInnerCol, ptTipStartInnerCol, ptBaseCol);
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptTipStartInner = GetPoint(axis, i, StemRadius, TotalLength - TipLength);
                        var ptTipStartOuter = GetPoint(axis, i, TipRadius, TotalLength - TipLength);

                        var prevPtTipStartInner = GetPoint(axis, i - 1, StemRadius, TotalLength - TipLength);
                        var prevPtTipStartOuter = GetPoint(axis, i - 1, TipRadius, TotalLength - TipLength);

                        // Face: Tip Start Inner to Tip Start Outer
                        AddQuad(prevPtTipStartInner, prevPtTipStartOuter, ptTipStartOuter, ptTipStartInner, color);
                        AddColQuad(Tris, prevPtTipStartInner, prevPtTipStartOuter, ptTipStartOuter, ptTipStartInner);
                    }

                    for (int i = 1; i <= Segments; i++)
                    {
                        var ptTipStartOuter        = GetPoint(axis, i, TipRadius, TotalLength - TipLength);
                        var prevPtTipStartOuter    = GetPoint(axis, i - 1, TipRadius, TotalLength - TipLength);
                        var ptTipStartOuterCol     = GetPoint(axis, i, TipRadius * 1.25f, TotalLength - TipLength);
                        var prevPtTipStartOuterCol = GetPoint(axis, i - 1, TipRadius * 1.25f, TotalLength - TipLength);

                        // Face: Tip Start to Tip
                        AddTri(prevPtTipStartOuter, tip, ptTipStartOuter, color);
                        AddColTri(Tris, prevPtTipStartOuterCol, tip * 1.10f, ptTipStartOuterCol);
                    }
                }

                //Arrow(MsbEditor.Gizmos.Axis.PosX, Color.FromArgb(0xF3, 0x36, 0x53));
                //Arrow(MsbEditor.Gizmos.Axis.PosZ, Color.FromArgb(0x38, 0x90, 0xED));
                //Arrow(MsbEditor.Gizmos.Axis.PosY, Color.FromArgb(0x86, 0xC8, 0x15));
                Arrow(axis, Color.FromArgb(0x86, 0xC8, 0x15));
                //FinalizeBuffers(true);

                GeometryData = new DbgPrimGeometryData()
                {
                    GeomBuffer = GeometryBuffer
                };

                Renderer.AddBackgroundUploadTask((d, cl) =>
                {
                    UpdatePerFrameResources(d, cl, null);
                });
            }
        }