Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Model through the entity API #7378

Closed
bivald opened this issue Dec 4, 2018 · 7 comments
Closed

Expose Model through the entity API #7378

bivald opened this issue Dec 4, 2018 · 7 comments

Comments

@bivald
Copy link

bivald commented Dec 4, 2018

In a way this is related to #4727, but I wanted to ask anyway. First of all, super big thank you for Cesium - it's truly an awesome tool!

It would be great if the underlying model was exposed through the entity API. I describe the reasons in https://groups.google.com/forum/#!topic/cesium-dev/4wVIah9ZAuk, but in short they are:

  • I'm looking to handle built-in animations on a fine grained level (start, stop on named animations and layer groups, keyframe names)
  • Using getNode to manipulate the model (hide, remove, add, set properties)

Currently I use nodeTransformation which works for some parts, but it would be exciting to be able to manipulate the actual model (similar to what you can do on an SVG).

I do realize this might be awkward, since you would need to expose the promises for model loaded etc. But it would strike a great balance between features (in the Model) and ease of use (of the Entity API)

@hpinkos
Copy link
Contributor

hpinkos commented Dec 4, 2018

Hello @bivald! Thanks for opening this issue, but this isn't something we're going to be able to do with the current version of the Entity API. The Entity API is meant to provide a level of abstraction away from the underlying primitives. Depending on whether you're using certain dynamic properties, the primitive might actually be destroyed and swapped out with a new one, so exposing the primitive to the end-user may result in unexpected behavior.

If you need to make changes to lower level model properties like you're describing, I would recommend creating and updating the model primitive yourself. We're happy to help if you have questions about this!

@hpinkos hpinkos closed this as completed Dec 4, 2018
@cesium-concierge
Copy link

Congratulations on closing the issue! I found these Cesium forum links in the comments above:

https://groups.google.com/forum/#!topic/cesium-dev/4wVIah9ZAuk

If this issue affects any of these threads, please post a comment like the following:

The issue at #7378 has just been closed and may resolve your issue. Look for the change in the next stable release of Cesium or get it now in the master branch on GitHub https://github.com/AnalyticalGraphicsInc/cesium.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@bivald
Copy link
Author

bivald commented Dec 4, 2018

Thank you @hpinkos, good points. I would be more then happy to use my own primitives, but have found it hard to enable the Entity API features, such as trackedEntity and position/orientation. The mailing list is best way to get help and pointers about this, right?

@hpinkos
Copy link
Contributor

hpinkos commented Dec 4, 2018

@bivald Here is some sample code. It shows how to convert position/orientation to a modelMatrix, and how to use camera.lookAt so the camera is focused on the primitive (note that if the model is moving you'll need to update camera.lookAt when it updates)

But yes, the mailing list is the best place to ask for help if you encounter any other issues. Our team also monitors the mailing list so make sure every question gets attention. Thanks!

var viewer = new Cesium.Viewer('cesiumContainer', {
    shouldAnimate : true,
    shadows : true
});

var scene = viewer.scene;

var url = '../../SampleData/models/CesiumAir/Cesium_Air.glb';
var height = 10000.0;
var heading = Cesium.Math.toRadians(30.0);
var pitch = Cesium.Math.toRadians(10.0);
var roll = Cesium.Math.toRadians(20.0);
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);

var origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, hpr);

var model = scene.primitives.add(Cesium.Model.fromGltf({
    url : url,
    modelMatrix : modelMatrix
}));

model.readyPromise.then(function(model) {
    model.activeAnimations.addAll({
        speedup : 0.5,
        loop : Cesium.ModelAnimationLoop.REPEAT
    });

    var camera = viewer.camera;

    var controller = scene.screenSpaceCameraController;
    var r = 2.0 * Math.max(model.boundingSphere.radius, camera.frustum.near);
    controller.minimumZoomDistance = r * 0.5;

    var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());
    var heading = Cesium.Math.toRadians(230.0);
    var pitch = Cesium.Math.toRadians(-20.0);
    camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, r * 2.0));
}).otherwise(function(error){
    console.log(error);
});

@OmarShehata
Copy link
Contributor

I understand why we can't expose the primitive, but it still feels like the Entity API is awfully limited with regards to controlling animation. Like it currently allows me to set clampAnimations, which is a very specific thing (how to handle when there are two channels of animation that aren't the same length playing together), but doesn't for example allow me to control how the animation should loop (which seems like a more common thing).

This PR #7361 adds the ability to control the animation speed, but still doesn't allow you to control other things. I wonder if it would be worth creating a ModelAnimation property on ModelGraphics that the underlying primitive can clone from or something like that?

@hpinkos
Copy link
Contributor

hpinkos commented Dec 4, 2018

@OmarShehata we can certainly consider piping more things through. It's just that no one's asked for it yet.

@mramato
Copy link
Member

mramato commented Dec 4, 2018

Yes, instead of just exposing underlying primitives, what we should be doing is expanding the Entity API to handle our users use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants