コンテンツにスキップ

Model animation

Experimental Feature

Play gltf model animation

model_animation.html
<!DOCTYPE html>
<!--   
    Model Information:
    * title: Low Poly Helicopter
    * source: https://sketchfab.com/3d-models/low-poly-helicopter-5bbed2de9baa4a13a7faa72653b78b64
    * author: antonmoek (https://sketchfab.com/antonmoek)

    Model License:
    * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
    * requirements: Author must be credited. Commercial use is allowed.

    If you use this 3D model in your project be sure to copy paste this credit wherever you share it:
    This work is based on "Low Poly Helicopter" (https://sketchfab.com/3d-models/low-poly-helicopter-5bbed2de9baa4a13a7faa72653b78b64) by antonmoek (https://sketchfab.com/antonmoek) licensed under CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)

-->    
<!--

    The human model and animation is from Mixamo (https://www.mixamo.com)
    Model: The Boss
    Animation: Standing Block Idle

-->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Model animation</title>
    <meta property="og:description" content="Play gltf model animation" />
    <meta name="mapray-version" content="experimental-feature">
    <meta name="mapray-api-status" content="experimental">
    <meta name="mapray-api-package" content="model-pbr">
    <script src="./model-pbr/mapray.min.js"></script>
    <script src="./model-pbr/maprayui.min.js"></script>
    <link rel="stylesheet" href="./model-pbr/mapray.css">
    <style>
        body {margin: 0; padding: 0;}
        html, body, div#mapray-container { height: 100%; }
    </style>
</head>

<body>
<div id="mapray-container"></div>
</body>
</html>

<script>
    class AnimationView extends maprayui.StandardUIViewer {
        constructor(container, options) {
        super(container, options);
            // Initial time
            this.time = [0.0, 0.0];
        }

        onUpdateFrame(delta_time) {
            super.onUpdateFrame(delta_time);

            if(this.getEntityNum() == 2.0 ) {
                for( let i = 0; i < 2.0; i++ ) {
                    const entity = this.getEntity(i);
                    entity.model_animation_updater.update( mapray.animation.Time.fromNumber( this.time[i] ));
                    this.time[i] += delta_time;

                    // Loop animation
                    if (this.time[i] > entity.model_animation_end) {
                        this.time[i] = 0.0;
                    }
                }
            }
        }
    }

    const cloudApi = new mapray.cloud.CloudApiV2({
        tokenType: mapray.cloud.CloudApi.TokenType.ACCESS_TOKEN,
        token: "<YOUR_MAPRAY_ACCESS_TOKEN>"
    });

    // The StandardUIView in the ui package includes mouse-based camera manipulation.
    const uiviewer = new AnimationView( "mapray-container", {
        dem_provider: new mapray.StandardDemProvider( cloudApi.getDefaultDemAsResource() ),
        atmosphere: new mapray.Atmosphere()
    } );

    uiviewer.setCameraPosition({
        longitude: 139.76090693564387,
        latitude: 35.66494022012519, 
        height: 100
    });

    uiviewer.setLookAtPosition({
        longitude: 139.7610190665805,
        latitude:  35.66572621212459, 
        height: 50
    });

    // Add city view
    const urls = [
        "https://opentiles.mapray.com/3dcity/tokyo_n/tile-index.json",
        "https://opentiles.mapray.com/3dcity/tokyo_s/tile-index.json",
    ];
    urls.map(url => {
        const provider = new mapray.StandardB3dProvider({url: url});
        uiviewer.viewer.b3d_collection.createScene( provider );
    });



    const resource = cloudApi.get3DDatasetAsResource(  [ 5080671454232576, 5088996979900416 ] );
    const loader = new mapray.SceneLoader( uiviewer.viewer.scene, resource, {
        onEntity: ( loader, entity, prop ) => {
            uiviewer.addEntity(entity);
        }
    } );

    loader.load();


</script>

Info

このサンプルコードは、<YOUR_MAPRAY_ACCESS_TOKEN>を、あなたのMapray CloudアカウントのOrganization Tokenに置き換えるまで、期待通りに動作しません。