3D Wireframe and Point Cloud.

I write two little script to draw 3D wireframe or a point cloud using GL library starting from an array of points. It is possible do the same with vectrosity (for use with Iphone or Ipad)? Somebody Help? Thanks…

Wireframe 3D script:

static var lineMaterial : Material;
var LineColor : Color;
var Opacity= 0.5;
var Linearray :  Array;
LineColor.a=Opacity;

Linearray = [0,0,0,1,1,1]; //This array can be more long...

static function CreateLineMaterial() {
if( !lineMaterial ) {
lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " + 
" ZTest Always Cull Off ZWrite Off " +
" BindChannels {" +
" Bind \"vertex\", vertex Bind \"color\", color }" +
"} } }" );
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
}

function OnPostRender() {
CreateLineMaterial();
// set the current material
lineMaterial.SetPass( 0 );
GL.PushMatrix();
GL.Begin( GL.LINES );
GL.Color(LineColor);

for (i = 0; i <Linearray.length/3 ; i++){
GL.Vertex(Vector3(-Linearray[i*3], Linearray[i*3+2], -Linearray[i*3+1]));
}
GL.End();
GL.PopMatrix();
}

Point Cloud script:

static var lineMaterial : Material;
var LineColor : Color;
var Linearray :  Array;
var DimCross = 0.01;
Linearray = [0,0,0,1,1,1]; //this array can be much long...

static function CreateLineMaterial() {
if( !lineMaterial ) {
lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " +
" ZTest Always Cull Off ZWrite Off " +
" BindChannels {" +
" Bind \"vertex\", vertex Bind \"color\", color }" +
"} } }" );
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
}

function OnPostRender() {
CreateLineMaterial();
// set the current material
lineMaterial.SetPass( 0 );
GL.PushMatrix();
GL.Begin( GL.LINES );
GL.Color(LineColor);

for (i = 0; i <Linearray.length/3 ; i++){
GL.Vertex(Vector3(-Linearray[i*3], Linearray[i*3+2]+DimCross, -Linearray[i*3+1]));
GL.Vertex(Vector3(-Linearray[i*3], Linearray[i*3+2]-DimCross, -Linearray[i*3+1]));
}
GL.End();
GL.PopMatrix();
}

Thanks everybody help me…

Yes, you can use Vectrosity for that.

–Eric

Just bought. I hope I can convert this script easily…

Work, but I have little problem… How I can import point from external file (such as Vector.txt) and use Vector.BytesToVector3Array command?

This is the script.

I try to import a vectorData.txt file but software doesn’t read…

BytesToVector3Array is for assets created with LineMaker, where the data is saved in binary format. If you have a file created with something else, then you’d have to parse the data yourself.

–Eric

Another problem: my array is 40.000-50.000 lines. Unity give me error when execute:

Can I solve? Is it a limit of software? How many line can i draw? 10.000,50.000,100.000?

I don’t know what’s in your .txt file, so I can’t really say without more info.

–Eric

It’s a .txt file with a list of coordinates. (Every line is a point). I use it for draw wireframe model. Example:

0,0.5,34,
4,5,6,
ecc…

In the script above you can find it with the name of linearray. With your plugin I can’t use diectly list of point but I edit adding prefix vector3. I try to do it automatically with unity command.
Important question: script works great but give me error (see above… stack is too big). How I can solve the problem?
If i remember in your post say that vectrosity can draw 500.000 lines? Is right?

You’d have to use String.Split, float.Parse, etc. Vectrosity can draw any number of line segments; how many you can actually use and still have it perform well depends on your hardware. There’s a limit of ~16K line segments per line, because of Unity’s 65K vertex per mesh limit.

–Eric