Joined: Mar 23, 2020
Post Count: 144
Status:
Offline
Re: Staircase generator plug-in
@el_dario Version 4.2 or later will be posted on sourceforge as soon as it's ready
---------------------------------------- Windows 64bit | Intel i7 | SH3D 8.0 + Plugins
Netherlands
Joined: Apr 8, 2022
Post Count: 1824
Status:
Offline
Re: Staircase generator plug-in
Why so difficult? You can easily calculate an SVG cutout string using the v lines in a room object (or any other object where an outline can be calculated from). It is much easier to draw a room then the screenshot copies. Here's the code for it in PHP and C#. Both code listings are made to to be readable by non-programmers too. This was a test for me so a little optimization is probably possible. The C# code is close to Java code so should be easy to convert. The PHP code is amateur work, I only use it for my websites.
C# code:
using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Text;
namespace SH3D { public class SVG { // constructor public SVG () {}
/// <summary> /// Create an SVG cutout string from the given obj file /// </summary> /// <returns> /// The SVG cutout string /// </returns> /// <param name='sourcefile'> /// The obj file to use for creating the SVG string. /// A cutout string is generated using the v lines in the first group, best result with a room object. /// </param> public string CreateSVGcutout (string sourcefile) { if (!File.Exists (sourcefile)) { return string.Empty; }
#region create vertice list // Create an empty list to hold all vertices (v lines) List<Vertice> vertices = new List<Vertice> ();
// Read all lines in the obj file into a string array String[] lines = File.ReadAllLines (sourcefile); bool start = false;
// For each line that starts with "v " create a Vertice object and add it to the vertices list. // z is set to 0 by default, not used for a SVG cutout. foreach (string line in lines) { if (line.StartsWith ("v ")) { start = true; string[] parts = line.Split (new char[] {' '}); // 0 = "v", 1=X, 2=Z, 3=Y Vertice v = new Vertice (double.Parse(parts [1]), double.Parse(parts [3]), 0.0d); vertices.Add (v); } else { // First set of v lines done, ignore the rest if (start) { break; } } } #endregion create vertice list
#region object bounderies // Get the object bounderies, I.E. the width and depth of the object // These are needed to calculate the L points // Calculating this enables processing objects that dont't have 0,0 as the position coordinates. double minwidth = 0.0; double maxwidth = 0.0; double mindepth = 0.0; double maxdepth = 0.0; bool first = true; foreach (Vertice v in vertices) { if (first) { minwidth = v.X; maxwidth = v.X; mindepth = v.Y; maxdepth = v.Y; first = false; } else { minwidth = Math.Min (minwidth, v.X); maxwidth = Math.Max (maxwidth, v.X); mindepth = Math.Min (mindepth, v.Y); maxdepth = Math.Max (maxdepth, v.Y); } }
// Recalculate the vertice points so they start from the correct origin for (int i=0; i< vertices.Count; i++) { vertices.X = vertices.X-minwidth; vertices.Y = vertices.Y-mindepth; } #endregion object bounderies
#region create SVG string string svg = ""; first = true; foreach (Vertice v in vertices) { if (first) { // first starts with "M" svg += "M" + Math.Round(v.X/width,4).ToString() + "," + Math.Round(v.Y/depth,4).ToString() + " "; first = false; } else { // add L points svg += "L" + Math.Round(v.X/width,4).ToString() + "," + Math.Round(v.Y/depth,4).ToString() + " "; } } svg += "z"; // z = back to start (M) #endregion create SVG string
// return the SVG string return svg; } } }
PHP code:
<?php include_once "base.php"; if (session_id() == "") { session_start(); }
class SVGCutout { // private $_exportpath = TMPPATH; public $lines;
// get the object bounderies, I.E. the width and depth of the object // these are needed to calculate the L points $minw = 0.0; $maxw = 0.0; $mind = 0.0; $maxd = 0.0; $first = true;
Joined: Mar 23, 2020
Post Count: 144
Status:
Offline
Re: Staircase generator plug-in
An excellent solution. Thank You However in many cases I need to get creative and design a cutout which does not correspond to model edges. e.g. circular for a T shaped
---------------------------------------- Windows 64bit | Intel i7 | SH3D 8.0 + Plugins
Netherlands
Joined: Apr 8, 2022
Post Count: 1824
Status:
Offline
Re: Staircase generator plug-in
That's why this code solution is easier. You can draw a room in any form you need, for example a star or T and it will calculate the cutout. To be clear: this is independent from the staircase object, completely separate. It is as if you draw the outline as in your examples but now without screenshots and as a room object.
---------------------------------------- Dodecagon.nl 1300+ 3D models, manuals, and projects
Joined: Feb 20, 2024
Post Count: 2
Status:
Offline
Re: Staircase generator plug-in
Hi, thanks for this nice plugin! Could you maybe add a function to make the "first stairs count" asymmetric, i.e. different counts for the bottom treads and the top treads?
So basically add also a "last stairs count" or something? Or maybe better names are "lower tread count" and "upper tread count"?
I have a staircase where this is like that.
Also, the latest version 4.2 is not detected by the Plugin Manager plugin yet!
Romania
Joined: Apr 24, 2014
Post Count: 832
Status:
Offline
Re: Staircase generator plug-in
Maybe this could help you.
---------------------------------------- A computer program does what you tell it to do, not what you want it to do. Murphy's Law When all else fails, read the instructions. Murphy's Law If you don't like "AS IS", DIY. Dorin's law