/// <summary> /// Initializes a new instance of the <see cref="MeshNode"/> class. /// </summary> /// <param name="mesh">The <see cref="Mesh"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="mesh"/> is <see langword="null"/>. /// </exception> public MeshNode(Mesh mesh) { if (mesh == null) { throw new ArgumentNullException("mesh"); } IsRenderable = true; CastsShadows = true; _mesh = mesh; _materialInstances = new MaterialInstanceCollection(_mesh.Materials); _passHashes = _materialInstances.PassHashes; SetHasAlpha(); // Ensure that MorphWeights are set. (Required for correct rendering.) if (mesh.HasMorphTargets()) { MorphWeights = new MorphWeightCollection(mesh); } // We do not call OnInitializeShape here because virtual methods should not be called // in constructor. Shape = mesh.BoundingShape; }
/// <summary> /// Initializes a new instance of the <see cref="MaterialInstanceCollection"/> class by cloning /// the specified material instances. /// </summary> /// <param name="materials">The material instances to be cloned.</param> internal MaterialInstanceCollection(MaterialInstanceCollection materials) { PassHashes = materials.PassHashes; int numberOfMaterials = materials.Count; _array = new MaterialInstance[numberOfMaterials]; for (int i = 0; i < numberOfMaterials; i++) { _array[i] = materials[i].Clone(); } }
/// <summary> /// Called when all fix-ups are executed and the asset is fully loaded. /// </summary> /// <param name="sender">The sender.</param> /// <param name="eventArgs"> /// The <see cref="EventArgs"/> instance containing the event data. /// </param> internal void OnAssetLoaded(object sender, EventArgs eventArgs) { // Meshes are shared resources, so they are loaded deferred. // OnAssetLoaded is called when all shared resources are loaded. _materialInstances = new MaterialInstanceCollection(Mesh.Materials); _passHashes = _materialInstances.PassHashes; SetHasAlpha(); // Ensure that MorphWeights are set. (Required for correct rendering.) if (_mesh.HasMorphTargets()) { MorphWeights = new MorphWeightCollection(_mesh); } OnInitializeShape(); // Note: The SkeletonPose is created by the ModelNode when the asset is loaded. }
/// <inheritdoc/> protected override void CloneCore(SceneNode source) { // Clone SceneNode properties. base.CloneCore(source); // Clone MeshNode properties. var sourceTyped = (MeshNode)source; _mesh = sourceTyped.Mesh; _materialInstances = new MaterialInstanceCollection(sourceTyped.MaterialInstances); _passHashes = _materialInstances.PassHashes; if (sourceTyped.MorphWeights != null) { MorphWeights = sourceTyped.MorphWeights.Clone(); } #if ANIMATION if (sourceTyped.SkeletonPose != null) { _skeletonPose = sourceTyped.SkeletonPose.Clone(); } #endif }
public MaterialInstanceCollectionView(MaterialInstanceCollection collection) { _collection = collection; }