Announcement

Collapse
No announcement yet.

Moving Collada Model

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving Collada Model

    We've worked with WWJ for many years, but I am brand new to Web WorldWind. How would I go about animating or updating the position of a collada model? I've added a model per the following code:

    Code:
    var modelLayer = new WorldWind.RenderableLayer("ModelLayer");
    wwd.addLayer(modelLayer);
    
    var position = new WorldWind.Position(37.62, -122.37, 5000);
    var duck = new WorldWind.ColladaLoader(position);
    duck.init({dirPath: 'resources/collada_models/duck/'});
    duck.load('duck.dae', function (scene) {
        scene.scale = 200;
        scene.xRotation = 180;
        modelLayer.addRenderable(scene);
    });

    If I set the position of the model like this immediately after loading the model it does appear in the new/different position:

    Code:
    duck.position = new WorldWind.Position(38, -123, 6000);

    But when I try to use the following test code to move the model on a timer nothing happens:

    Code:
    // Use a timer to move the model
    var lat = 37.62;
    var lon = -122.37;
    var alt = 500;
    window.setInterval(function() {
    
        lat += .1;
        lon += .1;
        alt += 100;
    
        duck.position = new WorldWind.Position(lat, lon, alt);
    
        wwd.redraw();
    
    }, 1000);
    Any help would be greatly appreciated!

    Also, is Web WorldWind being actively developed? We've been using Cesium for browser-based globe applications for several years, but the Web WorldWind product has some very interesting features. I would love to see it continue to develop. I would especially like to find out if 3D shapes are being developed (such as spheres, cylinders, polygons, etc.).

    Thanks,
    Rob

  • #2
    I realized that creating the colladaLoader does not return a reference to the scene (model). Instead it is the .load function of the colladaLoader that returns a reference to the scene (model).

    So setting the position on the scene object returned to the function provided as the second parameter in the .load method results in the ability to move/animate the collada model...

    Code:
    ...
    var modelLayer = new WorldWind.RenderableLayer("ModelLayer");
    wwd.addLayer(modelLayer);
    
    var position = new WorldWind.Position(37.62, -122.37, 5000);
    var colladaLoader = new WorldWind.ColladaLoader(position);
    colladaLoader.init({dirPath: 'resources/collada_models/'});
    colladaLoader.load('duck.dae', animateTest);
    ...
    
    function animateTest(model) {
    
        model.scale = 200;
        model.xRotation = 180;
        modelLayer.addRenderable(model);
    
        // Use a timer to move the model
        var lat = 37.62;
        var lon = -122.37;
        var alt = 500;
        window.setInterval(function() {
    
            if (lat > 38.0) {
                lat = 37.62;
                lon = -122.37;
                alt = 500;
            }
    
            lat += .01;
            lon += .01;
            alt += 100;
    
            model.position = new WorldWind.Position(lat, lon, alt);
    
            wwd.redraw();
    
        }, 1000);
    
    }

    Comment


    • #3
      RAM357, glad to hear you found a solution, and yes, WebWorldWind is actively being developed! Checkout GitHub for the latest and greatest info on the work happening now.
      Zach
      World Wind Team
      https://github.com/NASAWorldWind

      Comment


      • #4
        glueck, thanks for the response. I'll take a look at GitHub to get a sense about what's happening with the product.

        Could you point me in the right direction for understanding x,y and z translations and rotations? I have collada models that I am loading and animating. When I load the models they are upsidedown, and so I've experimented with flipping both the x and y rotations (and compensating z when flipping the x rotation). While the heading looks good the pitch and roll don't look right no matter what I do. So I'm guessing I might need to do something with the translations when I load the models. But I don't have any idea how the translations work. I don't know what values (or ranges) to use or what the values do when they are applied. I have not been able to interpret the results of experimenting with various value assignments.

        I believe I've worked out that x, y and z map as follows:
        • x = heading
        • y = roll
        • z = pitch
        Are these correct?

        If you could point me to a resource (whether Web WorldWind related or GL/3D related) that would help me understand how to use these parameters I would really appreciate it!

        *edited to ask if x,y,z mappings are correct
        Last edited by RAM357; 04-17-2018, 03:52 PM.

        Comment


        • #5
          Translations are used to move the model linearly on the x, y, z axes.
          An other way to think about translations is that they change the center of the model.
          If you don't need to change the center of the model, leave them at 0.

          For example the center of the duck is at the base, not inside the model.


          Rotations are used to rotate the model around one of the axes from the center point.
          We have an app example on github with rotations:
          https://github.com/NASAWorldWind/Web...ada/Collada.js

          x = heading
          y = roll
          z = pitch

          Are these correct?
          There is no right answer, it depends how your model was generated.


          If your model is upside down you can use one rotation for flipping the model.
          Then use one of the other two axes for heading.

          For example let's say we want the duck to be parallel with the earth surface and move around.
          1. Set xRotation to 90 deg, make the base of the duck parallel with the surface.
          2. Move the duck by setting it's position.
          3. Use the yRotation for heading, this value will need to be updated constantly as the duck moves.

          Hope this helps.

          Comment


          • #6
            strikerM,

            Thank you for the detailed response. This helps me understand the purpose and use of translations and rotations! It sounds like the issue I'm experiencing with pitch and roll probably just comes down to applying the values properly.

            Thanks again for the help!

            Comment

            Working...
            X