/// <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; }
protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation) { model = factory.GetModel(this.Name, isInternal, forceFromDisk); ModelBuilderHelper.Extract(factory, out BatchInformations, out TextureInformation, model, _diffuseName, _bumpName, _specularName, _glowName, isInternal); BoundingSphere sphere = new BoundingSphere(); foreach (var item in model.Meshes) { sphere = BoundingSphere.CreateMerged(sphere, item.BoundingSphere); } modelRadius = sphere.Radius; }
/// <summary> /// Initializes a new instance of the <see cref="CustomModel"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <param name="modelName">Name of the model.</param> /// <param name="meshindex">The meshindex.</param> /// <param name="binfo">The binfo.</param> /// <param name="diffuse">The diffuse.</param> public CustomModel(GraphicFactory factory, String modelName, int meshindex, BatchInformation[] binfo, Texture2D diffuse = null) : base(factory, modelName, false) { System.Diagnostics.Debug.Assert(binfo != null); System.Diagnostics.Debug.Assert(binfo.Count() != 0); BatchInformations = new BatchInformation[1][]; BatchInformations[0] = binfo; BoundingSphere bs = new BoundingSphere(); for (int i = 0; i < binfo.Count(); i++) { float radius; Vector3 center; ModelBuilderHelper.ExtractModelRadiusAndCenter(binfo[i], out radius, out center); bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius)); } modelRadius = bs.Radius; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[binfo.Count()]; for (int j = 0; j < TextureInformations[0].Count(); j++) { TextureInformations[0][j] = new TextureInformation(isInternal, factory); TextureInformations[0][j].LoadTexture(); if (diffuse == null) { if (model != null) { BasicEffect effect = model.Meshes[meshindex].MeshParts[j].Effect as BasicEffect; if (effect != null) { TextureInformations[0][j].SetTexture(effect.Texture, TextureType.DIFFUSE); } } } else { SetTexture(diffuse, TextureType.DIFFUSE, meshindex, j); } } }
/// <summary> /// Loads the model. /// </summary> /// <param name="factory">The factory.</param> /// <param name="BatchInformations">The batch informations.</param> /// <param name="TextureInformations">The texture informations.</param> protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations) { //code not called !!! //Here for future usage. model = factory.GetModel(this.Name, isInternal); ModelBuilderHelper.Extract(model, out BatchInformations); BoundingSphere sphere = new BoundingSphere(); foreach (var item in model.Meshes) { BoundingSphere.CreateMerged(sphere, item.BoundingSphere); } modelRadius = sphere.Radius; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = new TextureInformation(isInternal, factory); TextureInformations[0][0].LoadTexture(); }
/// <summary> /// Initializes a new instance of the <see cref="CustomModel"/> class. /// </summary> /// <param name="factory">The factory.</param> /// <param name="modelName">Name of the model.</param> /// <param name="BatchInformation">The batch information.</param> /// <param name="TextureInformation">The texture information.</param> /// <param name="meshindex">The meshindex.</param> /// <param name="meshpartIndex">Index of the meshpart.</param> public CustomModel(GraphicFactory factory, String modelName, BatchInformation BatchInformation, TextureInformation TextureInformation, int meshindex = 0, int meshpartIndex = 0) : base(factory, modelName, false) { System.Diagnostics.Debug.Assert(BatchInformation != null); System.Diagnostics.Debug.Assert(TextureInformation != null); BatchInformations = new BatchInformation[1][]; BatchInformations[0] = new BatchInformation[1]; BatchInformations[0][0] = BatchInformation; BoundingSphere bs = new BoundingSphere(); { float radius; Vector3 center; ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformation, out radius, out center); bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius)); } modelRadius = bs.Radius; TextureInformations = new TextureInformation[1][]; TextureInformations[0] = new TextureInformation[1]; TextureInformations[0][0] = TextureInformation; if (TextureInformation.getTexture(TextureType.DIFFUSE) == null) { if (model != null) { BasicEffect effect = model.Meshes[meshindex].MeshParts[meshpartIndex].Effect as BasicEffect; if (effect != null) { TextureInformations[0][0].SetTexture(effect.Texture, TextureType.DIFFUSE); } } } }