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();
}
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.
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.