IObject[] wl_OnCreateIObject(IWorld world, GraphicFactory factory, GraphicInfo ginfo, ObjectInformation[] oi)
        {
            IObject[] objs = new IObject[oi.Count()];
            int i = 0;
            foreach (var mi in oi)
            {
                mi.batchInformation.ModelLocalTransformation = Matrix.Identity;
                IModelo model = new CustomModel(factory, mi.modelName, mi.batchInformation, mi.textureInformation, mi.meshIndex, mi.meshPartIndex);
                //IPhysicObject po = new TriangleMeshObject(model, Vector3.Zero, Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial());
                GhostObject po = new GhostObject(mi.position, Matrix.CreateFromQuaternion(mi.rotation), mi.scale);
                IShader shader = new ForwardXNABasicShader();
                ForwardMaterial dm = new ForwardMaterial(shader);
                IObject obj = new IObject(dm, model, po);
                objs[i++] = obj;
            }

            return objs;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="loader">The loader.</param>
        public CustomModel(GraphicFactory factory, ObjectInformation[] loader)
            : base(factory, loader[0].modelName, false)
        {
            System.Diagnostics.Debug.Assert(loader!= null);
            System.Diagnostics.Debug.Assert(loader.Count() != 0);
            BatchInformations = new BatchInformation[1][];
            BatchInformations[0] = new BatchInformation[loader.Count()];

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[loader.Count()];

            BoundingSphere bs = new BoundingSphere();
            for (int i = 0; i < loader.Count(); i++)
            {
                BatchInformations[0][i] = loader[i].batchInformation;
                TextureInformations[0][i] = loader[i].textureInformation;

                float radius;
                Vector3 center;
                ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformations[0][i], out radius, out center);
                bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius));
            }            
            modelRadius = bs.Radius;
        }