Skip to content

Commit

Permalink
VoxelBlender Beta ГОТОВО!
Browse files Browse the repository at this point in the history
Да готовооооо пока только бета но всё же!!
  • Loading branch information
DSDemen committed Feb 25, 2024
1 parent c6a19b9 commit ae926de
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 158 deletions.
87 changes: 57 additions & 30 deletions FScreator/3dmodel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private void InitializeForm()
BuildButton.Click += BuildButton_Click;

textBox5.Location = new System.Drawing.Point(10, heightTextBox.Bottom + 10);

textBox6.Location = new System.Drawing.Point(10, BuildButton.Bottom + 10);

// Add the TrackBar and textboxes to the panel
Expand Down Expand Up @@ -303,6 +304,9 @@ private void CreateButton_Click(object sender, EventArgs e)
// Add the new cube to the list of cubes
cubes.Add(newCube);

// Output debugging information
Console.WriteLine($"New Cube Created - Center: ({newCube.Center.X}, {newCube.Center.Y}, {newCube.Center.Z}), Width: {newCube.Width}, Height: {newCube.Height}, Length: {newCube.Length}");

// Set the new cube as the cubeToAdjust
cubeToAdjust = newCube;

Expand Down Expand Up @@ -349,7 +353,6 @@ private void slider1_ValueChanged(object sender, EventArgs e)
// Update the position of the cubeToAdjust based on the slider value
double newPosition = sliderValue / 10.0;
cubeToAdjust.Center = new Point3D(0, newPosition, 0);
Console.WriteLine(newPosition);

// Redraw the 3D scene
helixViewport.InvalidateVisual();
Expand Down Expand Up @@ -524,58 +527,82 @@ private void UpdateTextBoxesFromCurrentCube()

private string GenerateJson()
{
Name2 = textBox6.Text; // Да я задаю имя файлу через переменную а что такого?
string fileName = textBox6.Text;

// Create a list to store cube information
List<List<double>> aabbsList = new List<List<double>>();
List<List<object>> aabbsList = GetAabbsList();

// Create the JSON structure
var jsonData = new Dictionary<string, object>
{
{ "texture", "def" },
{ "model", "custom" },
{ "model-primitives", new Dictionary<string, object>
{
{ "aabbs", aabbsList }
}
},
{ "hitbox", new List<double> { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 } }
};

string filePath = SaveJsonToFile(fileName, jsonData);

return filePath;
}

private List<List<object>> GetAabbsList()
{
List<List<object>> aabbsList = new List<List<object>>();

// Iterate through each cube and add its information to the list
foreach (var cube in cubes)
{
// Exclude bancube from the JSON data
if (cube != bancube)
{
var aabb = new List<double>
{ // НЕ ПОПРОВЛЯТЬ СЛОМАЕШЬ!!!!!!!!!!!!!!
cube.Center.X, cube.Center.Y, cube.Center.Z,
cube.Width, cube.Height, cube.Length
}; // НЕ ПОПРОВЛЯТЬ СЛОМАЕШЬ!!!!!!!!!!!!!!

// Debug statement to check cube information
Console.WriteLine($"Cube Center: ({cube.Center.X}, {cube.Center.Y}, {cube.Center.Z}), Width: {cube.Width}, Height: {cube.Height}, Length: {cube.Length}");

var aabb = new List<object>
{
cube.Center.Y, //0 2
cube.Center.Z, //2 5
cube.Center.X, //5 0
cube.Width,
cube.Height,
cube.Length,
"def",
"def",
"def",
"def",
"def",
"def"
};

aabbsList.Add(aabb);
}
}

// Create the JSON structure
var jsonData = new
{
model = "custom",
modelPrimitives = new
{
aabbs = aabbsList
}
};

// Get the current directory
string currentDirectory = Environment.CurrentDirectory;
return aabbsList;
}

