public void GetMeshBound(MeshType meshType, string name) { GameObject[] obj = Selection.gameObjects; for (int i = 0; i < obj.Length; i++) { MeshFilter render = obj[i].GetComponent <MeshFilter>(); if (render == null || render.sharedMesh == null) { continue; } LineRenderer lineRender = obj[i].GetComponent <LineRenderer>(); Mesh mesh = render.sharedMesh; List <List <Vector3> > vertices = MeshTools.TrianglesAndVerticesEdge(mesh.vertices, mesh.triangles); int index = 0; int maxCount = 0; for (int j = 0; j < vertices.Count; j++) { if (maxCount < vertices[j].Count) { index = j; maxCount = vertices[j].Count; } } CreateMesh(vertices[index], obj[i], obj[i].transform.parent, name, meshType); } }
private void RegenerateRegion(GameObject regionGo) { CombatGameState combatState = UnityGameInstance.BattleTechGame.Combat; RegionGameLogic regionGameLogic = regionGo.GetComponent <RegionGameLogic>(); List <Vector3> meshPoints = new List <Vector3>(); // Get all region points and fix the y height foreach (Transform t in regionGo.transform) { if (t.gameObject.name.StartsWith("RegionPoint")) { Vector3 position = t.position; float height = combatState.MapMetaData.GetLerpedHeightAt(position); Vector3 fixedHeightPosition = new Vector3(position.x, height, position.z); t.position = fixedHeightPosition; meshPoints.Add(t.localPosition); } } // Create new mesh from points and set to collider and mesh filter MeshCollider collider = regionGo.GetComponent <MeshCollider>(); MeshFilter mf = regionGo.GetComponent <MeshFilter>(); Mesh mesh = MeshTools.CreateHexigon(REGION_RADIUS, meshPoints); collider.sharedMesh = mesh; mf.mesh = mesh; List <MapEncounterLayerDataCell> cells = SceneUtils.GetMapEncounterLayerDataCellsWithinCollider(regionGo); for (int i = 0; i < cells.Count; i++) { MapEncounterLayerDataCell cell = cells[i]; cell.AddRegion(regionGameLogic); } }
public static RegionGameLogic CreateRegion(GameObject parent, string regionGameLogicGuid, string objectiveGuid, string name, string regionDefId, float radius = 0) { GameObject regionGo = CreateRegionGameObject(parent, name); float regionRadius = (radius > 0) ? radius : DEFAULT_REGION_RADIUS; MeshCollider collider = regionGo.AddComponent <MeshCollider>(); MeshFilter mf = regionGo.AddComponent <MeshFilter>(); Mesh mesh = MeshTools.CreateHexigon(regionRadius); collider.sharedMesh = mesh; mf.mesh = mesh; regionGo.AddComponent <TerrainDataChangeDetection>(); regionGo.AddComponent <SnapToTerrain>(); regionGo.AddComponent <MeshRenderer>(); RegionGameLogic regionGameLogic = regionGo.AddComponent <RegionGameLogic>(); regionGameLogic.encounterObjectGuid = regionGameLogicGuid; regionGameLogic.radius = regionRadius; regionGameLogic.regionDefId = regionDefId; regionGameLogic.alwaysShowRegionWhenActive = true; CreateRegionPointGameObject(regionGo, $"RegionPoint1", new Vector3(0, 0, regionRadius)); // North CreateRegionPointGameObject(regionGo, $"RegionPoint2", new Vector3(regionRadius, 0, regionRadius / 2f)); // North-East CreateRegionPointGameObject(regionGo, $"RegionPoint3", new Vector3(regionRadius, 0, -(regionRadius / 2f))); // South-East CreateRegionPointGameObject(regionGo, $"RegionPoint4", new Vector3(0, 0, -regionRadius)); // South CreateRegionPointGameObject(regionGo, $"RegionPoint5", new Vector3(-regionRadius, 0, -(regionRadius / 2f))); // South-West CreateRegionPointGameObject(regionGo, $"RegionPoint6", new Vector3(-regionRadius, 0, regionRadius / 2f)); // North-West return(regionGameLogic); }
/// <summary> /// This function builds the mesh by implementing a Cube Marching algorithm, removing duplicate vertices, calculating normals, and generating biome-based vertex colors. /// </summary> private void GenerateMesh() { List <VoxelData.Tri> geom = new List <VoxelData.Tri>(); for (int x = 0; x < data.GetLength(0); x++) { for (int y = 0; y < data.GetLength(1); y++) { for (int z = 0; z < data.GetLength(2); z++) { if (!data[x, y, z].IsHidden(0)) { data[x, y, z].MarchCube(0, geom); } } } } // combine all of the tris together into one mesh: Mesh mesh = MakeMeshFromTris(geom); // remove duplicate vertices: this.mesh.mesh = MeshTools.RemoveDuplicates(mesh, true); SetVertexColors(); }
/// <summary> /// Constructor PropertiesViewModel /// </summary> /// <param name="projectManager"></param> /// <param name="loggerService"></param> /// <param name="meshTools"></param> public PropertiesViewModel( IProjectManager projectManager, ILoggerService loggerService, ISettingsManager settingsManager, MeshTools meshTools, IModTools modTools ) : base(ToolTitle) { _settingsManager = settingsManager; _projectManager = projectManager; _loggerService = loggerService; _meshTools = meshTools; _modTools = modTools; SetupToolDefaults(); SetToNullAndResetVisibility(); nAudioSimple = NAudioSimpleEngine.Instance; NAudioSimpleEngine.Instance.PropertyChanged += NAudioEngine_PropertyChanged; StopAudioCommand = new RelayCommand(ExecuteStopPlaying, CanStopPlaying); PlayAudioCommand = new RelayCommand(ExecuteStartPlaying, CanStartPlaying); PauseAudioCommand = new RelayCommand(ExecutePausePlaying, CanPausePlaying); }
public static RegionGameLogic CreateWithdrawRegion(GameObject parent, string regionGameLogicGuid, string objectiveGuid, string name = null) { GameObject withdrawRegionGo = CreateWithdrawRegionGameObject(parent, name); MeshCollider collider = withdrawRegionGo.AddComponent <MeshCollider>(); MeshFilter mf = withdrawRegionGo.AddComponent <MeshFilter>(); Mesh mesh = MeshTools.CreateHexigon(REGION_RADIUS); collider.sharedMesh = mesh; mf.mesh = mesh; withdrawRegionGo.AddComponent <TerrainDataChangeDetection>(); withdrawRegionGo.AddComponent <SnapToTerrain>(); withdrawRegionGo.AddComponent <MeshRenderer>(); RegionGameLogic regionGameLogic = withdrawRegionGo.AddComponent <RegionGameLogic>(); regionGameLogic.encounterObjectGuid = regionGameLogicGuid; regionGameLogic.radius = REGION_RADIUS; regionGameLogic.regionDefId = "regionDef_EvacZone"; regionGameLogic.alwaysShowRegionWhenActive = true; CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint1", new Vector3(0, 0, REGION_RADIUS)); // North CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint2", new Vector3(REGION_RADIUS, 0, REGION_RADIUS / 2f)); // North-East CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint3", new Vector3(REGION_RADIUS, 0, -(REGION_RADIUS / 2f))); // South-East CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint4", new Vector3(0, 0, -REGION_RADIUS)); // South CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint5", new Vector3(-REGION_RADIUS, 0, -(REGION_RADIUS / 2f))); // South-West CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint6", new Vector3(-REGION_RADIUS, 0, REGION_RADIUS / 2f)); // North-West return(regionGameLogic); }
/* * Add a ceiling to the room */ public void AddCeiling() { GameObject ceiling = new GameObject(); ceiling.transform.parent = transform; int ceilingMaterialIndex = Random.Range(0, _ceilingMaterials.Length); MeshRenderer ceilingRendered = ceiling.AddComponent <MeshRenderer>(); ceilingRendered.material = _ceilingMaterials[ceilingMaterialIndex]; ceiling.transform.name = "Ceiling" + ceilingRendered.material.name; MeshCollider ceilingCollider = ceiling.AddComponent <MeshCollider>(); MeshFilter ceilingMeshFilter = ceiling.AddComponent <MeshFilter>(); List <Vector3> ceilingPoints = new List <Vector3>(); LineRange groundRangeX = _ground.GetXRange(); LineRange groundRangeZ = _ground.GetZRange(); ceilingPoints.Add(new Vector3(groundRangeX.max * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.min * _wall.GetWallShrink())); ceilingPoints.Add(new Vector3(groundRangeX.min * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.min * _wall.GetWallShrink())); ceilingPoints.Add(new Vector3(groundRangeX.min * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.max * _wall.GetWallShrink())); ceilingPoints.Add(new Vector3(groundRangeX.max * _wall.GetWallShrink(), _ceilingHeight, groundRangeZ.max * _wall.GetWallShrink())); PlaneRange ceilingRange = new PlaneRange( 0, 1, 0, 0, 0, 1 ); ceilingMeshFilter.mesh = MeshTools.CreateMeshFromVectors(ceilingPoints, ceilingRange); ceilingCollider.sharedMesh = ceilingMeshFilter.mesh; }
//Cube Data // Makes a cube /// <summary> /// Makes a cube with data taken from X,Y,Z coords /// </summary> /// <returns></returns> private Mesh MakeCylinder(int num) { List <Color> colors = new List <Color>(); //Set hue min and Max float hue = Mathf.Lerp(hueMin, hueMax, (num / (float)iterations)); Mesh mesh = MeshTools.MakeCylinder(5); Vector3[] verts = mesh.vertices; for (int i = 0; i < mesh.vertexCount; i++) { float tempHue = hue + (1 / (float)iterations) * verts[i].y; Color color = Color.HSVToRGB(tempHue, 1, 1); colors.Add(color); } mesh.SetColors(colors); return(mesh); }
/// <summary> /// creates a stem, growing from a position /// </summary> /// <param name="number">how long should the stem be</param> /// <param name="meshes">reference to list of meshes</param> /// <param name="pos">where to start the stem</param> /// <param name="rot">rotation of the stem</param> /// <param name="top">whether or not the stem is on top of the creature, used to calculate leaf direction</param> void GrowStem(int number, List <CombineInstance> meshes, Vector3 pos, Quaternion rot, bool top) { CombineInstance inst = new CombineInstance(); inst.mesh = MeshTools.MakeCylinder(5); inst.transform = Matrix4x4.TRS(pos, rot, new Vector3(.2f, number, .2f)); meshes.Add(inst); rot *= Quaternion.Euler(0, 180, 90); if (!top) { rot *= Quaternion.Euler(180, 0, 0); } float x = .1f; while (x < 1) { if (x * 2 < 1) { x = Random.Range(2 * x, 1); } else { break; } pos = inst.transform.MultiplyPoint(Vector3.up * x); float scale = 1 + (1 - x) * 3; GrowLeaf(1, meshes, pos, rot, scale); } }
/// <summary> /// Constructor PropertiesViewModel /// </summary> /// <param name="projectManager"></param> /// <param name="loggerService"></param> /// <param name="messageService"></param> /// <param name="meshTools"></param> /// <param name="commandManager"></param> public PropertiesViewModel( IProjectManager projectManager, ILoggerService loggerService, IMessageService messageService, MeshTools meshTools, ICommandManager commandManager ) : base(ToolTitle) { Argument.IsNotNull(() => projectManager); Argument.IsNotNull(() => messageService); Argument.IsNotNull(() => loggerService); Argument.IsNotNull(() => commandManager); Argument.IsNotNull(() => meshTools); _projectManager = projectManager; _loggerService = loggerService; _messageService = messageService; _meshTools = meshTools; SetupToolDefaults(); SetToNullAndResetVisibility(); nAudioSimple = NAudioSimpleEngine.Instance; NAudioSimpleEngine.Instance.PropertyChanged += NAudioEngine_PropertyChanged; // global commands FileSelectedCommand = new DelegateCommand <FileModel>(async(p) => await ExecuteSelectFile(p), CanOpenFile); commandManager.RegisterCommand(AppCommands.Application.FileSelected, FileSelectedCommand, this); StopAudioCommand = new RelayCommand(ExecuteStopPlaying, CanStopPlaying); PlayAudioCommand = new RelayCommand(ExecuteStartPlaying, CanStartPlaying); PauseAudioCommand = new RelayCommand(ExecutePausePlaying, CanPausePlaying); }
static private void FillBoundaryFace(TempMesh tempMesh, List <Vector3> added, ref Vector3[] tempTriangle) { // 1. Reorder added so in order ot their occurence along the perimeter. MeshUtils.ReorderList(added); // 2. Find actual face vertices var face = FindRealPolygon(added); // 3. Create triangle fans int t_fwd = 0, t_bwd = face.Count - 1, t_new = 1; bool incr_fwd = true; while (t_new != t_fwd && t_new != t_bwd) { MeshTools.AddTriangle(tempMesh, ref tempTriangle, face, t_bwd, t_fwd, t_new); if (incr_fwd) { t_fwd = t_new; } else { t_bwd = t_new; } incr_fwd = !incr_fwd; t_new = incr_fwd ? t_fwd + 1 : t_bwd - 1; } }
void OnGUI() { float y = 0; if (GUI.Button(new Rect(0, y, 120, 30), "create mesh")) { MeshFilter mf = gameObject.GetComponent <MeshFilter> (); mf.mesh = MeshTools.createFromHMap(null, 5, 5, 10, 10, 0); } if (GUI.Button(new Rect(0, y += 30, 120, 30), "combine mesh")) { MeshFilter mf = gameObject.GetComponent <MeshFilter> (); MeshTools.combine(transform); } if (GUI.Button(new Rect(0, y += 30, 120, 30), "weld mesh")) { MeshFilter mf = gameObject.GetComponent <MeshFilter> (); MeshTools.weld(transform, 1f, true); } if (GUI.Button(new Rect(0, y += 30, 120, 30), "split mesh")) { MeshFilter mf = gameObject.GetComponent <MeshFilter> (); MeshFilter splitplane = GameObject.Find("splitplane").GetComponent <MeshFilter> (); Vector3[] v = splitplane.mesh.vertices; int[] tri = splitplane.mesh.triangles; Matrix4x4 m = gameObject.transform.worldToLocalMatrix * splitplane.transform.localToWorldMatrix; mf.mesh = MeshTools.split(mf.mesh, new Plane(m.MultiplyPoint(v[tri[0]]), m.MultiplyPoint(v[tri[1]]), m.MultiplyPoint(v[tri[2]]))); } if (GUI.Button(new Rect(0, y += 30, 120, 30), "sub polytope")) { MeshFilter mf = gameObject.GetComponent <MeshFilter> (); mf.mesh = MeshTools.subdivision(mf.mesh); } }
public bool ExportMeshWithMaterials(Stream meshStream, FileInfo outfile, List <Archive> archives, string matRepo, EUncookExtension eUncookExtension = EUncookExtension.dds, bool isGLBinary = true, bool LodFilter = true) { if (matRepo == null) { throw new Exception("Material Repository Path is not set, Please select a folder in the Material Repository Settings where your textures will output, Generating the complete dump is not required."); } var cr2w = _wolvenkitFileService.TryReadRED4File(meshStream); if (cr2w == null || !cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().Any() || !cr2w.Chunks.Select(_ => _.Data).OfType <rendRenderMeshBlob>().Any()) { return(false); } MeshTools.MeshBones meshBones = new MeshTools.MeshBones(); meshBones.boneCount = cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().First().BoneNames.Count; if (meshBones.boneCount != 0) // for rigid meshes { meshBones.Names = RIG.GetboneNames(cr2w); meshBones.WorldPosn = MeshTools.GetMeshBonesPosn(cr2w); } RawArmature Rig = MeshTools.GetNonParentedRig(meshBones); MemoryStream ms = MeshTools.GetMeshBufferStream(meshStream, cr2w); MeshesInfo meshinfo = MeshTools.GetMeshesinfo(cr2w); List <RawMeshContainer> expMeshes = MeshTools.ContainRawMesh(ms, meshinfo, LodFilter); if (meshBones.boneCount == 0) // for rigid meshes { for (int i = 0; i < expMeshes.Count; i++) { expMeshes[i].weightcount = 0; } } MeshTools.UpdateMeshJoints(ref expMeshes, Rig, meshBones); ModelRoot model = MeshTools.RawMeshesToGLTF(expMeshes, Rig); ParseMaterials(cr2w, meshStream, outfile, archives, matRepo, eUncookExtension); if (isGLBinary) { model.SaveGLB(outfile.FullName); } else { model.SaveGLTF(outfile.FullName); } meshStream.Dispose(); meshStream.Close(); return(true); }
/// <summary> /// Pieces together a mesh based on a set position, rotation, and iterations. /// </summary> /// <param name="num">The number of iterations that have passed already.</param> /// <param name="meshes">Stores all the meshes this function constructs.</param> /// <param name="pos">The position of the endPoint of the previous stem segment/spawner location.</param> /// <param name="rot">The rotation of the previous stem segment/spawner location</param> private void Grow(int num, List <CombineInstance> meshes, Vector3 pos, Quaternion rot) { if (num <= 0) { return; //stop recursive function } //Adjust randomness for scale values: Vector3 tempStemScaling = (stemScaling * Random.Range(minRandomScaling, maxRandomScaling)) * objectScaling; Vector3 tempLeafScaling = (leafScaling * Random.Range(minRandomScaling, maxRandomScaling)) * objectScaling; //Adjust randomness for leaves: numberOfLeaves = Random.Range(minLeaves, maxLeaves); // Add Stem Mesh: CombineInstance stem = new CombineInstance(); stem.mesh = MeshTools.MakeCylinder(5); AddColorToVertices(stem.mesh, num); stem.transform = Matrix4x4.TRS(pos, rot, tempStemScaling); meshes.Add(stem); // Add Leaves Mesh: for (int i = 1; i <= numberOfLeaves; i++) { CombineInstance leaves = new CombineInstance(); leaves.mesh = MeshTools.MakeCube(); AddColorToVertices(leaves.mesh, num); float rotAmount = 360 / (numberOfLeaves * i); Quaternion leafRot = rot * Quaternion.Euler(leafOffsetAngleX, leafOffsetAngleY * rotAmount, leafOffsetAngleZ); leaves.transform = Matrix4x4.TRS(pos, leafRot, tempLeafScaling); meshes.Add(leaves); } // Count down number of passes: num--; // Get the position of the end of this section: pos = stem.transform.MultiplyPoint(new Vector3(0, 1, 0)); //Generate random angles based on set angle values: float randX = stemAngleX + Random.Range(minRandomAngle, maxRandomAngle); float randY = stemAngleY + Random.Range(minRandomAngle, maxRandomAngle); float randZ = stemAngleZ + Random.Range(minRandomAngle, maxRandomAngle); //Create a Quaternion to change the local transform to the world Vector3.up: Quaternion rot1 = Quaternion.FromToRotation(transform.up, Vector3.up); //Create a Quaternion using the random angles from earlier: Quaternion rot2 = Quaternion.Euler(randX, randY, randZ); //Use a slerp to create a Quaternion between rot1 and rot2, leaning more towards randomness in later segments: Quaternion finalRot = Quaternion.Slerp(rot1, rot2, (num / (float)iterations)); //Grow another segment: Grow(num, meshes, pos, finalRot); }
void CombineMesh() { GameObject existingGemCells = GameObject.Find("GemCells"); if (existingGemCells != null) { Mesh combinedMesh = MeshTools.CombineGameObjectMeshes(currentGemsObjs); AssetDatabase.CreateAsset(combinedMesh, "Assets/" + settings.combineMeshOutPath); AssetDatabase.SaveAssets(); //DestroyImmediate(existingGemCells); } }
/// <summary> /// creates the mesh of the cube that is generated /// </summary> private Mesh MakeCube() { Mesh mesh = MeshTools.MakeTaperCube(.2f); List <Color> colors = new List <Color>(); for (int i = 0; i < mesh.vertexCount; i++) { Color color = Color.HSVToRGB(Random.Range(0, 2), 1, Random.Range(0, 2)); colors.Add(color); } mesh.SetColors(colors); return(mesh); }
private Mesh MakeCube1() { List <Color> colors = new List <Color>(); Mesh mesh = MeshTools.MakeSmoothCube(); for (int i = 0; i < mesh.vertexCount; i++) { Color color = Color.HSVToRGB(0, Random.Range(0, 2), 0); colors.Add(color); } mesh.SetColors(colors); return(mesh); }
public bool ExportMeshWithMaterials(Stream meshStream, FileInfo outfile, List <Archive> archives, string matRepo, EUncookExtension eUncookExtension = EUncookExtension.dds, bool isGLBinary = true, bool LodFilter = true) { if (matRepo == null) { throw new Exception("Material Repository Path is not set, Please select a folder in the Material Repository Settings where your textures will output, Generating the complete dump is not required."); } var cr2w = _wolvenkitFileService.TryReadRED4File(meshStream); if (cr2w == null || !cr2w.Chunks.Select(_ => _.Data).OfType <CMesh>().Any() || !cr2w.Chunks.Select(_ => _.Data).OfType <rendRenderMeshBlob>().Any()) { return(false); } var rendblob = cr2w.Chunks.Select(_ => _.Data).OfType <rendRenderMeshBlob>().First(); var rendbuffer = cr2w.Buffers[rendblob.RenderBuffer.Buffer.Value - 1]; meshStream.Seek(rendbuffer.Offset, SeekOrigin.Begin); var ms = new MemoryStream(); meshStream.DecompressAndCopySegment(ms, rendbuffer.DiskSize, rendbuffer.MemSize); var meshesinfo = MeshTools.GetMeshesinfo(rendblob); List <RawMeshContainer> expMeshes = MeshTools.ContainRawMesh(ms, meshesinfo, LodFilter); MeshTools.UpdateSkinningParamCloth(ref expMeshes, meshStream, cr2w); RawArmature Rig = MeshTools.GetOrphanRig(rendblob); ModelRoot model = MeshTools.RawMeshesToGLTF(expMeshes, Rig); ParseMaterials(cr2w, meshStream, outfile, archives, matRepo, eUncookExtension); if (isGLBinary) { model.SaveGLB(outfile.FullName); } else { model.SaveGLTF(outfile.FullName); } meshStream.Dispose(); meshStream.Close(); return(true); }
/// <summary> /// creates the mesh of the cube that is generated /// </summary> private Mesh MakeCube() { List <Color> colors = new List <Color>(); Mesh mesh = MeshTools.MakeCube(); for (int i = 0; i < mesh.vertexCount; i++) { Color color = Color.HSVToRGB(1, 1, 1); colors.Add(color); } mesh.SetColors(colors); return(mesh); }
public ModTools( ILoggerService loggerService, IProgressService <double> progressService, IHashService hashService, Red4ParserService wolvenkitFileService, MeshTools meshTools, IArchiveManager archiveManager ) { _loggerService = loggerService; _progressService = progressService; _hashService = hashService; _wolvenkitFileService = wolvenkitFileService; _meshTools = meshTools; _archiveManager = archiveManager; }
//private readonly MaterialTools _materialTools; public ModTools( ILoggerService loggerService, IProgressService <double> progressService, IHashService hashService, Red4ParserService wolvenkitFileService, MeshTools meshTools //MaterialTools materialTools ) { _loggerService = loggerService; _progressService = progressService; _hashService = hashService; _wolvenkitFileService = wolvenkitFileService; _meshTools = meshTools; //_materialTools = materialTools; }
public void DrawLine() { if (Points.Length < 2) { return; } ThisMesh = new Mesh(); if (WipeAmount < 0.001f) { return; } SplitQuads = new List <Vector3[]>(); SourceSlices = new List <Slice2D>(); PolyLine = new List <Vector3>(); // Adjusted Points are trimmed (fillamount) then scaled var adjPoints = Points.AdjustPoints(WipeAmount, WipeMode, Xscale, Yscale, ShowDebug) .OffsetPoints(Offset); SourceSlices = InitializeQuads(adjPoints, SourceSlices); FinalSlices = Continuous ? SetAveragedSlices(SourceSlices) : SourceSlices; // Prepare vertices for (int index = 0; index < FinalSlices.Count; index++) { //if (HasHat && index == 0) continue; Slice2D slice = FinalSlices[index]; PolyLine.Add(slice.P1); PolyLine.Add(slice.P2); } ThisMesh.vertices = PolyLine.ToArray(); MeshTools.AssignDefaultUvs(ThisMesh); if (Continuous) { MeshTools.CreateConnectedMesh(ThisMesh, FinalSlices); } else { MeshTools.CreateSplitMesh(ThisMesh, FinalSlices); } //ThisMaterial.EnableKeyword("_EMISSION"); // Unity5 Standard Material Requirement //"_EmissionColor" ThisMaterial.SetColor("_Color", LineColor); }
public static void Regenerate(this RegionGameLogic regionGameLogic) { GameObject regionGo = regionGameLogic.gameObject; CombatGameState combatState = UnityGameInstance.BattleTechGame.Combat; List <Vector3> meshPoints = new List <Vector3>(); // Remove old region location from layer data cells List <MapEncounterLayerDataCell> beforeCells = SceneUtils.GetMapEncounterLayerDataCellsWithinCollider(regionGo); for (int i = 0; i < beforeCells.Count; i++) { MapEncounterLayerDataCell cell = beforeCells[i]; cell.RemoveRegion(regionGameLogic); } // Get all region points and fix the y height foreach (Transform t in regionGo.transform) { if (t.gameObject.name.StartsWith("RegionPoint")) { Vector3 position = t.position; float height = combatState.MapMetaData.GetLerpedHeightAt(position); Vector3 fixedHeightPosition = new Vector3(position.x, height, position.z); t.position = fixedHeightPosition; meshPoints.Add(t.localPosition); } } // Create new mesh from points and set to collider and mesh filter MeshCollider collider = regionGo.GetComponent <MeshCollider>(); MeshFilter mf = regionGo.GetComponent <MeshFilter>(); Mesh mesh = MeshTools.CreateHexigon(regionGameLogic.radius, meshPoints); collider.sharedMesh = mesh; mf.mesh = mesh; List <MapEncounterLayerDataCell> afterCells = SceneUtils.GetMapEncounterLayerDataCellsWithinCollider(regionGo); for (int i = 0; i < afterCells.Count; i++) { MapEncounterLayerDataCell cell = afterCells[i]; cell.AddRegion(regionGameLogic); } }
/// <summary> /// This creates the actual mesh /// </summary> /// <param name="num">the number of iterations</param> /// <returns></returns> private Mesh MakeCube(int num) { List <Color> colors = new List <Color> (); float hue = 1; Mesh mesh = MeshTools.MakeCube(); Vector3[] verts = mesh.vertices; for (int i = 0; i < mesh.vertexCount; i++) { float tempHue = hue + (1 * verts[i].y); Color color = Color.HSVToRGB(tempHue, .5f, 1); colors.Add(color); } mesh.SetColors(colors); return(mesh); }
/// <summary> /// creates the mesh and colors it by vertex /// </summary> /// <param name="num">the amount of iterations</param> /// <returns></returns> private Mesh MakeCube(int num) { List <Color> colors = new List <Color>(); float hueMin = .1f; float hueMax = .001f; float hue = Mathf.Lerp(hueMin, hueMax, (num / (float)iterations)); Mesh mesh = MeshTools.MakeCube(); for (int i = 0; i < mesh.vertexCount; i++) { float tempHue = hue;// + (1/(float)iterations) * pos.y; Color color = Color.HSVToRGB(tempHue, 1, 1); colors.Add(color); } mesh.SetColors(colors); return(mesh); }
public bool ExportMeshWithMaterials(Stream meshStream, FileInfo outfile, List <Archive> archives, string matRepo, EUncookExtension eUncookExtension = EUncookExtension.dds, bool isGLBinary = true, bool LodFilter = true) { if (matRepo == null) { throw new Exception("Material Repository Path is not set, Please select a folder in the Material Repository Settings where your textures will output, Generating the complete dump is not required."); } var cr2w = _wolvenkitFileService.ReadRed4File(meshStream); if (cr2w == null || cr2w.RootChunk is not CMesh cMesh || cMesh.RenderResourceBlob.Chunk is not rendRenderMeshBlob rendblob) { return(false); } using var ms = new MemoryStream(rendblob.RenderBuffer.Buffer.GetBytes()); var meshesinfo = MeshTools.GetMeshesinfo(rendblob, cr2w); var expMeshes = MeshTools.ContainRawMesh(ms, meshesinfo, LodFilter); MeshTools.UpdateSkinningParamCloth(ref expMeshes, meshStream, cr2w); var Rig = MeshTools.GetOrphanRig(rendblob, cr2w); var model = MeshTools.RawMeshesToGLTF(expMeshes, Rig); ParseMaterials(cr2w, meshStream, outfile, archives, matRepo, eUncookExtension); if (isGLBinary) { model.SaveGLB(outfile.FullName); } else { model.SaveGLTF(outfile.FullName); } meshStream.Dispose(); meshStream.Close(); return(true); }
private MeshFilter CreateWall( float length, float height, float maxDismension, Material mat) { var name = "wall" + length.ToString() + "x" + height.ToString(); var mf = MeshTools.CreateMeshObj(name, mat); mf.mesh = MeshTools.CreatePlaneMesh( length, height, 2, 2, name, _IsSerializeMeshes, MAZE_MESHDATA_PATH, maxDismension); return(mf); }
// Start is called before the first frame update void Start() { rng = new System.Random(); mesh = MeshTools.Get(gameObject); size = GetComponent <MeshRenderer>().bounds.size; canvasSize = new Vector2(size.x, size.y); print(canvasSize); // MeshHelper.Subdivide(mesh, 6); // divides a single quad into 6x6 quads // Vector3[] vertices = mesh.vertices; // Vector3[] normals = mesh.normals; // for (var i = 0; i < vertices.Length; i++) { // vertices[i] += normals[i] * Mathf.Sin((float)i) / 4f; // } // mesh.vertices = vertices; Fracture(new Vector2(0, 0)); }
/// <summary> /// Constructor PropertiesViewModel /// </summary> /// <param name="projectManager"></param> /// <param name="loggerService"></param> /// <param name="meshTools"></param> public PropertiesViewModel( IProjectManager projectManager, ILoggerService loggerService, ISettingsManager settingsManager, MeshTools meshTools, IModTools modTools ) : base(ToolTitle) { _settingsManager = settingsManager; _projectManager = projectManager; _loggerService = loggerService; _meshTools = meshTools; _modTools = modTools; SetupToolDefaults(); SideInDockedMode = DockSide.Left; SetToNullAndResetVisibility(); PreviewAudioCommand = ReactiveCommand.Create <string, string>(str => str); }
private GameObject CreateFloor( float width, float depth, Material mat) { var name = "floor" + width.ToString() + "x" + depth.ToString(); var floor = MeshTools.CreateMeshObj(name, mat); floor.sharedMesh = MeshTools.CreatePlaneMesh( width, depth, 2, 2, name, _IsSerializeMeshes, MAZE_MESHDATA_PATH, Mathf.Max(width, depth) ); floor.transform.rotation = Quaternion.Euler(90, 0, 0); return(floor.gameObject); }