/// <summary> /// Creates an instance object for the given part /// </summary> /// <param name="part">The part to be instanced</param> /// <param name="instance">The instance data</param> /// <remarks> /// i. Every part many be instanced zero or many times /// ii. Instances should refer to a collection of parts /// iii. Instance data is linked to a single instance /// </remarks> public void CreateInstance(GlobalGeometryPartBlockNew part, IH2ObjectInstance instance, bool supportsPermutations) { // 1. Check if the part is already in dictionary and initialize it into the dictionary if not HashSet <InstanceKey> instances; if (!PartInstances.TryGetValue(part, out instances)) { // Initialize a collection of instance identifiers instances = new HashSet <InstanceKey>( ); PartInstances.Add(part, instances); } // 2. Check to see if this instance has already been added InstanceKey key; if (!InstanceKeys.TryGetValue(instance, out key)) { // (a) Create a key for the new instance and (b) link the key with the instance key = CreateInstanceKey( ); InstanceKeys.Add(instance, key); // (c) Link the key with the intance data InstanceData.Add(key, new InstanceData(instance, supportsPermutations)); } // 3. Check to see if the part is already linked with the instance instances.Add(key); }
public bool Equals(IH2ObjectInstance other) { var type = other.ObjectDatum.ManualBSPFlags.Type == ObjectData.ManualBSPFlags.Type; var uniqueId = other.ObjectDatum.ObjectID.UniqueID == ObjectData.ObjectID.UniqueID; return(type && uniqueId); }
bool IEquatable <IH2ObjectInstance> .Equals(IH2ObjectInstance other) { var instance = other as ScenarioInstanceBlock; if (instance == null) { return(false); } var objectInstance = ( IH2ObjectInstance )this; return(other.ObjectDatum.ObjectID.UniqueID == objectInstance.ObjectDatum.ObjectID.UniqueID); }
/// <summary> /// Buffers array data and creates draw commands as needed for a given object /// </summary> /// <param name="eye">Viewer camera used to select detail level</param> /// <param name="objectBlock">Object to draw</param> /// <param name="instance">Instance data of object to draw</param> private void Dispatch(Camera eye, ObjectBlock objectBlock, IH2ObjectInstance instance) { CacheKey cacheKey; if (!objectBlock.TryGetCacheKey(out cacheKey)) { return; } var modelBlock = objectBlock.Model.Get <ModelBlock>(cacheKey); var renderBlock = modelBlock?.RenderModel.Get <RenderModelBlock>(cacheKey); if (renderBlock == null) { return; } BucketManager.UnpackVertexData(renderBlock); // TODO use bounding offset and bounding radius here x var distance = eye.DistanceOf(instance.ObjectDatum.Position); var detailLevel = GetDetailLevel(modelBlock, distance); var variant = StringIdent.Zero; var type = instance.GetType( ); if (!SupportsPermutations.ContainsKey(type)) { SupportsPermutations[type] = type.Field("PermutationData") != null; } var supportsPermutation = SupportsPermutations[type]; if (supportsPermutation) { var instanceVariant = StringIdent.Zero; var defaultModelVariant = objectBlock.DefaultModelVariant; // Select the instance variant if it exists, else select the default variant if it exists, // else default to zero variant = instanceVariant == StringIdent.Zero ? defaultModelVariant == StringIdent.Zero ? StringIdent.Zero : defaultModelVariant : instanceVariant; } var hasVariant = variant != StringIdent.Zero; var hasRegions = modelBlock.ModelRegionBlock.Length > 0; // Here sections are collected using the detail level and chosen variant (if it exists) RenderModelSectionBlock[] sections; if (hasVariant) { var variantBlock = modelBlock.Variants.Single(e => e.Name == variant); sections = ProcessVariant(variantBlock, renderBlock, detailLevel); } else if (hasRegions) { sections = ProcessRegions(modelBlock.ModelRegionBlock, renderBlock, detailLevel); } else { sections = renderBlock.Sections; } // Loop through all the sections and load the vertex data if needed and pass the part along // to the draw manager to handle sorting and grouping foreach (var renderModelSection in sections) { if (renderModelSection.SectionData.Length <= 0) { continue; } _bucketManager.BufferPartData(renderModelSection.SectionData[0].Section); foreach (var part in renderModelSection.SectionData[0].Section.Parts) { var materialBlock = renderBlock.Materials[part.Material]; // Create an instance for this part and assign a shader for it _drawManager.CreateInstance(part, instance, supportsPermutation); _drawManager.AssignShader(part, cacheKey, materialBlock.Shader.Ident); } } }
/// <summary> /// Creates an instance object for the given part /// </summary> /// <param name="part">The part to be instanced</param> /// <param name="instance">The instance data</param> public void CreateInstance(GlobalGeometryPartBlockNew part, IH2ObjectInstance instance, bool supportsPermutations) { InstanceManager.CreateInstance(part, instance, supportsPermutations); }
int IEqualityComparer <IH2ObjectInstance> .GetHashCode(IH2ObjectInstance obj) { return(obj.ObjectDatum.ObjectID.UniqueID); }
bool IEqualityComparer <IH2ObjectInstance> .Equals(IH2ObjectInstance x, IH2ObjectInstance y) { return(x.Equals(y)); }