0

http://adndevblog.typepad.com/cloud_and_mobile/2015/12/understand-the-coordinate-system-of-view-and-data-api-with-axishelper-extension.html

1, the above doesn't seem to work in current viewer, thoughts?

2, Augusto says: https://stackoverflow.com/a/39123356/5410501

However, the 3D bounding box extension seems to be functioning in the demo page: http://viewer.autodesk.io/node/gallery/embed?id=560c6c57611ca14810e1b2bf&extIds=Autodesk.ADN.Viewing.Extension.BoundingBox

I want (need) to draw lines in 3D viewer and 2D viewer. How can I do this?

The below code in V2.11 does not seem to draw lines. Try http://viewer.autodesk.io/node/gallery/#/viewer?id=57ecc0fc21f5a6ec046dd0fd

with below pasted into console.

var drawLine = function(start, end, material) {

        var geometry = new THREE.Geometry();

        geometry.vertices.push(new THREE.Vector3(
            start.x, start.y, start.z));

        geometry.vertices.push(new THREE.Vector3(
            end.x, end.y, end.z));

        var line = new THREE.Line(geometry, material);

        NOP_VIEWER.impl.scene.add(line);
        //refresh NOP_VIEWER
        NOP_VIEWER.impl.invalidate(true);

        return line;
}

var _axisLines = [];

    //get bounding box of the model
    var boundingBox = NOP_VIEWER.model.getBoundingBox();
    var maxpt = boundingBox.max;
    var minpt = boundingBox.min;

    var xdiff =    maxpt.x - minpt.x;
    var ydiff =    maxpt.y - minpt.y;
    var zdiff =    maxpt.z - minpt.z;

    //make the size is bigger than the max bounding box 
    //so that it is visible 
    var size = Math.max(xdiff,ydiff,zdiff) * 1.2; 
    //console.log('axix size :' + size);


    // x-axis is red
    var material_X_Axis = new THREE.LineBasicMaterial({
        color: 0xff0000,  //red 
        linewidth: 2
    });
    NOP_VIEWER.impl.matman().addMaterial('material_X_Axis',material_X_Axis,true);
    //draw the x-axix line
    var xLine = drawLine(
        {x : 0, y : 0, z : 0} ,
        {x : size, y : 0, z : 0} , 
        material_X_Axis);

    _axisLines.push(xLine);


    // y-axis is green
    var material_Y_Axis = new THREE.LineBasicMaterial({
        color: 0x00ff00,  //green 
        linewidth: 2
    });
    NOP_VIEWER.impl.matman().addMaterial('material_Y_Axis',material_Y_Axis,true);
    //draw the y-axix line
    var yLine = drawLine(
        {x : 0, y : 0, z : 0} ,
        {x : 0, y : size, z : 0} , 
        material_Y_Axis);

    _axisLines.push(yLine);


    // z-axis is blue
    var material_Z_Axis = new THREE.LineBasicMaterial({
        color: 0x0000ff,  //blue 
        linewidth: 2
    });
    NOP_VIEWER.impl.matman().addMaterial('material_Z_Axis',material_Z_Axis,true);
    //draw the z-axix line
    var zLine = drawLine(
        {x : 0, y : 0, z : 0} ,
        {x : 0, y : 0, z : size} , 
        material_Z_Axis);

    _axisLines.push(zLine);

console.log(_axisLines);
Community
  • 1
  • 1
MarshAPI
  • 35
  • 1
  • 6
  • In the Bounding Box extension, the viewer is being loaded locally and is version 1.2.23. I can easily draw lines into that view with the exact code posted on http://adndevblog.typepad.com/cloud_and_mobile/2015/12/understand-the-coordinate-system-of-view-and-data-api-with-axishelper-extension.html – MarshAPI Feb 19 '17 at 18:06
  • I can draw lines using the BondingBox extension as-is in the latest version of the viewer in 3D models: v 2.13. If you have trouble please post a code sample that can reproduce the issue. – Felipe Feb 20 '17 at 10:55
  • sample code added with sample viewer link that doesn't seem to like this line drawing code. (glad to know that this should be possible though) – MarshAPI Feb 20 '17 at 16:51
  • In the link you posted, try enabling the BoundingBox extension, works fine on my side. The code is available there: https://github.com/Autodesk-Forge/library-javascript-viewer-extensions/tree/master/src/Autodesk.ADN.Viewing.Extension.BoundingBox – Felipe Feb 21 '17 at 10:45

1 Answers1

0

May I know which version you are testing with?

I created a simple test to consume the codes of AxisHelper. It looks it can work with current default version of Viewer (2.10) . I also explicitly set version to 2.11, it can also work. https://github.com/xiaodongliang/TempTest

As the blog shows, to add additional geometries to the viewer, the native Three.js objects will be created, then added to the viewer scene, finally, refresh the view by viewer.impl.invalidate.

Hope this test sample could help you. If you are using v2.10, or, v2.11, and still have the issue, could you provide a small demo codes?

Xiaodong Liang
  • 2,051
  • 2
  • 9
  • 14