Exemple #1
0
        void createVb(ref int count, BarGeo geo)
        {
            VertexBuffer vb = new VertexBuffer(GraphicsDevice, instanceVertDecl, count, BufferUsage.WriteOnly);

            vb.SetData(instanceVerts, 0, count);
            geo.instanceBindingList.Add(new VertexBufferBinding(vb, 0, 1));
            count = 0;
        }
Exemple #2
0
        public override void createGeoChunk(out Geo geo, BoundingBox bbox, Midi.Track midiTrack, TrackProps trackProps, MaterialProps texMaterial)
        {
            BarGeo barGeo = new BarGeo();

            geo = barGeo;
            List <Midi.Note> noteList = midiTrack.Notes;

            if (noteList.Count == 0)
            {
                return;
            }

            float halfNoteHeight = Project.Props.NoteHeight / 2;
            int   instanceIndex  = 0;

            for (int n = 0; n < noteList.Count; n++)
            {
                Midi.Note note = noteList[n];
                if (note.start > Project.Notes.SongLengthT) //only if audio ends before the notes end
                {
                    continue;
                }
                Vector2 noteStart = Project.getScreenPos(note.start, note.pitch);
                Vector2 noteEnd   = Project.getScreenPos(note.stop, note.pitch);

                //Create bounding boxes
                Vector3 boxMin = new Vector3(noteStart.X, noteStart.Y - halfNoteHeight, 0);
                Vector3 boxMax = new Vector3(noteEnd.X, noteEnd.Y + halfNoteHeight, 0);
                geo.bboxes.Add(new BoundingBoxEx(boxMin, boxMax));

                //Create inctance data
                Vector2 topLeft_world = new Vector2(noteStart.X, noteStart.Y - halfNoteHeight);
                Vector2 size_world    = new Vector2(noteEnd.X - noteStart.X, halfNoteHeight * 2 - 0.001f);
                Vector2 topLeft_tex   = topLeft_world;
                Vector2 size_tex      = size_world;

                Texture2D texture = texMaterial.TexProps.Texture;
                if (texture != null)
                {
                    Vector2 texSize = new Vector2(texture.Width, texture.Height);
                    calcRectTexCoords(out topLeft_tex, out size_tex, texSize, topLeft_world, size_world, texMaterial);
                }
                instanceVerts[instanceIndex].destRect = new Vector4(topLeft_world.X, topLeft_world.Y, size_world.X, size_world.Y);
                instanceVerts[instanceIndex].srcRect  = new Vector4(topLeft_tex.X, topLeft_tex.Y, size_tex.X, size_tex.Y);
                if (++instanceIndex >= MaxInstances - 1)
                {
                    createVb(ref instanceIndex, barGeo);
                }
            }
            if (instanceIndex > 0)
            {
                createVb(ref instanceIndex, barGeo);
            }
        }
Exemple #3
0
        public override void drawGeoChunk(Geo geo)
        {
            BarGeo barGeo = (BarGeo)geo;

            GraphicsDevice.Indices = indexBuf;
            fx.CurrentTechnique    = fx.Techniques["Technique1"];
            fx.CurrentTechnique.Passes["Pass1"].Apply();

            foreach (var instanceBinding in barGeo.instanceBindingList)
            {
                GraphicsDevice.SetVertexBuffers(meshBinding, instanceBinding);
                GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 2, instanceBinding.VertexBuffer.VertexCount);
            }
        }