[x3d-public] Report for now, JinLOA4Canonical.x3d scaling and recentering.

Michalis Kamburelis michalis.kambi at gmail.com
Thu Jun 22 05:27:48 PDT 2023


You need to add containerField="value" to the "<MetadataXxx ...>"
children inside "<MetadataSet ...>".

Reason: the default containerField of MetadataXxx nodes is "metadata".
This makes indeed cumbersome behavior in case of children of
"<MetadataSet ...>", that you usually want placed in MetadataSet.value
(MFNode), not in MetadataSet.metadata (SFNode). But there's no easy
solution otherwise -- we need default containerField of MetadataXxx
nodes to be "metadata" to work naturally outside of MetadataSet. And
since X3D XML encoding is general, it cannot have special rules like
"containerField default is X in this context, Y in that context" --
that would complicate X3D browsers implementations just for this
specific case.

Note that the attached X3D model actually has it correct in 1x
MetadataString. But then 4x other MetadataString, and 1x
MetadataFloat, have it wrong.
,
Here's the relevant piece, with some whitespace added by me:

"""
<MetadataSet containerField="metadata" name="HAnimHumanoid.info"
reference="https://www.web3d.org/documents/specifications/19774/V2.0/Architecture/ObjectInterfaces.html#Humanoid">

    <MetadataString name="authorName" value=""Jin Hoon Lee and
Min Joo Lee, Chul Hee Jung and Myeong Won Lee""
containerField="value"></MetadataString>

    <MetadataString name="authorEmail"
value=""myeongwonlee at gmail.com""></MetadataString>

    <MetadataString name="creationDate" value=""31 March
2011""></MetadataString>

    <MetadataString name="gender" value=""female""></MetadataString>

    <MetadataFloat name="height" value="1.5"></MetadataFloat>

    <MetadataString name="humanoidVersion"
value=""2.0""></MetadataString>
</MetadataSet>
"""

Here's the corrected version (makes CGE and view3dscene open without
any warnings):

"""
<MetadataSet containerField="metadata" name="HAnimHumanoid.info"
reference="https://www.web3d.org/documents/specifications/19774/V2.0/Architecture/ObjectInterfaces.html#Humanoid">

    <MetadataString name="authorName" value=""Jin Hoon Lee and
Min Joo Lee, Chul Hee Jung and Myeong Won Lee""
containerField="value"></MetadataString>

    <MetadataString name="authorEmail"
value=""myeongwonlee at gmail.com""
containerField="value"></MetadataString>

    <MetadataString name="creationDate" value=""31 March
2011"" containerField="value"></MetadataString>

    <MetadataString name="gender" value=""female""
containerField="value"></MetadataString>

    <MetadataFloat name="height" value="1.5"
containerField="value"></MetadataFloat>

    <MetadataString name="humanoidVersion" value=""2.0""
containerField="value"></MetadataString>
</MetadataSet>
"""

Regards,
Michalis


