Hello people.
I'm working on a idea to get an easy workflow between 3dsmax<>XNA. first i have to create something that can import splines.
The idea is a follow: in 3dsmax i'll export all vertex points of a spline to a "splines.spl".
In XNA i would need a custom content reader/writer/processor thingy.
Well, i looked at a couple of tutorials, one of those is found here: http://msdn.microsoft.com/en-us/library/bb447754.aspx
So i created a new project called Splines and added the Curve3D class that was included with a scripedCamera sample.
first a class to hold the input from the file
SplineSource:
| namespace Splines |
| { |
| class SplineSource |
| { |
| public SplineSource(string sourceCode) |
| { |
| this.sourceCode = sourceCode; |
| } |
| |
| private string sourceCode; |
| public string SourceCode { get { return sourceCode; } } |
| } |
| } |
Then a importer :
SplineImporter
| namespace Splines |
| { |
| [ContentImporter(".spl", CacheImportedData=true, DisplayName = "Spline Importer", DefaultProcessor = "SplineProcessor")] |
| class SplineImporter : ContentImporter<SplineSource> |
| { |
| public override SplineSource Import(string filename, ContentImporterContext context) |
| { |
| string sourceCode = System.IO.File.ReadAllText(filename); |
| return new SplineSource(sourceCode); |
| } |
| } |
| } |
And a processor to process all the data. (this gives an error if i use the input data e.g uncomment the line)
| namespace Splines |
| { |
| [ContentProcessor(DisplayName = "Spline Processor")] |
| class SplineProcessor : ContentProcessor<SplineSource, SplineCurve> |
| { |
| public override SplineCurve Process(SplineSource input, ContentProcessorContext context) |
| { |
| string[] elements = input.SourceCode.Split(','); |
| Curve3D spCurve = new Curve3D(); |
| |
| // spCurve.AddPoint(new Vector3(Convert.ToSingle(elements[0]), Convert.ToSingle(elements[1]), Convert.ToSingle(elements[2])), 0); |
| spCurve.AddPoint(new Vector3(1,1,1), 0); |
| |
| return new SplineCurve(spCurve); |
| //throw new NotImplementedException(); |
| } |
| } |
| } |
and a splinecurve class:
| namespace Splines |
| { |
| public class SplineCurve |
| { |
| public SplineCurve(Curve3D splineCurve3D) |
| { this.splineCurve3D = new Curve3D();} |
| |
| private Curve3D splineCurve3D; |
| public Curve3D SplineCurve3D |
| { |
| get |
| {return (Curve3D) splineCurve3D; } |
| } |
| |
| } |
| } |
But for testing thingies i just a 1,1,1 to a curve3D point....
So next a writer to write stuff (as a xnb file i think) ?
| namespace Splines |
| { |
| [ContentTypeWriter] |
| public class SplineWriter : ContentTypeWriter<SplineCurve> |
| { |
| protected override void Write(ContentWriter output, SplineCurve value) |
| { |
| output.Write(value.SplineCurve3D.curveX.ToString()); |
| output.Write(value.SplineCurve3D.curveY.ToString()); |
| output.Write(value.SplineCurve3D.curveZ.ToString()); |
| } |
| |
| public override string GetRuntimeReader(TargetPlatform targetPlatform) |
| { |
| return "Splines.SplineReader, Splines, version=1.0.0.0, Culture=neutral"; |
| |
| //return typeof(SplineCurve).AssemblyQualifiedName; |
| } |
| } |
| } |
And Finally a reader to read it back out "sjees but well" :)
| namespace Splines |
| { |
| public class SplineReader : ContentTypeReader<SplineCurve> |
| { |
| protected override SplineCurve Read(ContentReader input, SplineCurve existingInstance) |
| { |
| Curve3D myCurve = new Curve3D(); |
| Vector3 point = new Vector3(input.ReadSingle(), |
| input.ReadSingle(), |
| input.ReadSingle()); |
| myCurve.AddPoint(point,1); |
| return new SplineCurve(myCurve); |
| } |
| } |
| } |
And as you can guess when i add the references to my project, add a .spl file (that contains "1,1,1") and try to load it... it does not work. i get weird numbers and not 1,1,1.....
You can also see that the reading/writing and such is far from complete. cause it should read all the lines, write all the lines, etc.
But that i'll do when the basic thing works.
So perhpas you guys can have a look at this and help me out.
The maxscript is very easy for me and when i got it all working i'll upload it somewhere so maybe more people can use it.... :)
Cheers!
Martijn