// Combine the current directory with the file name
string filePath = Path.Combine(currentDirectory, Name2+".json");
private string SaveJsonToFile(string fileName, object jsonData)
{
string currentDir = Directory.GetCurrentDirectory();
string filePath = Path.Combine(currentDir, "Jsons", fileName + ".json");

try
{
// Write the JSON data to the file with new lines, spaces, and commas
File.WriteAllText(filePath, "{\n \"texture\": \"def\",\n \"model\": \"custom\",\n \"model-primitives\": {\n \"aabbs\": [\n" + string.Join(",\n", aabbsList.Select(aabb => $" [ {string.Join(", ", aabb)} ]")) + "\n ]\n }\n}");
// Use Newtonsoft.Json for serialization
string jsonContent = JsonConvert.SerializeObject(jsonData, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(filePath, jsonContent);

// Provide feedback to the user
MessageBox.Show($"JSON file created successfully at {filePath}", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
catch (IOException ex)
{
// Handle exceptions (e.g., file IO errors)
MessageBox.Show($"Error creating JSON file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

// Return the file path (optional)
return filePath;
}
}
Expand Down
77 changes: 2 additions & 75 deletions FScreator/CREATE_BLOCK.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions FScreator/CREATE_BLOCK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ private void button1_Click(object sender, EventArgs e)
"\"breakable\":" + breakable + ",\n" +
"\"hidden\":" + hidden + ",\n" +
"\"model\":\""+comboBox1.Text + "\",\n" +
"\"inventory-size\":"+numericUpDown2.Value +"\",\n"+
"\"draw-group\":" + draw_Droup + "";
if (panel4.Visible == true)
{
Expand All @@ -206,10 +205,6 @@ private void button1_Click(object sender, EventArgs e)
{
file += ",\n\"script-name\":\"" + textBox18.Text + "\"";
}
if(UI_ELEMENT.Visible == true)
{
file += ",\n\"ui-layout\":\"" + textBox19.Text + "\"";
}
file += "\n}";
String hlp = Directory.GetCurrentDirectory();

Expand Down Expand Up @@ -266,17 +261,5 @@ private void checkBox11_CheckedChanged(object sender, EventArgs e)
SCRIPT.Visible = true;
}
}

private void checkBox12_CheckedChanged(object sender, EventArgs e)
{
if (UI_ELEMENT.Visible)
{
UI_ELEMENT.Visible = false;
}
else
{
UI_ELEMENT.Visible = true;
}
}
}
}
5 changes: 5 additions & 0 deletions FScreator/CREATE_OBL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -15,6 +16,7 @@ namespace FScreator
{
public partial class CREATE_OBL : Form
{
public string savedir;
public CREATE_OBL()
{
InitializeComponent();
Expand Down Expand Up @@ -51,6 +53,9 @@ private void button1_Click(object sender, EventArgs e)
dir = System.IO.Path.Combine(name, textBox1.Text);
Directory.CreateDirectory(dir);
String[] IN = dir.Split('\\');

savedir = Path.Combine(name, textBox1.Text);

//create blocks directory
dir = System.IO.Path.Combine (name+"\\"+textBox1.Text,"blocks");
Directory.CreateDirectory (dir);
Expand Down
48 changes: 12 additions & 36 deletions FScreator/FScreator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,44 +289,20 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="anonymous.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="dirt.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="disc.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="discord.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="email.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="FSlogo.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="FSlogom.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="grass_side.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="grass_top.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="lock.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="relog.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="anonymous.png" />
<Content Include="dirt.png" />
<Content Include="disc.png" />
<Content Include="discord.png" />
<Content Include="email.png" />
<Content Include="FSlogo.ico" />
<Content Include="FSlogom.ico" />
<Content Include="grass_side.png" />
<Content Include="grass_top.png" />
<Content Include="lock.png" />
<Content Include="relog.png" />
<Content Include="txts\Terms of Service.txt" />
<Content Include="txts\user.txt" />
<Content Include="ui.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ui.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets" Condition="Exists('..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets')" />
Expand Down

0 comments on commit ae926de

Please sign in to comment.