<template>
    <div class="home">
      <div class="header">

      </div>
      <div class="content">
        <div id="left">
          <a @click="showAssetsList(0)" href=""> 材质 </a>
          <a @click="showAssetsList(1)" href=""> 贴图 </a>
        </div>
        <div id="middle">
            <div id="viewerContainner">
              <!-- viewSize : x = {{ viewSize.x }}, y = {{ viewSize.y }}  <br/>
              styleSize : x = {{ styleSize.x }}, y = {{ styleSize.y }}   -->

            </div>
            <div id="assetsListContainner">
              <assets-list :assets="assets" ></assets-list>
            </div>
        </div>
        <div id="right"></div>
      </div>
    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import AssetsList from '../components/AssetsList.vue'


import * as THREE from 'three'
import Viewer from '../webgl/Viewer'
import MarmosetAssetsManager from '../webgl/assets/marmosets/MarmosetAssetsManager'
import { MeshMaterial } from '../webgl/materials/marmoset';

const examples = [
  "static/model/henrique/henrique.mview",
  "static/model/vivfox/vivfox.mview",
  "static/model/metal/metal.mview",
]



@Component({
  components: { 
    'assets-list': AssetsList
  }
})
export default class Home extends Vue {

  assets:any[] = []

  mounted() {

    let containner = this.$el.querySelector("#viewerContainner") as HTMLDivElement;
    let viewer = new Viewer()
    viewer.start(containner)
    
    let loader = new MarmosetAssetsManager()

    let index = Number(this.$route.query['index']) || 0

    loader.load(examples[index]).then( model => {

      model && viewer.add(model);

      window['model'] = model
      
      let ms = loader.getMaterials();
      ms.forEach( item => this.assets.push(item));

    })
    window.THREE = THREE
    

  }

}
</script>
<style lang="less" scoped>

  .home {


    display: flex;

    justify-content: space-between;

    position: fixed;
    width: 100%;
    height: 100%;

    .header {

      height: 3rem;

    }

    .content {

      flex: 1;
      border: 1px solid red;
   
      height: 100%;

      display: flex;
      justify-content: space-between;

    }

    
    #left {

      width: 3rem

    }

    #middle {

      flex: 1;

      display: flex;
      flex-direction: column;
      justify-content: space-between;

    }
  
    #right {

      width: 200px;
    }

    #assetsListContainner {

      height: 200px;
      border: 1px solid green;

      flex-shrink: 0;

    }

    #viewerContainner {

      flex: 1;
      border: 1px solid blue;
      overflow: hidden;
   
    }

  }

</style>
