2

I am a newbie in this field and have been trying to work with the x3dom objects. The problem that I am now facing is how to display the attributes of the x3dom objects as a popup. I have seen the examples given in the x3dom website but have not found any relevant examples yet. I would be glad if anybody have some examples to share. Thank you in advance.

2 Answers2

0

You could use the attributes property (e.g. document.getElementById("id").attributes), here's an example that shows a table of attributes when you click either buttons:

<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
    <title>X3DOM</title>
    <link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.0.4/css/bootstrap.min.css" rel="stylesheet" />

</head>
<body class="container">


    <X3D width="100%" height="300px">
        <Scene>
            <Shape id="myShape">
                <Appearance>
                    <Material id="myMaterial" diffuseColor="0.6 0.6 0.6" specularColor="0.8 0.8 0.8" shininess="0.145" ambientIntensity="0.2" emissiveColor="0,0,0"/>
                </Appearance>
                <Sphere />
            </Shape>
        </Scene>
    </X3D>


    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="http://x3dom.org/x3dom/release/x3dom.js"></script>
    <script>
    function displayAttributes(objectId){
        var code = '';
        var attributes = document.getElementById(objectId).attributes;
        $.each(attributes, function(index, attr) {
            code += '<tr><th>' + attr.name +'</th><td>' + attr.value + '</td></tr>';
        });
        $("#attributesTable").html(code);
    }
    </script>


    <button onclick="displayAttributes('myShape')" class="btn btn-large">Attributes of the shape</button>
    <button onclick="displayAttributes('myMaterial')" class="btn btn-large">Attributes of the material</button>

    <table id="attributesTable" class="table table-striped table-bordered" style="margin-top:50px"></table>


</body>
</html>

Gist: https://gist.github.com/4329304

wildpeaks
  • 7,273
  • 2
  • 30
  • 35
  • Thank you so much for the reply. It clarified some points for me. However what I was looking for was clicking on the object and getting its attribute info as popup rather than from the buttons. Thank you once again.. – user1879084 Dec 18 '12 at 21:06
0

exactly what you are trying is unclear not sure this helps

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="http://x3dom.org/x3dom/example/x3dom.css"></link>
<script type="text/javascript" src = "http://x3dom.org/x3dom/example/x3dom.js"></script>
</head>
<body>
<X3D showLog='true' width="400px" height="400px"><Scene>
<Shape><Box size="2 2 2" onclick="alert_attributes();" /></Shape>
</Scene></X3D>
<script>
function alert_attributes()
{
var size = document.getElementsByTagName("Box")[0].getAttribute('size');
x3dom.debug.logInfo( size );
alert( size );

}
</script>
</body>
</html>
drfrog
  • 347
  • 2
  • 9