public static MeshDraft Back1(Vector3 center, float width, float length, float height) { var draft = new MeshDraft(); int plankCount = Random.Range(1, 5); float plankStep = height / plankCount; float plankHeight = plankStep * Random.Range(0.3f, 0.8f); float plankWidth = width - length * 2; float offeset = 0; if (plankCount > 1) { offeset = RandomE.Range(0, (plankStep - plankHeight) / 2, 3); } Vector3 startPosition = Vector3.up * (-height / 2 + plankStep - plankHeight / 2 - offeset); for (int i = 0; i < plankCount; i++) { var plank = MeshDraft.Hexahedron(plankWidth, length, plankHeight, false); plank.Move(startPosition + Vector3.up * i * plankStep); draft.Add(plank); } var rod = MeshDraft.Hexahedron(length, length, height, false); rod.Move(Vector3.left * (width / 2 - length / 2)); draft.Add(rod); rod.Move(Vector3.right * (width - length)); draft.Add(rod); draft.Move(center + Vector3.up * height / 2); return(draft); }
public static MeshDraft RodBack(Vector3 center, float width, float length, float height) { var draft = new MeshDraft(); int rodCount = Random.Range(1, 5); float maxWidth = (width - length*2)/rodCount; float rodWidth = RandomE.Range(maxWidth/4, maxWidth*3/4, 3); float interval = (width - length*2 - rodWidth*rodCount)/(rodCount + 1); float upperRodHeight = Mathf.Min(height*3/4, length*Random.Range(1, 4)); float rodHeight = height - upperRodHeight; var leftRod = MeshDraft.Hexahedron(length, length, rodHeight); leftRod.Move(Vector3.left*(width - length)/2 + Vector3.down*upperRodHeight/2); draft.Add(leftRod); leftRod.Move(Vector3.right*(width - length)); draft.Add(leftRod); Vector3 startPosition = Vector3.left*(width/2 - length - interval - rodWidth/2) + Vector3.down*upperRodHeight/2; for (int i = 0; i < rodCount; i++) { var rod = MeshDraft.Hexahedron(rodWidth, length, rodHeight); rod.Move(startPosition + Vector3.right*i*(rodWidth + interval)); draft.Add(rod); } var upperRod = MeshDraft.Hexahedron(width, length, upperRodHeight); upperRod.Move(Vector3.up*rodHeight/2); draft.Add(upperRod); draft.Move(center + Vector3.up*height/2); return draft; }
public void InteralCacheOrganTemplates() { CachedOrganTemplates = (new[] { new MeshVariant { mesh = MeshRef } }.Concat(MeshVariants)).Select(variant => { var newDraft = new MeshDraft(variant.mesh); var bounds = variant.mesh.bounds; Vector3 translatePostMesh; if (UseMeshOrigin) { translatePostMesh = new Vector3((bounds.center.x + bounds.size.x / 2f) * IndividualScale.x, 0, 0); } else { newDraft.Move(Vector3.right * (-bounds.center.x + bounds.size.x / 2)); translatePostMesh = new Vector3(bounds.size.x * IndividualScale.x, 0, 0); } newDraft.Scale(IndividualScale); return(new TurtleOrganTemplate( newDraft, variant.materialOverride ?? material, translatePostMesh, AlsoMove )); }).ToArray(); }
public static MeshDraft Back1(Vector3 center, float width, float length, float height) { var draft = new MeshDraft(); int plankCount = Random.Range(1, 5); float plankStep = height/plankCount; float plankHeight = plankStep*Random.Range(0.3f, 0.8f); float plankWidth = width - length*2; float offeset = 0; if (plankCount > 1) { offeset = RandomE.Range(0, (plankStep - plankHeight)/2, 3); } Vector3 startPosition = Vector3.up*(-height/2 + plankStep - plankHeight/2 - offeset); for (int i = 0; i < plankCount; i++) { var plank = MeshDraft.Hexahedron(plankWidth, length, plankHeight); plank.Move(startPosition + Vector3.up*i*plankStep); draft.Add(plank); } var rod = MeshDraft.Hexahedron(length, length, height); rod.Move(Vector3.left*(width/2 - length/2)); draft.Add(rod); rod.Move(Vector3.right*(width - length)); draft.Add(rod); draft.Move(center + Vector3.up*height/2); return draft; }
public override MeshDraft Construct(Vector2 parentLayoutOrigin) { List <Vector2> roofPolygon2; List <Vector3> roofPolygon3; var roofDraft = ConstructRoofBase(out roofPolygon2, out roofPolygon3); var skeletonGenerator = new StraightSkeletonGenerator(); var skeleton = skeletonGenerator.Generate(roofPolygon2); var roofTop = new MeshDraft(); foreach (var skeletonPolygon2 in skeleton.polygons) { if (skeletonPolygon2.Count == 3) { roofTop.Add(ConstructGableDraft(skeletonPolygon2, RoofPitch)); } else { roofTop.Add(ConstructContourDraft(skeletonPolygon2, RoofPitch)); } } roofTop.Move(Vector3.up * roofConfig.thickness); roofDraft.Add(roofTop) .Paint(roofColor); return(roofDraft); }
public static MeshDraft RodBack(Vector3 center, float width, float length, float height) { var draft = new MeshDraft(); int rodCount = Random.Range(1, 5); float maxWidth = (width - length * 2) / rodCount; float rodWidth = RandomE.Range(maxWidth / 4, maxWidth * 3 / 4, 3); float interval = (width - length * 2 - rodWidth * rodCount) / (rodCount + 1); float upperRodHeight = Mathf.Min(height * 3 / 4, length * Random.Range(1, 4)); float rodHeight = height - upperRodHeight; var leftRod = MeshDraft.Hexahedron(length, length, rodHeight, false); leftRod.Move(Vector3.left * (width - length) / 2 + Vector3.down * upperRodHeight / 2); draft.Add(leftRod); leftRod.Move(Vector3.right * (width - length)); draft.Add(leftRod); Vector3 startPosition = Vector3.left * (width / 2 - length - interval - rodWidth / 2) + Vector3.down * upperRodHeight / 2; for (int i = 0; i < rodCount; i++) { var rod = MeshDraft.Hexahedron(rodWidth, length, rodHeight, false); rod.Move(startPosition + Vector3.right * i * (rodWidth + interval)); draft.Add(rod); } var upperRod = MeshDraft.Hexahedron(width, length, upperRodHeight, false); upperRod.Move(Vector3.up * rodHeight / 2); draft.Add(upperRod); draft.Move(center + Vector3.up * height / 2); return(draft); }
public static MeshDraft XStretchers(Vector3[] legCenters, float legWidth, float legHeight) { var draft = new MeshDraft(); legWidth = RandomE.Range(legWidth/2, legWidth*3/4, 2); draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[2], legWidth)); draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[3], legWidth)); draft.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight/2, 2)); return draft; }
public static MeshDraft XStretchers(Vector3[] legCenters, float legWidth, float legHeight) { var draft = new MeshDraft(); legWidth = RandomE.Range(legWidth / 2, legWidth * 3 / 4, 2); draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[2], legWidth)); draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[3], legWidth)); draft.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight / 2, 2)); return(draft); }
public static MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight) { var draft = new MeshDraft(); legWidth = RandomE.Range(legWidth/2, legWidth, 3); draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[3], legWidth)); draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[2], legWidth)); Vector3 leftCenter = (legCenters[3] + legCenters[0])/2; Vector3 rightCenter = (legCenters[2] + legCenters[1])/2; draft.Add(ChairGenerator.BeamDraft(leftCenter, rightCenter, legWidth)); draft.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3)); return draft; }
public static MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight) { var draft = new MeshDraft(); legWidth = RandomE.Range(legWidth / 2, legWidth, 3); draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[3], legWidth)); draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[2], legWidth)); Vector3 leftCenter = (legCenters[3] + legCenters[0]) / 2; Vector3 rightCenter = (legCenters[2] + legCenters[1]) / 2; draft.Add(ChairGenerator.BeamDraft(leftCenter, rightCenter, legWidth)); draft.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3)); return(draft); }
private MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight) { var draft = new MeshDraft(); legWidth = RandomE.Range(legWidth / 2, legWidth, 3); draft.Add(BeamDraft(legCenters[0], legCenters[3], legWidth)); draft.Add(BeamDraft(legCenters[1], legCenters[2], legWidth)); var leftCenter = (legCenters[3] + legCenters[0]) / 2; var rightCenter = (legCenters[2] + legCenters[1]) / 2; draft.Add(BeamDraft(leftCenter, rightCenter, legWidth)); draft.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3)); return(draft); }
public void Generate() { meshFilter = GetComponent <MeshFilter>(); MeshDraft draft = TerrainDraft(TerrainSize, CellSize, NoiseOffset, NoiseScale, Gradient); draft.Move(Vector3.left * TerrainSize.x / 2 + Vector3.back * TerrainSize.z / 2); meshFilter.mesh = draft.ToMesh(); MeshCollider meshCollider = GetComponent <MeshCollider>(); if (meshCollider) { meshCollider.sharedMesh = meshFilter.mesh; } }
public static MeshDraft BoxStretchers(Vector3[] legCenters, float legWidth, float legHeight) { var draft = new MeshDraft(); legWidth = RandomE.Range(legWidth / 2, legWidth, 3); MeshDraft stretcher0 = ChairGenerator.BeamDraft(legCenters[0], legCenters[1], legWidth); stretcher0.Add(ChairGenerator.BeamDraft(legCenters[2], legCenters[3], legWidth)); stretcher0.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3)); MeshDraft stretcher1 = ChairGenerator.BeamDraft(legCenters[0], legCenters[3], legWidth); stretcher1.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[2], legWidth)); stretcher1.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3)); draft.Add(stretcher0); draft.Add(stretcher1); return(draft); }
/// <summary> /// Convert the draft to a mesh and assign it to the tile's MeshFilter component. /// </summary> private void DraftToMesh() { // Move the center of the vertices to the center of the tile draft.Move(Vector3.left * TerrainController.TerrainSize.x / 2 + Vector3.back * TerrainController.TerrainSize.z / 2); meshFilter.mesh = draft.ToMesh(); meshCollider.sharedMesh = meshFilter.mesh; meshRenderer.enabled = true; // Start generating points for asset placement // now that we know where each biome is (BiomeEdges, YEdgesPerXStep and XEdgesPerYStep) if (assetPlacement) { assetPlacement.GenerateSpawnPoints(); } }
public void Generate() { Vector3 terrainSize = new Vector3(terrainSizeX, terrainSizeY, terrainSizeZ); var draft = LowPolyTerrainGenerator.TerrainDraft(terrainSize, cellSize, noiseScale, grad); vert_x = (int)(terrainSizeX / cellSize); vert_z = (int)(terrainSizeZ / cellSize); for (int i = 0; i < 9; i++) { MeshDraft temp = LowPolyTerrainGenerator.TerrainDraft(terrainSize, cellSize, noiseScale, grad); temp.Move(Vector3.left * terrainSizeX / 2 + Vector3.back * terrainSizeZ / 2); drafts.Add(temp); } draft.Move(Vector3.left * terrainSizeX / 2 + Vector3.back * terrainSizeZ / 2); meshFilter.mesh = draft.ToMesh(); meshCollider.sharedMesh = draft.ToMesh(); //meshCollider2.sharedMesh = draft.ToMesh(); MorphFitRight(drafts[1], drafts[0]); MorphFitRight(drafts[2], drafts[1]); MorphFitRight(drafts[5], drafts[4]); MorphFitRight(drafts[7], drafts[6]); MorphFitRight(drafts[4], drafts[3]); MorphFitRight(drafts[8], drafts[7]); MorphFitDown(drafts[3], drafts[0]); MorphFitDown(drafts[4], drafts[1]); MorphFitDown(drafts[5], drafts[2]); MorphFitDown(drafts[6], drafts[3]); MorphFitDown(drafts[7], drafts[4]); MorphFitDown(drafts[8], drafts[5]); for (int i = 0; i < 9; i++) { meshes.Add(drafts[i].ToMesh()); } }
private MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight) { var draft = new MeshDraft(); legWidth = RandomE.Range(legWidth/2, legWidth, 3); draft.Add(BeamDraft(legCenters[0], legCenters[3], legWidth)); draft.Add(BeamDraft(legCenters[1], legCenters[2], legWidth)); var leftCenter = (legCenters[3] + legCenters[0])/2; var rightCenter = (legCenters[2] + legCenters[1])/2; draft.Add(BeamDraft(leftCenter, rightCenter, legWidth)); draft.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3)); return draft; }
public void Rebuild(int sleepMs = 0) { if (!needRebuild) { return; } var parentMap = gameObject.GetComponentInParent <TestMap>(); if (start.x < 0 || start.y < 0 || end.x < 0 || end.y < 0) { return; // will cause fatal error } mapData = DDA.GetTilesBetween(start, end); if (mapData == null) { return; } float tileSize = parentMap.tileSize; if (thread != null && thread.IsAlive) { return; } thread = new Thread(() => { Thread.Sleep(sleepMs); MeshDraft chunkMesh = new MeshDraft(); int gameObjectCount = 0; foreach (var tile in mapData.tiles) { //if (!tile.seen) continue; MeshDraft tileMesh = parentMap.GetCachedTerMesh(tile.ter); // probably will not work in non main thread if (tileMesh != null) { if (chunkMesh.vertexCount + tileMesh.vertexCount < 65000) { MeshDraft tileMeshCopy = tileMesh.Clone(); tileMeshCopy.Move(new Vector3((tile.loc.x - start.x) * tileSize, tile.loc.y * tileSize, (tile.loc.z - start.y) * tileSize)); chunkMesh.Add(tileMeshCopy); } else { AssignMesh(chunkMesh, "subchunk" + gameObjectCount.ToString("D2")); gameObjectCount++; chunkMesh = new MeshDraft(); } } } if (chunkMesh.vertexCount > 0 && gameObjectCount == 0) { AssignMesh(chunkMesh); } else if (chunkMesh.vertexCount > 0) { AssignMesh(chunkMesh, "subchunk" + gameObjectCount.ToString("D2")); } }); thread.Start(); }
private void Start() { draft = MeshE.PlaneDraft(xSize, zSize, xSegments, zSegments); draft.Move(Vector3.left * xSize / 2 + Vector3.back * zSize / 2); Generate(); }
private void Start() { draft = MeshE.PlaneDraft(xSize, zSize, xSegments, zSegments); draft.Move(Vector3.left*xSize/2 + Vector3.back*zSize/2); Generate(); }