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); }
private static MeshDraft Seat0(Vector3 center, float width, float length, float height) { var draft = MeshDraft.Hexahedron(width, length, height, false); draft.Move(center + Vector3.up * height / 2); return(draft); }
private static MeshDraft Leg0(Vector3 center, float width, float height) { var draft = MeshDraft.Hexahedron(width, width, height); draft.Move(center + Vector3.up * height / 2); return(draft); }
public static MeshDraft FlatOverhangRoof(Vector3 a, Vector3 b, Vector3 c, Vector3 d) { Vector3 width = b - a; Vector3 length = c - b; Vector3 roofHeight = Vector3.up * FlatOverhangRoofHeight; var draft = MeshDraft.Hexahedron(width + width.normalized, length + length.normalized, roofHeight); draft.Move((a + c) / 2 + roofHeight / 2); draft.Paint(Khrushchyovka.roofColor); return(draft); }
public static MeshDraft EntranceRoofed(Vector3 origin, Vector3 width, Vector3 height) { var draft = Entrance(origin, width, height); Vector3 roofLength = Vector3.Cross(width, height).normalized *EntranceRoofLength; Vector3 roofHeight = Vector3.up * EntranceRoofHeight; var roof = MeshDraft.Hexahedron(width, roofLength, roofHeight); roof.Move(origin + width / 2 - roofLength / 2 + height - roofHeight / 2); roof.Paint(Khrushchyovka.roofColor); draft.Add(roof); return(draft); }
public static MeshDraft BeamDraft(Vector3 from, Vector3 to, float width, float rotation = 0) { var up = to - from; var draft = MeshDraft.Hexahedron(width, width, up.magnitude); Vector3 direction = up; direction.y = 0; var quaternion = Quaternion.identity; if (direction != Vector3.zero) { quaternion = Quaternion.LookRotation(direction); } draft.Rotate(Quaternion.FromToRotation(Vector3.up, up)*Quaternion.Euler(0, rotation, 0)*quaternion); draft.Move((from + to)/2); return draft; }
private static MeshDraft Windowpane(Vector3 origin, Vector3 width, Vector3 heigth) { Vector3 right = width.normalized; Vector3 normal = Vector3.Cross(width, heigth).normalized; var draft = new MeshDraft(); int rodCount = Mathf.FloorToInt(width.magnitude / WindowSegmentMinWidth); float interval = width.magnitude / (rodCount + 1); Vector3 frameWidth = right * WindowFrameWidth / 2; Vector3 frameHeight = Vector3.up * WindowFrameWidth / 2; Vector3 frameLength = normal * WindowFrameWidth / 2; Vector3 startPosition = origin + heigth / 2 + frameLength / 2; for (int i = 0; i < rodCount; i++) { var frame = MeshDraft.Hexahedron(frameWidth * 2, frameLength, heigth - frameHeight * 2, Directions.Left | Directions.Back | Directions.Right); frame.Move(startPosition + right * (i + 1) * interval); draft.Add(frame); } Vector3 windowCorner = origin + frameWidth + frameHeight; Vector3 windowWidth = width - frameWidth * 2; Vector3 windowHeigth = heigth - frameHeight * 2; var window = PerforatedQuad(origin, width, heigth, windowCorner, windowWidth, windowHeigth); draft.Add(window); var hole = MeshDraft.Hexahedron(windowWidth, frameLength, windowHeigth, Directions.All & ~Directions.ZAxis); hole.Move(startPosition + width / 2); hole.FlipFaces(); draft.Add(hole); draft.Paint(Khrushchyovka.frameColor); var glass = MeshDraft.Quad(windowCorner + frameLength, windowWidth, windowHeigth); glass.Paint(Khrushchyovka.glassColor); draft.Add(glass); return(draft); }
public static MeshDraft AtticVented(Vector3 origin, Vector3 width, Vector3 height) { Vector3 right = width.normalized; Vector3 center = origin + width / 2 + height / 2; Vector3 holeOrigin = center - right * AtticHoleWidth / 2 - Vector3.up * AtticHoleHeight / 2; Vector3 holeWidth = right * AtticHoleWidth; Vector3 holeHeight = Vector3.up * AtticHoleHeight; Vector3 holeDepth = Vector3.Cross(width, height).normalized *AtticHoleDepth; var draft = PerforatedQuad(origin, width, height, holeOrigin, holeWidth, holeHeight); draft.Paint(Khrushchyovka.wallColor); var hexahedron = MeshDraft.Hexahedron(holeWidth, holeDepth, holeHeight, Directions.All & ~Directions.Back); hexahedron.Move(center + holeDepth / 2); hexahedron.FlipFaces(); hexahedron.Paint(Khrushchyovka.roofColor); draft.Add(hexahedron); return(draft); }
private static MeshDraft Window(Vector3 origin, Vector3 width, Vector3 height, float widthOffset, float heightOffset, float windowHeight) { Vector3 right = width.normalized; Vector3 frameOrigin = origin + right * widthOffset + Vector3.up * heightOffset; Vector3 frameWidth = right * (width.magnitude - widthOffset * 2); Vector3 frameHeight = Vector3.up * windowHeight; Vector3 frameDepth = Vector3.Cross(width, height).normalized *WindowDepth; var draft = PerforatedQuad(origin, width, height, frameOrigin, frameWidth, frameHeight); var frame = MeshDraft.Hexahedron(frameWidth, -frameDepth, frameHeight, Directions.All & ~Directions.ZAxis); frame.Move(frameOrigin + frameWidth / 2 + frameHeight / 2 + frameDepth / 2); draft.Add(frame); draft.Paint(Khrushchyovka.wallColor); draft.Add(Windowpane(frameOrigin + frameDepth, frameWidth, frameHeight)); return(draft); }
public static MeshDraft SocleWindowed(Vector3 origin, Vector3 width, Vector3 height) { Vector3 right = width.normalized; Vector3 windowOrigin = origin + width / 2 - right * SocleWindowWidth / 2 + Vector3.up * SocleWindowHeightOffset; Vector3 windowWidth = right * SocleWindowWidth; Vector3 windowHeigth = Vector3.up * SocleWindowHeight; Vector3 windowDepth = Vector3.Cross(width, height).normalized *SocleWindowDepth; var draft = PerforatedQuad(origin, width, height, windowOrigin, windowWidth, windowHeigth); var frame = MeshDraft.Hexahedron(windowWidth, -windowDepth, windowHeigth, Directions.All & ~Directions.ZAxis); frame.Move(windowOrigin + windowWidth / 2 + windowHeigth / 2 + windowDepth / 2); draft.Add(frame); draft.Paint(Khrushchyovka.socleColor); var window = MeshDraft.Quad(windowOrigin + windowDepth / 2, windowWidth, windowHeigth); window.Paint(Khrushchyovka.socleWindowColor); draft.Add(window); return(draft); }
public static MeshDraft BalconyGlazed(Vector3 origin, Vector3 width, Vector3 height) { Vector3 balconyWidth = width; Vector3 balconyHeight = height.normalized * BalconyHeight; Vector3 balconyDepth = Vector3.Cross(height, width).normalized *BalconyDepth; var draft = new MeshDraft(); var balcony = MeshDraft.Hexahedron(balconyWidth, balconyDepth, balconyHeight, Directions.All & ~Directions.Up & ~Directions.Back); balcony.FlipFaces(); balcony.Move(origin + width / 2 + balconyDepth / 2 + balconyHeight / 2); balcony.Paint(Khrushchyovka.wallColor); draft.Add(balcony); Vector3 roof0 = origin + height; Vector3 roof1 = roof0 + balconyWidth; Vector3 roof2 = roof1 + balconyDepth; Vector3 roof3 = roof0 + balconyDepth; var roof = MeshDraft.Quad(roof0, roof1, roof2, roof3); roof.Paint(Khrushchyovka.roofColor); draft.Add(roof); Vector3 glassHeight = height - balconyHeight; Vector3 glass0 = origin + balconyHeight; Vector3 glass1 = glass0 + balconyDepth; Vector3 glass2 = glass1 + balconyWidth; var glass = Windowpane(glass0, balconyDepth, glassHeight); glass.Add(Windowpane(glass1, balconyWidth, glassHeight)); glass.Add(Windowpane(glass2, -balconyDepth, glassHeight)); draft.Add(glass); return(draft); }
/// <inheritdoc /> public Mesh CreatePrimitive(PrimitiveDefinition definition) { MWVector3 dims = definition.Dimensions; MeshDraft meshDraft; float radius, height; switch (definition.Shape) { case PrimitiveShape.Sphere: dims = dims ?? new MWVector3(1, 1, 1); meshDraft = MeshDraft.Sphere( definition.Dimensions.SmallestComponentValue() / 2, definition.USegments.GetValueOrDefault(36), definition.VSegments.GetValueOrDefault(18), true); break; case PrimitiveShape.Box: dims = dims ?? new MWVector3(1, 1, 1); meshDraft = MeshDraft.Hexahedron(dims.X, dims.Z, dims.Y, true); break; case PrimitiveShape.Capsule: dims = dims ?? new MWVector3(0.2f, 1, 0.2f); radius = definition.Dimensions.SmallestComponentValue() / 2; height = definition.Dimensions.LargestComponentValue() - 2 * radius; meshDraft = MeshDraft.Capsule( height, radius, definition.USegments.GetValueOrDefault(36), definition.VSegments.GetValueOrDefault(18)); // default capsule is Y-aligned; rotate if necessary if (dims.LargestComponentIndex() == 0) { meshDraft.Rotate(Quaternion.Euler(0, 0, 90)); } else if (dims.LargestComponentIndex() == 2) { meshDraft.Rotate(Quaternion.Euler(90, 0, 0)); } break; case PrimitiveShape.Cylinder: dims = dims ?? new MWVector3(0.2f, 1, 0.2f); radius = 0.2f; height = 1; if (Mathf.Approximately(dims.X, dims.Y)) { height = dims.Z; radius = dims.X / 2; } else if (Mathf.Approximately(dims.X, dims.Z)) { height = dims.Y; radius = dims.X / 2; } else { height = dims.X; radius = dims.Y / 2; } meshDraft = MeshDraft.Cylinder( radius, definition.USegments.GetValueOrDefault(36), height, true); // default cylinder is Y-aligned; rotate if necessary if (dims.X == height) { meshDraft.Rotate(Quaternion.Euler(0, 0, 90)); } else if (dims.Z == height) { meshDraft.Rotate(Quaternion.Euler(90, 0, 0)); } break; case PrimitiveShape.Plane: dims = dims ?? new MWVector3(1, 0, 1); meshDraft = MeshDraft.Plane( dims.X, dims.Z, definition.USegments.GetValueOrDefault(1), definition.VSegments.GetValueOrDefault(1), true); meshDraft.Move(new Vector3(-dims.X / 2, 0, -dims.Z / 2)); break; default: throw new Exception($"{definition.Shape.ToString()} is not a known primitive type."); } return(meshDraft.ToMesh()); }
private void Start() { GetComponent <MeshFilter>().mesh = MeshDraft.Hexahedron(width, length, height).ToMesh(); }
public static MeshDraft Balcony(Vector3 origin, Vector3 width, Vector3 height) { Vector3 right = width.normalized; Vector3 normal = Vector3.Cross(height, width).normalized; Vector3 balconyWidth = width; Vector3 balconyHeight = Vector3.up * BalconyHeight; Vector3 balconyDepth = normal * BalconyDepth; var draft = new MeshDraft(); var balconyOuter = MeshDraft.Hexahedron(balconyWidth, balconyDepth, balconyHeight, Directions.All & ~Directions.Up & ~Directions.Back); balconyOuter.FlipFaces(); Vector3 balconyCenter = origin + width / 2 + balconyDepth / 2 + balconyHeight / 2; balconyOuter.Move(balconyCenter); balconyOuter.Paint(Khrushchyovka.wallColor); Vector3 innerWidthOffset = right * BalconyThickness; Vector3 innerWidth = balconyWidth - innerWidthOffset * 2; Vector3 innerHeightOffset = Vector3.up * BalconyThickness; Vector3 innerHeight = balconyHeight - innerHeightOffset; Vector3 innerDepthOffset = normal * BalconyThickness; Vector3 innerDepth = balconyDepth - innerDepthOffset; var balconyInner = MeshDraft.Hexahedron(innerWidth, innerDepth, innerHeight, Directions.All & ~Directions.Up & ~Directions.Back); balconyInner.Move(balconyCenter - innerDepthOffset / 2 + innerHeightOffset / 2); Vector3 borderOrigin = origin + balconyWidth + balconyHeight; Vector3 borderInnerOrigin = borderOrigin - innerWidthOffset; var balconyBorder = Bracket(borderOrigin, -balconyWidth, balconyDepth, borderInnerOrigin, -innerWidth, innerDepth); draft.Add(balconyOuter); draft.Add(balconyInner); draft.Add(balconyBorder); Vector3 windowWidthOffset = right * WindowWidthOffset; Vector3 windowHeightOffset = Vector3.up * WindowHeightOffset; Vector3 windowWidth = right * (width.magnitude - WindowWidthOffset * 2); Vector3 windowHeight = Vector3.up * WindowHeight; Vector3 windowDepth = normal * WindowDepth; int rodCount = Mathf.FloorToInt(windowWidth.magnitude / WindowSegmentMinWidth); Vector3 doorWidth = right * windowWidth.magnitude / (rodCount + 1); Vector3 doorHeight = windowHeightOffset + windowHeight; List <Vector3> outerFrame = new List <Vector3> { origin + windowWidthOffset + innerHeightOffset, origin + windowWidthOffset + doorHeight, origin + windowWidthOffset + windowWidth + doorHeight, origin + windowWidthOffset + windowWidth + windowHeightOffset, origin + windowWidthOffset + doorWidth + windowHeightOffset, origin + windowWidthOffset + doorWidth + innerHeightOffset }; var panel = MeshDraft.TriangleStrip(new List <Vector3> { outerFrame[0], origin, outerFrame[1], origin + height, outerFrame[2], origin + width + height, outerFrame[3], origin + width, outerFrame[4], origin + width, outerFrame[5] }); draft.Add(panel); List <Vector3> innerFrame = new List <Vector3>(); foreach (Vector3 vertex in outerFrame) { innerFrame.Add(vertex - windowDepth); } var frame = MeshDraft.FlatBand(innerFrame, outerFrame); draft.Add(frame); draft.Paint(Khrushchyovka.wallColor); draft.Add(Windowpane(outerFrame[0] - windowDepth, doorWidth, doorHeight - innerHeightOffset)); draft.Add(Windowpane(outerFrame[4] - windowDepth, windowWidth - doorWidth, windowHeight)); return(draft); }
/// <inheritdoc /> public GameObject CreatePrimitive(PrimitiveDefinition definition, GameObject parent, bool addCollider) { var spawnedPrimitive = new GameObject(definition.Shape.ToString()); spawnedPrimitive.transform.SetParent(parent.transform, false); MWVector3 dims = definition.Dimensions; MeshDraft meshDraft; switch (definition.Shape) { case PrimitiveShape.Sphere: meshDraft = MeshDraft.Sphere( definition.Radius.GetValueOrDefault(0.5f), definition.USegments.GetValueOrDefault(36), definition.VSegments.GetValueOrDefault(36), true); break; case PrimitiveShape.Box: dims = dims ?? new MWVector3(1, 1, 1); meshDraft = MeshDraft.Hexahedron(dims.X, dims.Z, dims.Y, true); break; case PrimitiveShape.Capsule: dims = dims ?? new MWVector3(0, 1, 0); meshDraft = MeshDraft.Capsule( dims.LargestComponentValue(), definition.Radius.GetValueOrDefault(0.5f), definition.USegments.GetValueOrDefault(36), definition.VSegments.GetValueOrDefault(36)); // default capsule is Y-aligned; rotate if necessary if (dims.LargestComponentIndex() == 0) { meshDraft.Rotate(Quaternion.Euler(0, 0, 90)); } else if (dims.LargestComponentIndex() == 2) { meshDraft.Rotate(Quaternion.Euler(90, 0, 0)); } break; case PrimitiveShape.Cylinder: dims = dims ?? new MWVector3(0, 1, 0); meshDraft = MeshDraft.Cylinder( definition.Radius.GetValueOrDefault(0.5f), definition.USegments.GetValueOrDefault(36), dims.LargestComponentValue(), true); // default cylinder is Y-aligned; rotate if necessary if (dims.LargestComponentIndex() == 0) { meshDraft.Rotate(Quaternion.Euler(0, 0, 90)); } else if (dims.LargestComponentIndex() == 2) { meshDraft.Rotate(Quaternion.Euler(90, 0, 0)); } break; case PrimitiveShape.Plane: dims = dims ?? new MWVector3(1, 0, 1); meshDraft = MeshDraft.Plane( dims.X, dims.Z, definition.USegments.GetValueOrDefault(1), definition.VSegments.GetValueOrDefault(1), true); meshDraft.Move(new Vector3(-dims.X / 2, 0, -dims.Z / 2)); break; case PrimitiveShape.InnerSphere: meshDraft = MeshDraft.Sphere( definition.Radius.GetValueOrDefault(0.5f), definition.USegments.GetValueOrDefault(36), definition.VSegments.GetValueOrDefault(36), true); meshDraft.FlipFaces(); break; default: throw new Exception($"{definition.Shape.ToString()} is not a known primitive type."); } spawnedPrimitive.AddComponent <MeshFilter>().mesh = meshDraft.ToMesh(); var renderer = spawnedPrimitive.AddComponent <MeshRenderer>(); renderer.sharedMaterial = MREAPI.AppsAPI.DefaultMaterial; if (addCollider) { spawnedPrimitive.AddColliderToPrimitive(definition); } return(spawnedPrimitive); }