Guest User

Untitled

a guest
Dec 4th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <reference path="typings/ue.d.ts">/>
  2.  
  3. (function (global) {    
  4.     "use strict"
  5.     const THREE = require( 'three' );
  6.  
  7.     function threeVertexToUEVertex( v ){
  8.         return {
  9.             X: v.x,
  10.             Y: v.y,
  11.             Z: v.z
  12.         };
  13.     }
  14.  
  15.     class ProceduralJSMesh extends Blueprint.Load('/Game/ProceduralBox').GeneratedClass {
  16.         ctor() {
  17.             // Subobject initialization, property initialization
  18.             this.bAlwaysRelevant = true
  19.             console.log( 'constructing procedural js mesh' );
  20.         }
  21.        
  22.         ReceiveBeginPlay() {                                                                
  23.          
  24.             const geo = new THREE.TorusKnotGeometry(200, 40, 128, 24, 2, 3, 1);
  25.  
  26.             this.vertices = geo.vertices.map( function( vertex ){
  27.                 return threeVertexToUEVertex( vertex );
  28.             });
  29.  
  30.             this.triangles = geo.faces.reduce( function( arr, f ){
  31.                 arr.push( f.c );
  32.                 arr.push( f.b );
  33.                 arr.push( f.a );                              
  34.                 return arr;
  35.             }, [] );
  36.            
  37.             this.normals = geo.faces.reduce( function( arr, f ){                    
  38.                 arr.push( threeVertexToUEVertex( f.vertexNormals[ 0 ] ) );
  39.                 arr.push( threeVertexToUEVertex( f.vertexNormals[ 1 ] ) );
  40.                 arr.push( threeVertexToUEVertex( f.vertexNormals[ 2 ] ) );                    
  41.                 return arr;
  42.             }, [] );
  43.  
  44.             this.uvs = geo.faceVertexUvs[ 0 ].reduce( function( arr, uvs ){
  45.                 uvs.forEach( function( vertex ){
  46.                     arr.push( {
  47.                         X: vertex.x,
  48.                         Y: vertex.y
  49.                     } );
  50.                 });
  51.                 return arr;
  52.             }, [] );
  53.        
  54.             super.ReceiveBeginPlay();
  55.                                                          
  56.         }
  57.     }
  58.        
  59.     let MyActor_C = require('uclass')()(global,ProceduralJSMesh)
  60.    
  61.     let _ = require('lodash')    
  62.  
  63.     function GetPC() {
  64.         return GWorld.GetAllActorsOfClass(PlayerController).OutActors[0]
  65.     }
  66.    
  67.     function main() {
  68.         if (GWorld.IsServer()) {
  69.             let actor = new MyActor_C(GWorld,{X:1})                    
  70.            
  71.             return function () {
  72.                 actor.DestroyActor()
  73.             }
  74.         } else {
  75.             return function() {}
  76.         }                
  77.     }
  78.      
  79.     try {
  80.         module.exports = () => {
  81.             let cleanup = null
  82.             process.nextTick(() => cleanup = main());
  83.             return () => cleanup()
  84.         }
  85.     }
  86.     catch (e) {
  87.         require('bootstrap')('generate')
  88.     }
  89. })(this)
Advertisement
Add Comment
Please, Sign In to add comment