czw., 22 cze 2023 o 04:48 John Carlson <yottzumm at gmail.com> napisał(a):
>
> // Working prototype code to find texCoordIndex values > length of TextureCoordinate.point.
>
> // You'll want to translate into your own language/encoding.  Only works for IFS right now
>
> let fs = require("fs");
> let file = "JinLOA4Canonical.json";
> let data = fs.readFileSync(file).toString();
> let json = JSON.parse(data);
> /*console.log(json.X3D);
> console.log(json.X3D.Scene);
> console.log(json.X3D.Scene["-children"]);
> console.log(json.X3D.Scene["-children"][3]["HAnimHumanoid"]);
> console.log(json.X3D.Scene["-children"][3]["HAnimHumanoid"]["@scale"]);
> */
> /*
> let divisor = [];
> divisor[0] = scale[0];
> divisor[1] = scale[1];
> divisor[2] = scale[2];
> */
> let HUMANCHILD = 3;
>
> //json.X3D.Scene["-children"][HUMANCHILD] = json.X3D.Scene["-children"][HUMANCHILD+1];
>
> let scale = json.X3D.Scene["-children"][HUMANCHILD]["HAnimHumanoid"]["@scale"];
> let center = json.X3D.Scene["-children"][HUMANCHILD]["HAnimHumanoid"]["-skeleton"][0]["HAnimJoint"]["@center"];
>
> //delete json.X3D.Scene["-children"][HUMANCHILD+1];
>
> let x = center[0];
> let y = center[1];
> let z = center[2];
>
>
> function centering(json) {
> for (let j in json) {
> if (j === "@center") {
> if (json["@name"] === "l_talocrural") {
> l_x = json["@center"][0];
> l_z = json["@center"][2];
> y = json["@center"][1];
> } else if (json["@name"] === "r_talocrural") {
> r_x = json["@center"][0];
> y = json["@center"][1];
> r_z = json["@center"][2];
> }
> } else if (typeof json[j] === 'object') {
> centering(json[j]);
> }
> }
> }
>
> function transform(json, indent, parent, max, parentTranslation) {
> let translation = [0,0,0];
> for (let j in json) {
> if (j === "@translation") {
> json[j][0] = json[j][0] - x;
> json[j][1] = json[j][1] - y;
> json[j][2] = json[j][2] - z;
> json[j][0] = json[j][0] / scale[0];
> json[j][1] = json[j][1] / scale[1];
> json[j][2] = json[j][2] / scale[2];
> translation[0] = json[j][0] + parentTranslation[0];
> translation[1] = json[j][1] + parentTranslation[1];
> translation[2] = json[j][2] + parentTranslation[2];
> json[j][0] = parseFloat(json[j][0].toFixed(4));
> json[j][1] = parseFloat(json[j][1].toFixed(4));
> json[j][2] = parseFloat(json[j][2].toFixed(4));
> // delete json[j];
> } else if (j === "@center") {
> json[j][0] = json[j][0] - x;
> json[j][1] = json[j][1] - y;
> json[j][2] = json[j][2] - z;
> json[j][0] = json[j][0] / scale[0];
> json[j][1] = json[j][1] / scale[1];
> json[j][2] = json[j][2] / scale[2];
> json[j][0] = json[j][0] + parentTranslation[0];
> json[j][1] = json[j][1] + parentTranslation[1];
> json[j][2] = json[j][2] + parentTranslation[2];
> json[j][0] = parseFloat(json[j][0].toFixed(4));
> json[j][1] = parseFloat(json[j][1].toFixed(4));
> json[j][2] = parseFloat(json[j][2].toFixed(4));
> // console.log(json["@name"]);
> // console.log(json["@center"][0].toFixed(4), json["@center"][1].toFixed(4), json["@center"][2].toFixed(4));
> } else if (j === "@centerOfRotation") {
> json[j][0] = json[j][0] - x;
> json[j][1] = json[j][1] - y;
> json[j][2] = json[j][2] - z;
> json[j][0] = json[j][0] / scale[0];
> json[j][1] = json[j][1] / scale[1];
> json[j][2] = json[j][2] / scale[2];
> json[j][0] = json[j][0] + parentTranslation[0];
> json[j][1] = json[j][1] + parentTranslation[1];
> json[j][2] = json[j][2] + parentTranslation[2];
> json[j][0] = parseFloat(json[j][0].toFixed(4));
> json[j][1] = parseFloat(json[j][1].toFixed(4));
> json[j][2] = parseFloat(json[j][2].toFixed(4));
> } else if (j === "@position") {
> json[j][0] = json[j][0] - x;
> json[j][1] = json[j][1] - y;
> json[j][2] = json[j][2] - z;
> json[j][0] = json[j][0] / scale[0];
> json[j][1] = json[j][1] / scale[1];
> json[j][2] = json[j][2] / scale[2];
> json[j][0] = json[j][0] + parentTranslation[0];
> json[j][1] = json[j][1] + parentTranslation[1];
> json[j][2] = json[j][2] + parentTranslation[2];
> json[j][0] = parseFloat(json[j][0].toFixed(4));
> json[j][1] = parseFloat(json[j][1].toFixed(4));
> json[j][2] = parseFloat(json[j][2].toFixed(4));
> } else if (j === "IndexedFaceSet") {
> // console.log(json[j]);
> if (json[j]["@texCoordIndex"]) {
> var tci = json[j]["@texCoordIndex"];
> // console.log(tci);
> max = Math.max(...tci);
> // console.log(max);
>
> }
> transform(json[j], indent+1, json, max, translation);
> } else if (j === "@point") {
> let i = 0;
> for (i = 0; i < json[j].length; i+=3) {
> if (!parent["TextureCoordinate"]) {
> json[j][i+0] = json[j][i+0] - x;
> json[j][i+1] = json[j][i+1] - y;
> json[j][i+2] = json[j][i+2] - z;
> json[j][i+0] = json[j][i+0] / scale[0];
> json[j][i+1] = json[j][i+1] / scale[1];
> json[j][i+2] = json[j][i+2] / scale[2];
> json[j][i+0] = json[j][i+0] + parentTranslation[0];
> json[j][i+1] = json[j][i+1] + parentTranslation[1];
> json[j][i+2] = json[j][i+2] + parentTranslation[2];
> json[j][i+0] = parseFloat(json[j][i+0].toFixed(4));
> json[j][i+1] = parseFloat(json[j][i+1].toFixed(4));
> json[j][i+2] = parseFloat(json[j][i+2].toFixed(4));
> }
> }
> if (parent["TextureCoordinate"]) {
> if (json[j].length/2 > 0 && json[j].length/2 <= max) {
> console.log("point length", json[j].length, ", point length/2", json[j].length/2, ", Max index", max);
> console.log(parent);
> }
> }
> } else if (typeof json[j] === 'object') {
> transform(json[j], indent+1, json, max, translation);
> }
> }
> }
>
> centering(json);
>
> x = (l_x + r_x) / 2;
> z = (l_z + r_z) / 2;
>
> console.log(x, y, z);
>
> transform(json, 0, null, Math.INFINITY, [0,0,0]);
>
> console.log(scale);
> scale[0] = scale[0] / scale [0];
> scale[1] = scale[1] / scale [1];
> scale[2] = scale[2] / scale [2];
> console.log(scale);
>
> let out = JSON.stringify(json, null, 2);
> let outfile = "JinLOA4Canonical101.json";
> fs.writeFile(outfile, out, function(err) {
> if(err) {
> return console.error(err);
> }
> });
>
> json = JSON.parse(data);
> out = JSON.stringify(json, null, 2);
> outfile = "JinLOA4Canonical100.json";
> fs.writeFile(outfile, out, function(err) {
> if(err) {
> return console.error(err);
> }
> });
>
>
> On Wed, Jun 21, 2023 at 9:10 PM John Carlson <yottzumm at gmail.com> wrote:
>>
>> Here's the current JinLOA4Canonical101.x3d attached. Michalis, you will find a metadata problem if you launch it.  I was able to view in freewrl 4 and 5. The viewpoint isn't right, suggestions welcome.  Joe, I haven't been able to delete the translations without major problems, I will call you tomorrow.
>>
>> Files are here for now:
>>
>> https://coderextreme.net/jin.zip



More information about the x3d-public mailing list