예제 #1
0
        public Model Finish()
        {
            GraphicsBuffer buffer      = new GraphicsBuffer();
            SphereBuilder  modelBounds = new SphereBuilder();

            foreach (MeshInfo meshInfo in meshes)
            {
                meshInfo.AddCentrePoints(ref modelBounds, positionChannel, indices);
            }
            modelBounds.CalculateCentre();
            foreach (MeshInfo meshInfo in meshes)
            {
                meshInfo.AddRadiusPoints(ref modelBounds, positionChannel, indices);
            }

            Model model = new Model(buffer, ElementType.UInt32, modelBounds.Sphere);

            // Put the bones in the model.
            foreach (var mesh in meshes)
            {
                if (mesh.Bone != null && mesh.Bone.model == null)
                {
                    model.Bones.Add(mesh.Bone);
                }
            }

            // Create the meshes and put them in the model.
            foreach (MeshInfo meshInfo in meshes)
            {
                SphereBuilder meshSphere = new SphereBuilder();

                meshInfo.AddCentrePoints(ref meshSphere, positionChannel, indices);
                meshSphere.CalculateCentre();
                meshInfo.AddRadiusPoints(ref meshSphere, positionChannel, indices);

                ModelMesh mesh = new ModelMesh(meshSphere.Sphere, meshInfo.Bone, meshInfo.Parts);
                model.Meshes.Add(mesh);
            }

            // Calculate the total size of the buffer.
            int bufferSize = indexCount * 4;

            foreach (var channel in Channels)
            {
                channel.CheckSize(ref bufferSize);
            }

            // Write the data into the buffer.
            byte[] bufferData   = new byte[bufferSize];
            int    bufferOffset = indexCount * 4;

            indices.CopyTo(0, indexCount, bufferData, 0);
            foreach (var channel in Channels)
            {
                channel.Write(bufferData, ref bufferOffset, model, buffer);
            }
            buffer.Data(bufferData);

            return(model);
        }