PDA

View Full Version : vcount 4



Friba77
05-24-2012, 12:59 AM
Hi!

i am writing a parser for collada-files. I can already work with meshes. But only if the vcount-element contains the number 3. e. g.: <vcount>3 3 3 3 3 </vcount>

Unfortunately i have problem with the number 4. e. g. <vcount>4 4 4 4 4 </vcount>

In this case the image is not rendered completely. Some areas are missing.

e. g. my test-model in Blender:
http://i48.tinypic.com/34hx3qp.jpg

But in my browser:
http://i48.tinypic.com/25p7bq0.jpg

A part of my javascript code:


/**
* @param COLLADA_Mesh mesh
* @return array
* e. g.
* ['#Plane-mesh-positions']: [1, -1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0]
* ['#Plane-mesh-normals']: [0, 0, 1]
*/
function getSourceValues(mesh) {
var sourceValues = [];

var meshSources = mesh.getSources(); // 1 ... n COOLADA_Source-objects
var length = meshSources.length;
for (var i = 0; i < length; ++i) {
var meshSource = meshSources[i];
var meshSourceArrayElement = meshSource.getArrayElement();
// 0 ... 1 xxx_array, e. g. float_array => COLLADA_FloatArray-object
if (
meshSourceArrayElement != undefined &&
meshSourceArrayElement instanceof COLLADA_FloatArray
) {
var id = '#' + meshSource.getId();
sourceValues[id] = meshSourceArrayElement.getValues();
}
}
return sourceValues;
}
function getNormals(sourceValues, indices) {
var vertexIndices = indices['VERTEX'].values; // xml-file vertices indices
var normalIndices = indices['NORMAL'].values; // xml-file normal indices

var normalValues = sourceValues[indices['NORMAL'].source]; // xml-file normal values

var normals = []; // javascript webgl normal values

var length = vertexIndices.length;
for (var i = 0; i < length; ++i) {
var vertexIndex = vertexIndices[i];
var normalIndex = normalIndices[i];

var count = 3;
for (var j = 0; j < count; ++j) // x, y, z
normals[vertexIndex * count + j] = normalValues[normalIndex * count + j];
}
I think that i have to define some more vertices. Is this correct?

Friba77
05-24-2012, 06:46 AM
I think, i have found the problem. WebGL can only work with vcount = 3.

So if i have a vcount = 4, i have to split it into 2 vcount = 3.

E. g.:

<input ... offset="0" />
<input ... offset="1" />
<vcount>4 3</vcount>


0 1 2 3 4 5 6 7 8 9 10 11 12 13</p>

xml-polygon 0:
4 pairs: 0/1, 2/3, 4/5, 6/7
=> must be split into 2 webgl-polygons, e.g.:
first webgl-polygon: 0/1, 2/3, 4/5
second webgl-polygon: 0/1, 4/5, 6/7

xml-polygon 1:
3 pairs: 8/9 10/11 12/13
=> 1 webgl-polygon: the same polygon as the xml-polygon: 8/9, 10/11, 12/13

Is this correct?

Friba77
05-24-2012, 09:54 AM
Everyting OK. Itīs working :)