Commit 7f866d01 authored by VihangiSalgado's avatar VihangiSalgado

Structure tools

parent cfe4dca8
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -8,9 +9,17 @@ namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
static void Main(string[] arg)
{
// loard strings
string[] Strings = File.ReadAllLines("dum.usa.txt");
// Get data
Structure.UsaFile usa = StructureTools.StringArrayToUsaFile(Strings);
// write data to file
byte[] tstFile = StructureTools.UsaFileToBytes(usa);
File.WriteAllBytes("test.usa", tstFile);
}
}
}
......@@ -15,7 +15,7 @@ namespace ConsoleApp1
#region usaFile
//USA main format structure
public struct usaFile
public struct UsaFile
{
public char[] header; // usa header
public UInt64 fileSize; // file size
......@@ -23,64 +23,66 @@ namespace ConsoleApp1
public string userName; // user nam of the person
public string step; // step of the model
public string comments; // cooments about file
public geometry[] geometries; // geometry of the 3D model
public apearance[] apearances; // aparance of the 3D model
public scene Scene; // scene of the 3D model
public animation[] animations; // animation of the 3D model
public UInt32 numberOfGeo; // number of geomtries
public UInt64[] geoOffSets; // place in binary file to reach geo data
public Geometry[] geometries; // geometry of the 3D model
public UInt32 numOfAp; // number of app
public UInt64[] apOffSet; //place in binary file to reach app data
public Apearance[] apearances; // aparance of the 3D model
public UInt64 numOfCam; // number of cam
public UInt64[] camOffset; // place in binary file to reach cam data
public Camera[] cam; // camera data
public UInt64 numOfLight; // number of lights
public UInt64[] lightOffSet; // place in binary file to reach light data
public Light[] light; // light data
public UInt64 numOfAnime; // number of animes
public UInt64[] animeOffSet; // place in binary file to reach anime data
public Animation[] animations; // animation of the 3D model
}
// Encording geometry of the 3D model
public struct geometry
public struct Geometry
{
public UInt16 serfaceID; // ID of the each triangle serface
public UIntPtr point1; // first vertx of the triangle
public UIntPtr point2; // second vertex of the triangle
public UIntPtr point3; // third vertex of the triangle
public UIntPtr nPoint1; // first vertex of the outword normal vector
public UIntPtr nPoint2; // second vertex of the outword normal vector
public UInt64 serfaceID; // ID of the each triangle serface
public UInt32 point1; // first vertx of the triangle
public UInt32 point2; // second vertex of the triangle
public UInt32 point3; // third vertex of the triangle
public UInt32 nPoint1; // first vertex of the outword normal vector
public UInt32 nPoint2; // second vertex of the outword normal vector
}
// storing apearance of the 3D model
public struct apearance
public struct Apearance
{
public UInt16 serfaceID2; //ID of the each serface
public UInt32 aColor; // colour of the ech serface
public UInt64 serfaceID2; //ID of the each serface
public UInt64 aColor; // colour of the ech serface
public UInt64 texture; // texture of the serface
public UInt32 matirial; // material of ther serface
public UInt64 matirial; // material of ther serface
}
//saving scene informtion
public struct scene
// Scene information
public struct Camera
{
public camera cam;
public light lightSource;
public UInt32 magPoint; // magnification point of the camera
public UInt32 location; // Location of the camra
public UInt32 direction; // direction of thee camera
public UInt32 up; //which dirction is the up
}
// camra information
public struct camera
public struct Light
{
public UIntPtr magPoint; // magnification point of the camera
public UIntPtr location; // Location of the camra
public UIntPtr direction; // direction of thee camera
public bool up; //which dirction is the up
}
//light source information
public struct light
{
public UIntPtr lLoction; // direction of the light source
public UInt32 lLoction; // direction of the light source
public UInt32 lColour; // colour of the source light
public UInt32 intensity; // intencity of the light source
}
//Encording Animation
public struct animation
public struct Animation
{
public float rotation; // rotation of the virtual bone
public float scale; // scale of the bone
public UIntPtr shear; // shear of the bone
public UIntPtr translation; // translation of th bone
}
public UInt32 rotation; // rotation of the virtual bone
public UInt32 scale; // scale of the bone
public UInt32 shear; // shear of the bone
public UInt32 translation; // translation of th bone
}
#endregion
......
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -8,5 +9,232 @@ namespace ConsoleApp1
{
public static class StructureTools
{
#region usafFile
// Take string from text file and convert it to USA structure
public static Structure.UsaFile StringArrayToUsaFile(string[] Strings)
{
// Make new USA file
Structure.UsaFile usa = new Structure.UsaFile();
usa.userName = Strings[0]; // set user name
usa.step = Strings[1]; // set step
usa.comments = Strings[2]; // set comments
usa.numberOfGeo = UInt32.Parse(Strings[3]);
Structure.Geometry[] geometries = new Structure.Geometry[usa.numberOfGeo];
for (int i = 4; i < usa.numberOfGeo; i++)
{
string[] values = Strings[4].Split(',');
geometries[4].serfaceID = UInt64.Parse(values[0]);
geometries[4].point1 = UInt32.Parse(values[1]);
geometries[4].point2 = UInt32.Parse(values[2]);
geometries[4].point3 = UInt32.Parse(values[3]);
geometries[4].nPoint1 = UInt32.Parse(values[4]);
geometries[4].nPoint2 = UInt32.Parse(values[5]);
}
usa.geometries = geometries;
usa.numOfAp = UInt32.Parse(Strings[5]);
Structure.Apearance[] apearances = new Structure.Apearance[usa.numOfAp];
for (int i = 4; i < usa.numOfAp; i++)
{
string[] values1 = Strings[5].Split(',');
apearances[6].serfaceID2 = UInt64.Parse(values1[0]);
apearances[6].aColor = UInt32.Parse(values1[1]);
apearances[6].texture = UInt32.Parse(values1[2]);
apearances[6].matirial = UInt32.Parse(values1[3]);
}
usa.apearances = apearances;
usa.numOfCam = UInt64.Parse(Strings[7]);
Structure.Camera[] cameras = new Structure.Camera[usa.numOfCam];
string[] values2 = Strings[4].Split(',');
cameras[8].magPoint = UInt32.Parse(values2[0]);
cameras[8].location = UInt32.Parse(values2[1]);
cameras[8].direction = UInt32.Parse(values2[2]);
cameras[8].up = UInt32.Parse(values2[3]);
usa.cam = cameras;
usa.numOfLight = UInt64.Parse(Strings[9]);
Structure.Light[] lights = new Structure.Light[usa.numOfLight];
string[] values3 = Strings[4].Split(',');
lights[10].lLoction = UInt32.Parse(values3[0]);
lights[10].lColour = UInt32.Parse(values3[1]);
lights[10].intensity = UInt32.Parse(values3[2]);
usa.cam = cameras;
usa.numOfAnime = UInt64.Parse(Strings[11]);
Structure.Animation[] animations = new Structure.Animation[usa.numOfAnime];
string[] values4 = Strings[4].Split(',');
animations[12].rotation = UInt32.Parse(values4[0]);
animations[12].scale = UInt32.Parse(values4[1]);
animations[12].shear = UInt32.Parse(values4[2]);
animations[12].translation = UInt32.Parse(values4[3]);
usa.animations = animations;
usa.version = 1; // set file specific data
// set header
char[] header = { 'U', 'S', 'A' };
usa.header = header;
// UInt64 offset = (UInt64)(usa.header.Length + 8 + 8 + usa.userName.Length + 1 + usa.step.Length + 1 + usa.comments.Length + 1);
//calculate the starting offset
UInt64 offset = (UInt64) (usa.header.Length + 8 + 8 + usa.userName.Length + 1 + usa.step.Length + 1 + usa.comments.Length + 1 + 8 + usa.geoOffSets.Length * 8 + 8
+ usa.apOffSet.Length * 8 + 8 + usa.camOffset.Length * 8 + 8 + usa.lightOffSet.Length * 8 + 8 + usa.animeOffSet.Length * 8);
// graully st and increse bytes
UInt64[] offsets1 = new UInt64[usa.numberOfGeo];
for (int i = 0; i < offsets1.Length; i++)
{
// set initial value
offsets1[i] = offset;
// increment
offset += (UInt64)(8 + 4 + 4 + 4 + 4 + 4);
}
UInt64[] offsets2 = new UInt64[usa.numOfAp];
for (int i = 0; i < offsets2.Length; i++)
{
// set initial value
offsets2[i] = offset;
// increment
offset += (UInt64)(8 + 8 + 8 + 8);
}
UInt64[] offsets3 = new UInt64[usa.numOfCam];
for (int i = 0; i < offsets3.Length; i++)
{
// set initial value
offsets3[i] = offset;
// increment
offset += (UInt64)(4 + 4 + 4 + 4);
}
UInt64[] offsets4 = new UInt64[usa.numOfLight];
for (int i = 0; i < offsets4.Length; i++)
{
// set initial value
offsets4[i] = offset;
// increment
offset += (UInt64)(4 + 4 + 4);
}
UInt64[] offsets = new UInt64[usa.numOfAnime];
for (int i = 0; i < offsets.Length; i++)
{
// set initial value
offsets[i] = offset;
// increment
offset += (UInt64)(4 + 4 + 4 + 4);
}
//set file size
usa.fileSize = offset;
// return the final data
return usa;
}
// save the usa fil to a bin to be rad later
public static byte[] UsaFileToBytes(Structure.UsaFile usa)
{
// make memory stream
MemoryStream o = new MemoryStream();
// make binary write to write stream
BinaryWriter bw = new BinaryWriter(o);
bw.Write(usa.header);
bw.Write(usa.fileSize);
bw.Write(usa.version);
bw.Write(usa.userName);
bw.Write(usa.step);
bw.Write(usa.comments);
bw.Write(usa.numberOfGeo);
foreach (UInt64 offset in usa.geoOffSets)
{
bw.Write(offset);
}
foreach (Structure.Geometry Geometry in usa.geometries)
{
bw.Write(Geometry.serfaceID);
bw.Write(Geometry.point1);
bw.Write(Geometry.point2);
bw.Write(Geometry.point3);
bw.Write(Geometry.nPoint1);
bw.Write(Geometry.nPoint2);
}
bw.Write(usa.numOfAp);
foreach (UInt64 offset in usa.apOffSet)
{
bw.Write(offset);
}
foreach (Structure.Apearance Apearance in usa.apearances)
{
bw.Write(Apearance.serfaceID2);
bw.Write(Apearance.aColor);
bw.Write(Apearance.texture);
bw.Write(Apearance.matirial);
}
bw.Write(usa.numOfCam);
foreach (UInt64 offset in usa.camOffset)
{
bw.Write(offset);
}
foreach (Structure.Camera Camera in usa.cam)
{
bw.Write(Camera.magPoint);
bw.Write(Camera.location);
bw.Write(Camera.direction);
bw.Write(Camera.up);
}
bw.Write(usa.numOfLight);
foreach (UInt64 offset in usa.lightOffSet)
{
bw.Write(offset);
}
foreach (Structure.Light Light in usa.light)
{
bw.Write(Light.lLoction);
bw.Write(Light.lColour);
bw.Write(Light.intensity);
}
bw.Write(usa.numOfAnime);
foreach (UInt64 offset in usa.animeOffSet)
{
bw.Write(offset);
}
foreach (Structure.Animation Animation in usa.animations)
{
bw.Write(Animation.rotation);
bw.Write(Animation.scale);
bw.Write(Animation.shear);
bw.Write(Animation.translation);
}
// return final bytes
return o.ToArray();
}
#endregion
}
}
vihangis
anm
animation of the hand
01
001,2,4,6,8,10
01
001,13127648,13127648,13127648
01
1,2,3,4
01
5,13127648,13127648
01
90,50,5,2
\ No newline at end of file
user name
step
comments
Encording geometry of the 3D model
{
// Approximate mesh
Serfce ID
Vertices of the Trangle
Outword normal vector
}
Storing apearance of the 3D model
{
// Face attributes
Serface ID
colour
texture
matirial type
}
Saving scene information
{
camera
{
magnification and principle point
location
direction of the camera is facing
which direction is up
}
Light source
{
location of th light source
colour
intensity
}
}
Encording Animation
{
//Skeletal Animation
// represent virtual bones by 4x3 matrix
1st colomn - rotation
2nd colomn - scale
3rd colomn - shear
4th colomn - trnslation.
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment