-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setAttribute works on FloatVertexAttribute #610
base: master
Are you sure you want to change the base?
Changes from 9 commits
16fefd1
51ec347
b0663b0
3f5e20d
52cf65c
f01242e
296a1d9
eebe316
4be1859
41267fc
dae7a22
8ad2353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,7 +633,7 @@ x3dom.registerNodeType( | |
{ | ||
if (fieldName != "coord" && fieldName != "normal" && | ||
fieldName != "texCoord" && fieldName != "color" && | ||
fieldName != "coordIndex") | ||
fieldName != "coordIndex" && !fieldName.startsWith("attrib_")) | ||
{ | ||
x3dom.debug.logWarning("IndexedFaceSet: fieldChanged for " + | ||
fieldName + " not yet implemented!"); | ||
|
@@ -791,8 +791,21 @@ x3dom.registerNodeType( | |
hasColor = false; | ||
} | ||
this._mesh._numColComponents = numColComponents; | ||
if (fieldName.startsWith("attrib")) { | ||
var attrName = fieldName.slice(7); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. But the name of the attribute is not provided after an underscore ("attrib_temperature") but only in the name field of the attrib child node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name is given during the call of FiledChanged on the FloatVertexAttribute element fieldChanged: function (fieldName) {
var that = this;
if (fieldName == "value" || fieldName == "numComponents") {
Array.forEach(this._parentNodes, function (node) {
node.fieldChanged("attrib_"+that._vf.name);
});
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. While that probably works. I do not think the node.fieldChanged() function is intended to be reused for internal purposes like this. Why not make a new function updateAttrib(name) or in IndexedFaceSet.js (and all possible parentNodes of FloatVertexAttribute) ? Or do the update right here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of the new function updateAttrib(name) is not bad, it can be similar to the handleAttibs in X3domComposedGeometryNode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the name in node.updateAttrib(name) would have the name of the changed attribute, no ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you call node.updateAttrib in the IFS, the only information given is FieldChanged("attribs"). |
||
var attrNode = this._cf.attrib.nodes.find( | ||
function (a) {return a._vf.name == attrName;} | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To find out which attribute changed, it is probably necessary to implement fieldChanged() in FloatVertexAttribute.js . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no way to know which attribute changed in the FieldChanged of IndexedFaceSet, and this is made to avoid to update/compute all the other attributes. |
||
if (attrNode) { | ||
var attr_data = attrNode._vf.value; | ||
var attr_numComp = attrNode._vf.numComponents; | ||
var hasAttributes = this._mesh._dynamicFields[attrName] !== undefined; | ||
this._mesh._dynamicFields[attrName].numComponents = attr_numComp; | ||
this._mesh._dynamicFields[attrName].value = []; | ||
} | ||
} | ||
|
||
var i, j, t, cnt, faceCnt; | ||
var i, j, k, t, cnt, faceCnt; | ||
var p0, p1, p2, n0, n1, n2, t0, t1, t2, c0, c1, c2; | ||
|
||
if(this._vf.convex) { | ||
|
@@ -865,8 +878,6 @@ x3dom.registerNodeType( | |
else if (hasColorInd && !colPerVert) { c2 = +colorInd[faceCnt]; } | ||
else if (colPerVert) { c2 = p2; } | ||
else { c2 = faceCnt; } | ||
t = 3; | ||
|
||
//this._mesh._indices[0].push(cnt++, cnt++, cnt++); | ||
|
||
this._mesh._positions[0].push(positions[p0].x); | ||
|
@@ -932,111 +943,18 @@ x3dom.registerNodeType( | |
this._mesh._texCoords[0].push(texCoords[t2].z); | ||
} | ||
} | ||
|
||
//faceCnt++; | ||
break; | ||
case 3: | ||
p1 = p2; | ||
t1 = t2; | ||
if (normPerVert) { | ||
n1 = n2; | ||
} | ||
if (colPerVert) { | ||
c1 = c2; | ||
} | ||
p2 = +indexes[i]; | ||
|
||
if (hasNormalInd && normPerVert) { | ||
n2 = +normalInd[i]; | ||
} else if (hasNormalInd && !normPerVert) { | ||
/*n2 = +normalInd[faceCnt];*/ | ||
} else if (normPerVert) { | ||
n2 = p2; | ||
} else { | ||
n2 = faceCnt; | ||
} | ||
|
||
if (hasTexCoordInd) { | ||
t2 = +texCoordInd[i]; | ||
} else { | ||
t2 = p2; | ||
} | ||
|
||
if (hasColorInd && colPerVert) { | ||
c2 = +colorInd[i]; | ||
} else if (hasColorInd && !colPerVert) { | ||
/*c2 = +colorInd[faceCnt];*/ | ||
} else if (colPerVert) { | ||
c2 = p2; | ||
} else { | ||
c2 = faceCnt; | ||
} | ||
|
||
//this._mesh._indices[0].push(cnt++, cnt++, cnt++); | ||
|
||
this._mesh._positions[0].push(positions[p0].x); | ||
this._mesh._positions[0].push(positions[p0].y); | ||
this._mesh._positions[0].push(positions[p0].z); | ||
this._mesh._positions[0].push(positions[p1].x); | ||
this._mesh._positions[0].push(positions[p1].y); | ||
this._mesh._positions[0].push(positions[p1].z); | ||
this._mesh._positions[0].push(positions[p2].x); | ||
this._mesh._positions[0].push(positions[p2].y); | ||
this._mesh._positions[0].push(positions[p2].z); | ||
|
||
if (hasNormal) { | ||
this._mesh._normals[0].push(normals[n0].x); | ||
this._mesh._normals[0].push(normals[n0].y); | ||
this._mesh._normals[0].push(normals[n0].z); | ||
this._mesh._normals[0].push(normals[n1].x); | ||
this._mesh._normals[0].push(normals[n1].y); | ||
this._mesh._normals[0].push(normals[n1].z); | ||
this._mesh._normals[0].push(normals[n2].x); | ||
this._mesh._normals[0].push(normals[n2].y); | ||
this._mesh._normals[0].push(normals[n2].z); | ||
} | ||
//else { | ||
this._mesh._multiIndIndices.push(p0, p1, p2); | ||
//} | ||
|
||
if (hasColor) { | ||
this._mesh._colors[0].push(colors[c0].r); | ||
this._mesh._colors[0].push(colors[c0].g); | ||
this._mesh._colors[0].push(colors[c0].b); | ||
if (numColComponents === 4) { | ||
this._mesh._colors[0].push(colors[c0].a); | ||
} | ||
this._mesh._colors[0].push(colors[c1].r); | ||
this._mesh._colors[0].push(colors[c1].g); | ||
this._mesh._colors[0].push(colors[c1].b); | ||
if (numColComponents === 4) { | ||
this._mesh._colors[0].push(colors[c1].a); | ||
} | ||
this._mesh._colors[0].push(colors[c2].r); | ||
this._mesh._colors[0].push(colors[c2].g); | ||
this._mesh._colors[0].push(colors[c2].b); | ||
if (numColComponents === 4) { | ||
this._mesh._colors[0].push(colors[c2].a); | ||
} | ||
} | ||
|
||
if (hasTexCoord) { | ||
this._mesh._texCoords[0].push(texCoords[t0].x); | ||
this._mesh._texCoords[0].push(texCoords[t0].y); | ||
if (numTexComponents === 3) { | ||
this._mesh._texCoords[0].push(texCoords[t0].z); | ||
} | ||
this._mesh._texCoords[0].push(texCoords[t1].x); | ||
this._mesh._texCoords[0].push(texCoords[t1].y); | ||
if (numTexComponents === 3) { | ||
this._mesh._texCoords[0].push(texCoords[t1].z); | ||
} | ||
this._mesh._texCoords[0].push(texCoords[t2].x); | ||
this._mesh._texCoords[0].push(texCoords[t2].y); | ||
if (numTexComponents === 3) { | ||
this._mesh._texCoords[0].push(texCoords[t2].z); | ||
if (hasAttributes) { | ||
var pInd = [p0,p1,p2]; | ||
for (j=0;j<3;j++) { | ||
for (k = 0; k < attr_numComp; k++){ | ||
this._mesh._dynamicFields[attrName].value.push( | ||
attr_data[attr_numComp*pInd[j]+k] | ||
); | ||
} | ||
} | ||
} | ||
p1 = p2; | ||
t1 = t2; | ||
|
||
//faceCnt++; | ||
break; | ||
|
@@ -1147,6 +1065,7 @@ x3dom.registerNodeType( | |
|
||
Array.forEach(this._parentNodes, function (node) { | ||
node.setGeoDirty(); | ||
if (hasAttributes) node._dirty.specialAttribs = true; | ||
}); | ||
} | ||
else { | ||
|
@@ -1245,4 +1164,4 @@ x3dom.registerNodeType( | |
} | ||
} | ||
) | ||
); | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use startsWith instead of != and why the underscore in "attrib_" ? I do not think there is a field with such a name ?