コンテンツにスキップ

Support of gltf variant

Experimental Feature

Update model variant at runtime.

set_material_variant.html
<!DOCTYPE html>
<!--   
    Model Information:
    https://github.com/KhronosGroup/glTF-Sample-Models/tree/main/2.0/MaterialsVariantsShoe
    This model uses the KHR_materials_variants extension. 
    It is a shoe with 3 color variants in it: "Beach", "Midnight", and "Street".
    If each variant was a separate model, they would be 5.4 MB each. 
    Combined they make up a single model that is 7.8MB since they share geometry and all textures except the base color texture.

    Model License:
    * license type: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)
    * requirements: Author must be credited. Commercial use is allowed.
-->    
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Support of gltf variant</title>
    <meta property="og:description" content="Update model variant at runtime." />
    <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%; }
        .map-overlay { 
            font: 12px/20px "Robot", sans-serif;
            position: absolute;
            width: 200px;
            top: 0;
            left: 0;
            padding: 10px;
        }
        .map-overlay .map-overlay-inner {
            background-color: #fff;
            color: #000;
            box-shadow: 0 1px 2px rgba(0,0,0,0.1);
            border-radius: 3px;
            padding: 10px;
            margin-bottom: 10px;
        }
        .map-overlay-inner .select-fieldset {
            display: block;
        }
        .map-overlay-inner fieldset {
            display: flex;
            justify-content: space-between;
            border: none;
        }
        .map-overlay-inner .select-fieldset label {
            display: block;
            margin-bottom: 5px;
        }
        .map-overlay-inner label {
            font-weight: 700;
            margin-right: 10px;
        }
    </style>
</head>

<body>
<div id="mapray-container"></div>
<div class="map-overlay top">
    <div class="map-overlay-inner">
    <fieldset class="select-fieldset">
        <label for="variants">Select variant</label>
        <select id="variants" name="variants">
            <option value="midnight">Midnight</option>
            <option value="beach">Beach</option>
            <option value="street">Street</option>
        </select>
    </fieldset>
    </div>
</div>
</body>
</html>

<script>

    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 maprayui.StandardUIViewer( "mapray-container", { 
        dem_provider: new mapray.StandardDemProvider( cloudApi.getDefaultDemAsResource() )
    } );

    uiviewer.setCameraPosition({
        longitude: 139.76489,
        latitude: 35.67209, 
        height: 455
    });

    uiviewer.setLookAtPosition({
        longitude: 139.76489,
        latitude:  35.67209, 
        height: 455
    });

    document
    .getElementById('variants')
    .addEventListener('change', function () {
        console.log(this.value);

        if( uiviewer.getEntityNum() > 0 ) {
            uiviewer.getEntity(0).setMaterialVariant(this.value);
        }
    });



    const resource = cloudApi.get3DDatasetAsResource(  [ 5106260282179584 ] );
    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に置き換えるまで、期待通りに動作しません。