Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import {
  3.     Mesh,
  4.     MeshPhongMaterial,
  5.     FaceColors
  6. } from "../../node_modules/three/build/three.module.js";
  7. import { WOOD } from "../colors.mjs";
  8. import Builder from "./Builder2.mjs";
  9. import Randomizer from "./Randomizer.mjs";
  10.  
  11. export default class Barn extends Mesh {
  12.  
  13.     constructor() {
  14.  
  15.         const material = new MeshPhongMaterial( {
  16.             vertexColors: FaceColors,
  17.             flatShading: true
  18.         } );
  19.         const color = Randomizer.colorSpread( WOOD );
  20.  
  21.         const geometry = new Builder()
  22.             .repeat( 2, ( b, y ) => b.repeat( 11, ( b, x, height, mid ) => {
  23.  
  24.                 const angle = Math.PI / 2 + Math.PI / 2 / ( mid + 1 ) * x;
  25.                 height = 1 + Math.sin( angle ) / 2;
  26.                 return b.box( 1 / 8, 1 / 32, height ).randomize( 1 / 2 ).translate( x / 8, y * 11 / 8, height / 2 );
  27.  
  28.             } ) )
  29.             .repeat( 2, ( b, x ) => b.repeat( 11, ( b, y ) =>
  30.                 b.box( 1 / 32, 1 / 8, 1 ).randomize().translate( x * 11 / 8, y / 8, 1 / 2 ) ) )
  31.             .repeat( 5, ( b, x, height, mid, _1, count ) => {
  32.  
  33.                 const angle = Math.PI / 2 + Math.PI / 2 / ( mid + 1 ) * ( x * 8 / 11 );
  34.                 return b.repeat( 14, ( b, y ) =>
  35.                     b.box( 1 / 32, 1 / 8, 2 / count )
  36.                         .translate( Math.cos( angle ), y / 8, 2 / 4 + Math.sin( angle ) )
  37.                         .rotateY( - angle )
  38.                         .randomize( 1 / 2 ) );
  39.  
  40.             } )
  41.             .color( color )
  42.             .rotateZ( Math.PI / 4 )
  43.             .geometry();
  44.  
  45.         super( geometry, material );
  46.  
  47.         this.castShadow = true;
  48.         this.receiveShadow = true;
  49.  
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement