You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I read the .obj file and convert to Mesh
to generate ctm File
it was created but failed to load in three.js
it show following message
Uncaught Error in data stream
*** sample .obj file is uploaded
`using OpenCTM;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
private static float[] vert = new float[]{ 0,0,0,
1,0,0,
1,1,0,
0,1,0};//v
private static float[] normals = new float[]{1,1,1,
1,1,1,
1,1,1,
1,1,1};//vn
private static AttributeData[] uvad = { new AttributeData ("uv1", "test",
AttributeData.STANDARD_UV_PRECISION,
new float[]{0.0034f, 0.1f,
0.8f, 1.0f,
0.351f, 0.612f,
0.1229f, 0.91224f}) };//vt
private static int[] ind = new int[] { 0, 1, 2, 0, 2, 3 };//f
private static Mesh quad = new Mesh(vert, normals, ind, uvad, new AttributeData[0]);
public void rawTest()
{
testEncoder(new RawEncoder());
}
public void mg1Test()
{
testEncoder(new MG1Encoder());
}
public void mg2Test()
{
testEncoder(new MG2Encoder(MG2Encoder.STANDARD_VERTEX_PRECISION, MG2Encoder.STANDARD_NORMAL_PRECISION));
}
private void testEncoder(MeshEncoder encoder)
{
MemoryStream memory = new MemoryStream();
CtmFileWriter writer = new CtmFileWriter(memory, encoder);
writer.encode(quad, null);
memory.Seek(0, SeekOrigin.Begin);
using (FileStream file = new FileStream("mayu.ctm", FileMode.Create, System.IO.FileAccess.Write))
memory.CopyTo(file);
Stream readMemory = new MemoryStream(memory.ToArray());
CtmFileReader reader = new CtmFileReader(readMemory);
Mesh m = reader.decode();
m.checkIntegrity();
//MG2Encoder mg2 = encoder as MG2Encoder;
//Chech file integirty
//MemoryStream ms = new MemoryStream();
//using (FileStream file = new FileStream("col.ctm", FileMode.Open, FileAccess.Read))
// file.CopyTo(ms);
//Stream readMemory1 = new MemoryStream(ms.ToArray());
//CtmFileReader reader1 = new CtmFileReader(readMemory1);
//Mesh m2 = reader1.decode();
//m2.checkIntegrity();
//float[] v = m2.vertices;
//float[] n = m2.normals;
//AttributeData []ad = m2.texcoordinates;
//int[] index = m2.indices;
//var t= m2.getVertexCount();
//var c = m2.getTriangleCount();
}
static void Main(string[] args)
{
Program p = new ConsoleApplication1.Program();
var filrread = File.ReadAllLines(@"D:\\collar.obj");
//var filrread = File.ReadAllLines(@"D:\\Box.obj");
// var filrread = File.ReadAllLines(@"D:\\boxxxx.obj");
var ctmName = filrread.Where(x => x.Contains("object")).Select(x => x.Split(' ')[2]).FirstOrDefault();
var vcount = Convert.ToInt32(filrread.Where(x => x.Contains("vertices")).Select(x => x.Split(' ')[1]).FirstOrDefault())*3;
var vncount = Convert.ToInt32(filrread.Where(x => x.Contains("normals")).Select(x => x.Split(' ')[1]).FirstOrDefault())*3;
var vtcount = Convert.ToInt32(filrread.Where(x => x.Contains("texture")).Select(x => x.Split(' ')[1]).FirstOrDefault())*3;
var fcount = Convert.ToInt32(filrread.Where(x => x.Contains("triangles")).Select(x => x.Split(' ')[4]).FirstOrDefault());
var v = filrread.Where(x => x.StartsWith("v ")).Select(x => x.Replace("v ", string.Empty).Split(' ').ToList()).ToList();
var vn = filrread.Where(x => x.StartsWith("vn ")).Select(x => x.Replace("vn ", string.Empty).Split(' ').ToList()).ToList();
var vt = filrread.Where(x => x.StartsWith("vt ")).Select(x => x.Replace("vt ", string.Empty).Split(' ').ToList()).ToList();
var f = filrread.Where(x => x.StartsWith("f ")).Select(x => x.Replace("f ", string.Empty).TrimEnd().Split(' ').ToList().Select(ac => ac.Split('/')[0])).ToList();
List<float> vertex = new List<float>();
List<float> normal = new List<float>();
List<float> uv = new List<float>();
List<int> index = new List<int>();
int cnt = 0;
foreach (var item in v)
{
foreach (var itemList in item)
{
vertex.Add(Convert.ToSingle(itemList));
//normal.Add(cnt);
//uv.Add(cnt);
//cnt++;
}
}
foreach (var item in vn)
{
foreach (var itemList in item)
{
normal.Add(Convert.ToSingle(itemList));
}
}
foreach (var item in vt)
{
//foreach (var itemList in item)
for (int i = 0; i < item.Count - 1; i++)
{
//uv.Add(Convert.ToSingle(itemList[i]));
uv.Add(Convert.ToSingle(item[i]));
}
}
foreach (var item in f)
{
foreach (var itemList in item)
{
index.Add(Convert.ToInt32(itemList)-1); // remove -1 For Face adjustment
}
}
//if (vertex.Count == vcount && normal.Count == vncount && uv.Count == (vtcount-vt.Count) && f.Count == fcount)
{
vert = vertex.ToArray();
normals = normal.ToArray();
AttributeData ad = new AttributeData(ctmName, "1", AttributeData.STANDARD_UV_PRECISION, uv.ToArray());
List<AttributeData> adlist = new List<AttributeData>();
adlist.Add(ad);
ind = index.ToArray();
quad = new Mesh(vert, normals, ind, adlist.ToArray(), new AttributeData[0]);
}
p.mg2Test();
}
}
When I read the .obj file and convert to Mesh
to generate ctm File
it was created but failed to load in three.js
it show following message
Uncaught Error in data stream
*** sample .obj file is uploaded
`using OpenCTM;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
}
collar.obj.txt
`
The text was updated successfully, but these errors were encountered: