kovacsv / JSModeler

A JavaScript framework to create and visualize 3D models.
MIT License
655 stars 123 forks source link

SVG node ids and JSM.Model #6

Closed saadfaisal closed 10 years ago

saadfaisal commented 10 years ago

In my CSV , i have number of nodes(paths actually) with their specific IDs, is there a way that i can refer to the created JSM.Models from JSM.SvgToModel(), using their SVG ids with something like the following

var modelAndMaterials = JSM.SvgToModel (svgObject, 5, 5);
var model = modelAndMaterials[0];

var head_model = model.GetModelById("head_node");

and in my SVG node, i have two paths with ids set to "head_node" and "body_node", so now i am sure that the JSM.Model that i have just got is for the "head_node" path.

I hope i am clear in my requirement.

kovacsv commented 10 years ago

It is not possible to find bodies by id, but the index should be the same. So you can get the corresponding body by model.GetBody (pathIndex).

saadfaisal commented 10 years ago

Index is not the same that is the issue, the path that have defined first comes second in the Index and the path that i have second comes first.

kovacsv commented 10 years ago

Can you paste your svg file?

saadfaisal commented 10 years ago

sure , however i think the easier approach is to keep your shapes in different svg nodes and convert them individually with SvgToModel , that will be the easiest thing to do at this , however here is the svg for your reference. I have set the height and width parameter to 1 and set the style to hidden to keep the svg invisible.

<svg height="1" width="1" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" style="visibility: hidden;" id="svgid">
<g id="layer1">
<path
   style="fill:#ff0000"
   d="m 25.502398,783.90809 c -7.98199,0 -14.407063,5.69317 -14.407063,12.77293 l 0,46.08926 c 0,7.07976 6.425073,12.7896 14.407063,12.7896 l 350.788632,0 c 7.98198,0 14.40706,-5.70984 14.40706,-12.7896 l 0,-46.08926 c 0,-7.07976 -6.42508,-12.77293 -14.40706,-12.77293 l -350.788632,0 z m 31.432075,10.6719 c 13.998076,0 25.345756,10.75044 25.345756,24.01177 0,13.26133 -11.34768,24.01177 -25.345756,24.01177 -13.998076,0 -25.345758,-10.75044 -25.345758,-24.01177 0,-13.26133 11.347682,-24.01177 25.345758,-24.01177 z m 55.894067,0 221.82541,0 c 7.98199,0 14.40706,5.90523 14.40706,13.23982 l 0,21.5439 c 0,7.33458 -6.42507,13.23982 -14.40706,13.23982 l -221.82541,0 c -7.98199,0 -14.407065,-5.90524 -14.407065,-13.23982 l 0,-21.5439 c 0,-7.33459 6.425075,-13.23982 14.407065,-13.23982 z"
   id="STONEHEAD-000001" />

<path fill="#ffff00" d="M304 146C242.5142822265625 146 189.93736267089844 176.41582489013672 168.5625 219.4375L126 219.4375L126 485.4375L486 485.4375L486 219.4375L439.4375 219.4375C418.05596923828125 176.4159164428711 365.4692077636719 146 304 146z " id="BASE-000001" />
</g>
<defs id="SvgjsDefs1001"><pattern patternUnits="userSpaceOnUse" height="100" width="100" y="0" x="0" id="SvgjsPattern1011"><image height="128" width="128" xlink:href="img/egyptian_marble_128.jpg" id="SvgjsImage1012"></image></pattern></defs>
</svg>
kovacsv commented 10 years ago

For me it appears that the body indices are the same as svg indices of path elements: 0.: The red shape with the hole on the bottom of the model. 1.: The yellow shape on the top of the model.

But if it not works, you can convert every path separately.

saadfaisal commented 10 years ago

Yes you are absolutely right , i was mistaken at the identification of the svg indices.