/// <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); }
private void Compile(InputBuildContext context) { context.info.compilerCount++; InputGeometryCompiler compiler = context.geomCompiler; List <Component> items = context.components; List <byte> areas = context.areas; for (int i = 0; i < items.Count; i++) { Component item = items[i]; if (item is Terrain) { Terrain terrain = (Terrain)item; if (terrain.terrainData != terrainData) { continue; } TriangleMesh mesh = TerrainUtil.TriangulateSurface(terrain, mResolution); byte[] lareas = NMGen.CreateAreaBuffer(mesh.triCount, areas[i]); if (compiler.AddTriangles(mesh, lareas)) { string msg = string.Format("Compiled the {0} terrain surface. Triangles: {1}" , terrain.name, mesh.triCount); context.Log(msg, this); } else { string msg = string.Format("Compiler rejected mesh for the {0} terrain.", terrain.name); context.LogError(msg, this); return; } if (includeTrees) { int before = compiler.TriCount; TerrainUtil.TriangluateTrees(terrain, areas[i], compiler); string msg = string.Format("Compiled the {0} terrain trees. Triangles: {1}" , terrain.name, compiler.TriCount - before); context.Log(msg, this); } break; } } }
/// <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.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; }
private bool ProcessCompile(InputBuildContext context) { if (!ProcessValidation(context)) { return(false); } context.info.compilerCount++; if (areas.Count == 0) { context.Log("No area/flag maps. No action taken.", this); return(true); } ushort[] sflags = new ushort[flags.Count]; for (int i = 0; i < sflags.Length; i++) { // The editor should prevent overflows. sflags[i] = (ushort)flags[i]; } AreaFlagMapper mapper = AreaFlagMapper.Create(name, Priority, areas.ToArray(), sflags); if (mapper == null) { context.LogError("Failed to create NMGen processor. Unexpected invalid data.", this); return(false); } context.processors.Add(mapper); context.Log(string.Format("Added {0} NMGen processor.", typeof(AreaFlagMapper).Name), this); return(true); }
private bool ProcessCompile(InputBuildContext context) { if (!ProcessValidation(context)) return false; context.info.compilerCount++; if (areas.Count == 0) { context.Log("No area/flag maps. No action taken.", this); return true; } ushort[] sflags = new ushort[flags.Count]; for (int i = 0; i < sflags.Length; i++) { // The editor should prevent overflows. sflags[i] = (ushort)flags[i]; } AreaFlagMapper mapper = AreaFlagMapper.Create(name, Priority, areas.ToArray(), sflags); if (mapper == null) { context.LogError("Failed to create NMGen processor. Unexpected invalid data.", this); return false; } context.processors.Add(mapper); context.Log(string.Format("Added {0} NMGen processor.", typeof(AreaFlagMapper).Name), 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; }
private void Compile(InputBuildContext context) { context.info.compilerCount++; InputGeometryCompiler compiler = context.geomCompiler; List<Component> items = context.components; List<byte> areas = context.areas; for (int i = 0; i < items.Count; i++) { Component item = items[i]; if (item is Terrain) { Terrain terrain = (Terrain)item; if (terrain.terrainData != terrainData) continue; TriangleMesh mesh = TerrainUtil.TriangulateSurface(terrain, mResolution); byte[] lareas = NMGen.CreateAreaBuffer(mesh.triCount, areas[i]); if (compiler.AddTriangles(mesh, lareas)) { string msg = string.Format("Compiled the {0} terrain surface. Triangles: {1}" , terrain.name, mesh.triCount); context.Log(msg, this); } else { string msg = string.Format("Compiler rejected mesh for the {0} terrain.", terrain.name); context.LogError(msg, this); return; } if (includeTrees) { int before = compiler.TriCount; TerrainUtil.TriangluateTrees(terrain, areas[i], compiler); string msg = string.Format("Compiled the {0} terrain trees. Triangles: {1}" , terrain.name, compiler.TriCount - before); context.Log(msg, this); } break; } } }