/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.FilterComponents"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.FilterComponents) { return(true); } if (meshes == null) { context.LogError(name + " Mesh exclusion list is null. (Invalid processor state.)" , this); return(false); } if (meshes.Count == 0) { context.Log(name + ": Filter is inactive. No meshes configured to filter.", this); return(true); } List <Component> targetFilters = context.components; int removed = 0; for (int iTarget = targetFilters.Count - 1; iTarget >= 0; iTarget--) { if (!(targetFilters[iTarget] is MeshFilter)) { continue; } MeshFilter filter = (MeshFilter)targetFilters[iTarget]; if (!filter) { continue; } MatchPredicate p = new MatchPredicate(filter.sharedMesh, matchType, true); int iSource = meshes.FindIndex(p.Matches); if (iSource != -1) { targetFilters.RemoveAt(iTarget); removed++; } } if (removed > 0) { context.Log(string.Format("{0}: Filtered out {1} components.", name, removed), this); } else { context.Log(name + ": No components filtered.", this); } return(true); }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.FilterComponents"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.FilterComponents || context == null) return true; context.info.filterCount++; List<Component> items = context.components; int count = 0; for (int i = items.Count - 1; i >= 0; i--) { if (!items[i].gameObject.isStatic) { items.RemoveAt(i); count++; } } context.Log(string.Format("{0}: Applied static filter. Removed {1} components." , name, count) , this); return true; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.FilterComponents"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.FilterComponents || context == null) { return(true); } context.info.filterCount++; List <Component> items = context.components; int count = 0; for (int i = items.Count - 1; i >= 0; i--) { if (!items[i].gameObject.isStatic) { items.RemoveAt(i); count++; } } context.Log(string.Format("{0}: Applied static filter. Removed {1} components." , name, count) , this); return(true); }
public static float ToProgress(InputBuildState state) { float inc = 1 / 5f; switch (state) { case InputBuildState.LoadComponents: return(inc * 1); case InputBuildState.FilterComponents: return(inc * 2); case InputBuildState.ApplyAreaModifiers: return(inc * 3); case InputBuildState.CompileInput: return(inc * 4); case InputBuildState.PostProcess: return(inc * 5); case InputBuildState.Aborted: return(1.0f); case InputBuildState.Complete: return(1.0f); } return(0); }
public static string ToLabel(InputBuildState state) { switch (state) { case InputBuildState.LoadComponents: return("Loading scene objects..."); case InputBuildState.FilterComponents: return("Filtering scene objects..."); case InputBuildState.ApplyAreaModifiers: return("Applying area modifiers..."); case InputBuildState.CompileInput: return("Compiling input..."); case InputBuildState.PostProcess: return("Post-processing..."); case InputBuildState.Aborted: return("Aborted."); case InputBuildState.Complete: return("Input gathered."); } return("Unhandled state: " + state); }
private void FinalizeOnAbort(string message) { mAssets = new InputAssets(); mContext.LogError(message, this); ResetLocals(); mState = InputBuildState.Aborted; }
private void ApplyAreaModifiers() { List <Component> items = mContext.components; List <byte> areas = mContext.areas; int count = items.Count; areas.Clear(); for (int i = 0; i < count; i++) { areas.Add(NMGen.MaxArea); } if (!RunProcessors()) { return; } if (items.Count != count || areas.Count != count || items.Contains(null)) { FinalizeOnAbort(string.Format("Custom processors corrupted component list." + " (Detected nulls or count mismatch.) ({0})" , mState)); } else { mContext.Log(mState + " complete.", this); mState = InputBuildState.CompileInput; } }
private InputBuilder(InputBuildContext context, IInputBuildProcessor[] processors) { mContext = context; mInputProcessors = processors; System.Array.Sort(mInputProcessors, new PriorityComparer <IInputBuildProcessor>(true)); mState = InputBuildState.LoadComponents; }
private InputBuilder(InputBuildContext context, IInputBuildProcessor[] processors) { mContext = context; mInputProcessors = processors; System.Array.Sort(mInputProcessors, new PriorityComparer<IInputBuildProcessor>(true)); mState = InputBuildState.LoadComponents; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.ApplyAreaModifiers"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.ApplyAreaModifiers) { return(true); } context.info.areaModifierCount++; if (meshes == null || areas == null || meshes.Count != areas.Count) { context.LogError("Mesh/Area size error. (Invalid processor state.)", this); return(false); } if (meshes.Count == 0) { context.Log("No action taken. No mesh areas defined.", this); return(true); } List <Component> targetFilters = context.components; List <byte> targetAreas = context.areas; int applied = 0; for (int iTarget = 0; iTarget < targetFilters.Count; iTarget++) { if (!(targetFilters[iTarget] is MeshFilter)) { continue; } MeshFilter filter = (MeshFilter)targetFilters[iTarget]; if (filter == null || targetAreas[iTarget] == org.critterai.nmgen.NMGen.NullArea) { // Never override null area. continue; } MatchPredicate p = new MatchPredicate(filter.sharedMesh, matchType, true); int iSource = meshes.FindIndex(p.Matches); if (iSource != -1) { targetAreas[iTarget] = areas[iSource]; applied++; } } context.Log(string.Format("Applied area(s) to {0} components.", applied), this); return(true); }
private void LoadSceneItems() { if (RunProcessors() && ValidateSceneItems()) { mContext.Log(string.Format("{0} complete: {1} components." , mState, mContext.components.Count) , this); mState = InputBuildState.FilterComponents; } }
private void CompileInput() { // Just in case input processors were naughty. mContext.processors.Clear(); mContext.connCompiler.Reset(); mContext.geomCompiler.Reset(); if (RunProcessors()) { mContext.Log(mState + " complete.", this); mState = InputBuildState.PostProcess; } }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.CompileInput"/> and /// <see cref="InputBuildState.PostProcess"/> states. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state == InputBuildState.CompileInput) { return(ProcessCompile(context)); } if (state == InputBuildState.PostProcess) { return(ProcessPost(context)); } return(true); }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.FilterComponents"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.FilterComponents) return true; if (meshes == null) { context.LogError(name + " Mesh exclusion list is null. (Invalid processor state.)" , this); return false; } if (meshes.Count == 0) { context.Log(name + ": Filter is inactive. No meshes configured to filter.", this); return true; } List<Component> targetFilters = context.components; int removed = 0; for (int iTarget = targetFilters.Count - 1; iTarget >= 0; iTarget--) { if (!(targetFilters[iTarget] is MeshFilter)) continue; MeshFilter filter = (MeshFilter)targetFilters[iTarget]; if (!filter) continue; MatchPredicate p = new MatchPredicate(filter.sharedMesh, matchType, true); int iSource = meshes.FindIndex(p.Matches); if (iSource != -1) { targetFilters.RemoveAt(iTarget); removed++; } } if (removed > 0) context.Log(string.Format("{0}: Filtered out {1} components.", name, removed), this); else context.Log(name + ": No components filtered.", this); return true; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Processes during the <see cref="InputBuildState.LoadComponents"/> /// and <see cref="InputBuildState.CompileInput"/> states. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (context != null) { switch (state) { case InputBuildState.CompileInput: Compile(context); break; case InputBuildState.LoadComponents: Load(context); break; } } return(true); }
private void FilterSceneItems() { List <Component> items = mContext.components; int before = items.Count; mContext.info.compCountPre = before; if (RunProcessors() && ValidateSceneItems()) { string msg = string.Format("{0} complete. {1} components. {2} removed." , mState, mContext.components.Count, before - items.Count); mContext.Log(msg, this); mContext.info.compCountPost = items.Count; mState = InputBuildState.ApplyAreaModifiers; } }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Processes during the <see cref="InputBuildState.LoadComponents"/> /// and <see cref="InputBuildState.CompileInput"/> states. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (context != null) { switch (state) { case InputBuildState.CompileInput: Compile(context); break; case InputBuildState.LoadComponents: Load(context); break; } } return true; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.ApplyAreaModifiers"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state == InputBuildState.ApplyAreaModifiers) { context.info.areaModifierCount++; List <byte> areas = context.areas; for (int i = 0; i < areas.Count; i++) { areas[i] = mDefaultArea; } string msg = string.Format("{0}: Applied default area to all components: {1}" , name, mDefaultArea); context.Log(msg, this); } return(true); }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.ApplyAreaModifiers"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state == InputBuildState.ApplyAreaModifiers) { context.info.areaModifierCount++; List<byte> areas = context.areas; for (int i = 0; i < areas.Count; i++) { areas[i] = mDefaultArea; } string msg = string.Format("{0}: Applied default area to all components: {1}" , name, mDefaultArea); context.Log(msg, this); } return true; }
private void FinalizeBuild() { mAssets.info = mContext.info; mAssets.geometry = mContext.geomCompiler.CreateGeometry(out mAssets.areas); if (mAssets.geometry == null) { FinalizeOnAbort(string.Format("No geometry was produced. ({0})", mState)); return; } mAssets.processors = mContext.processors.ToArray(); mAssets.conns = mContext.connCompiler.CreateConnectionSet(); string msg = string.Format("Final geometry: Triangles: {0}, Vertices: {1}" , mAssets.geometry.triCount, mAssets.geometry.vertCount); mContext.Log(msg, this); mContext.Log("Final Off-Mesh Connections: " + mAssets.conns.Count, this); if (mAssets.processors.Length < 10) { foreach (INMGenProcessor p in mAssets.processors) { mContext.Log("NMGen Processor: " + p.Name, this); } } else { mContext.Log("NMGen processor count: " + mAssets.processors.Length, this); } ResetLocals(); mState = InputBuildState.Complete; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.FilterComponents"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.FilterComponents) return true; context.info.filterCount++; if (tags == null) { context.Log(name + " Mesh exclusion list is null. (Invalid processor state.)", this); return false; } if (tags.Count == 0) { context.Log(name + ": Filter is inactive. No tags configured to filter.", this); return true; } List<Component> targetItems = context.components; int removed = 0; for (int iTarget = targetItems.Count - 1; iTarget >= 0; iTarget--) { Component targetItem = targetItems[iTarget]; if (!targetItem) continue; int iSource = tags.IndexOf(targetItem.tag); if (iSource != -1) { // One of the tags is on this item. targetItems.RemoveAt(iTarget); removed++; continue; } if (recursive) { // Need to see if the tag is on any parent. Transform parent = targetItem.transform.parent; while (parent != null) { iSource = tags.IndexOf(parent.tag); if (iSource != -1) { // One of the tags is on this item. targetItems.RemoveAt(iTarget); removed++; break; } parent = parent.parent; } } } if (removed > 0) context.Log(string.Format("{0}: Filtered out {1} components.", name, removed), this); else context.Log(name + ": No components filtered.", this); return true; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.FilterComponents"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.FilterComponents) { return(true); } context.info.filterCount++; if (tags == null) { context.Log(name + " Mesh exclusion list is null. (Invalid processor state.)", this); return(false); } if (tags.Count == 0) { context.Log(name + ": Filter is inactive. No tags configured to filter.", this); return(true); } List <Component> targetItems = context.components; int removed = 0; for (int iTarget = targetItems.Count - 1; iTarget >= 0; iTarget--) { Component targetItem = targetItems[iTarget]; if (!targetItem) { continue; } int iSource = tags.IndexOf(targetItem.tag); if (iSource != -1) { // One of the tags is on this item. targetItems.RemoveAt(iTarget); removed++; continue; } if (recursive) { // Need to see if the tag is on any parent. Transform parent = targetItem.transform.parent; while (parent != null) { iSource = tags.IndexOf(parent.tag); if (iSource != -1) { // One of the tags is on this item. targetItems.RemoveAt(iTarget); removed++; break; } parent = parent.parent; } } } if (removed > 0) { context.Log(string.Format("{0}: Filtered out {1} components.", name, removed), this); } else { context.Log(name + ": No components filtered.", this); } return(true); }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.ApplyAreaModifiers"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.ApplyAreaModifiers) return true; context.info.areaModifierCount++; if (meshes == null || areas == null || meshes.Count != areas.Count) { context.LogError("Mesh/Area size error. (Invalid processor state.)", this); return false; } if (meshes.Count == 0) { context.Log("No action taken. No mesh areas defined.", this); return true; } List<Component> targetFilters = context.components; List<byte> targetAreas = context.areas; int applied = 0; for (int iTarget = 0; iTarget < targetFilters.Count; iTarget++) { if (!(targetFilters[iTarget] is MeshFilter)) continue; MeshFilter filter = (MeshFilter)targetFilters[iTarget]; if (filter == null || targetAreas[iTarget] == org.critterai.nmgen.NMGen.NullArea) // Never override null area. continue; MatchPredicate p = new MatchPredicate(filter.sharedMesh, matchType, true); int iSource = meshes.FindIndex(p.Matches); if (iSource != -1) { targetAreas[iTarget] = areas[iSource]; applied++; } } context.Log(string.Format("Applied area(s) to {0} components.", applied), this); return true; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.CompileInput"/> and /// <see cref="InputBuildState.PostProcess"/> states. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state == InputBuildState.CompileInput) return ProcessCompile(context); if (state == InputBuildState.PostProcess) return ProcessPost(context); return true; }
public static string ToLabel(InputBuildState state) { switch (state) { case InputBuildState.LoadComponents: return "Loading scene objects..."; case InputBuildState.FilterComponents: return "Filtering scene objects..."; case InputBuildState.ApplyAreaModifiers: return "Applying area modifiers..."; case InputBuildState.CompileInput: return "Compiling input..."; case InputBuildState.PostProcess: return "Post-processing..."; case InputBuildState.Aborted: return "Aborted."; case InputBuildState.Complete: return "Input gathered."; } return "Unhandled state: " + state; }
public static float ToProgress(InputBuildState state) { float inc = 1 / 5f; switch (state) { case InputBuildState.LoadComponents: return inc * 1; case InputBuildState.FilterComponents: return inc * 2; case InputBuildState.ApplyAreaModifiers: return inc * 3; case InputBuildState.CompileInput: return inc * 4; case InputBuildState.PostProcess: return inc * 5; case InputBuildState.Aborted: return 1.0f; case InputBuildState.Complete: return 1.0f; } return 0; }
private void FinalizeBuild() { mAssets.info = mContext.info; mAssets.geometry = mContext.geomCompiler.CreateGeometry(out mAssets.areas); if (mAssets.geometry == null) { FinalizeOnAbort(string.Format("No geometry was produced. ({0})", mState)); return; } mAssets.processors = mContext.processors.ToArray(); mAssets.conns = mContext.connCompiler.CreateConnectionSet(); string msg = string.Format("Final geometry: Triangles: {0}, Vertices: {1}" , mAssets.geometry.triCount, mAssets.geometry.vertCount); mContext.Log(msg, this); mContext.Log("Final Off-Mesh Connections: " + mAssets.conns.Count, this); if (mAssets.processors.Length < 10) { foreach (INMGenProcessor p in mAssets.processors) { mContext.Log("NMGen Processor: " + p.Name, this); } } else mContext.Log("NMGen processor count: " + mAssets.processors.Length, this); ResetLocals(); mState = InputBuildState.Complete; }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.ApplyAreaModifiers"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.ApplyAreaModifiers) { return(true); } context.info.areaModifierCount++; if (tags == null || areas == null || tags.Count != areas.Count) { context.Log("Mesh/Area size error. (Invalid processor state.)", this); return(false); } if (tags.Count == 0) { context.Log("No action taken. No tags defined.", this); return(true); } List <Component> targetItems = context.components; List <byte> targetAreas = context.areas; int applied = 0; for (int iTarget = 0; iTarget < targetItems.Count; iTarget++) { Component targetItem = targetItems[iTarget]; if (targetItem == null || targetAreas[iTarget] == NMGen.NullArea) { // Don't override null area. continue; } int iSource = tags.IndexOf(targetItem.tag); if (iSource != -1) { targetAreas[iTarget] = areas[iSource]; applied++; continue; } if (recursive) { // Need to see if the tag is on any parent. Transform parent = targetItem.transform.parent; while (parent != null) { iSource = tags.IndexOf(parent.tag); if (iSource != -1) { // One of the tags is on this item. targetAreas[iTarget] = areas[iSource]; applied++; break; } parent = parent.parent; } } } context.Log(string.Format("{1}: Applied area(s) to {0} components", applied, name), this); return(true); }
private void ApplyAreaModifiers() { List<Component> items = mContext.components; List<byte> areas = mContext.areas; int count = items.Count; areas.Clear(); for (int i = 0; i < count; i++) { areas.Add(NMGen.MaxArea); } if (!RunProcessors()) return; if (items.Count != count || areas.Count != count || items.Contains(null)) { FinalizeOnAbort(string.Format("Custom processors corrupted component list." + " (Detected nulls or count mismatch.) ({0})" , mState)); } else { mContext.Log(mState + " complete.", this); mState = InputBuildState.CompileInput; } }
private void FilterSceneItems() { List<Component> items = mContext.components; int before = items.Count; mContext.info.compCountPre = before; if (RunProcessors() && ValidateSceneItems()) { string msg = string.Format("{0} complete. {1} components. {2} removed." , mState, mContext.components.Count, before - items.Count); mContext.Log(msg, this); mContext.info.compCountPost = items.Count; mState = InputBuildState.ApplyAreaModifiers; } }
/// <summary> /// Processes the context. /// </summary> /// <remarks> /// <para> /// Applied during the <see cref="InputBuildState.ApplyAreaModifiers"/> state. /// </para> /// </remarks> /// <param name="state">The current state of the input build.</param> /// <param name="context">The input context to process.</param> /// <returns>False if the input build should abort.</returns> public bool ProcessInput(InputBuildContext context, InputBuildState state) { if (state != InputBuildState.ApplyAreaModifiers) return true; context.info.areaModifierCount++; if (tags == null || areas == null || tags.Count != areas.Count) { context.Log("Mesh/Area size error. (Invalid processor state.)", this); return false; } if (tags.Count == 0) { context.Log("No action taken. No tags defined.", this); return true; } List<Component> targetItems = context.components; List<byte> targetAreas = context.areas; int applied = 0; for (int iTarget = 0; iTarget < targetItems.Count; iTarget++) { Component targetItem = targetItems[iTarget]; if (targetItem == null || targetAreas[iTarget] == NMGen.NullArea) // Don't override null area. continue; int iSource = tags.IndexOf(targetItem.tag); if (iSource != -1) { targetAreas[iTarget] = areas[iSource]; applied++; continue; } if (recursive) { // Need to see if the tag is on any parent. Transform parent = targetItem.transform.parent; while (parent != null) { iSource = tags.IndexOf(parent.tag); if (iSource != -1) { // One of the tags is on this item. targetAreas[iTarget] = areas[iSource]; applied++; break; } parent = parent.parent; } } } context.Log(string.Format("{1}: Applied area(s) to {0} components", applied, name), this); return true; }