Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an example for inclusion in an Angular Project #326

Open
2 of 6 tasks
meronbrouwer opened this issue Sep 28, 2017 · 12 comments
Open
2 of 6 tasks

Provide an example for inclusion in an Angular Project #326

meronbrouwer opened this issue Sep 28, 2017 · 12 comments

Comments

@meronbrouwer
Copy link

Describe your issue here.

Version:
  • v2.x.x
  • v1.x.x
Issue type:
  • Bug
  • Proposal/Enhancement
  • Question
  • Discussion

The examples could use one that shows a Hello World as an Angular component. This will require the typings to be (mostly) finished.
@looading
Copy link

looading commented Sep 28, 2017

You can use whs directly in Angular.
Here is a shabby example.

// container.component.ts
import { Component, ComponentRef, ElementRef, OnInit, Input, OnChanges } from '@angular/core';
import * as THREE from 'three';
import {
  CameraComponentParams,
  App } from 'whs';

import * as WHS from 'whs/build/whs';

@Component({
  selector: 'whs-container',
  templateUrl: './container.component.html',
  styleUrls: ['./container.component.scss']
})
export class ContainerComponent implements OnInit, OnChanges {
  private _container: App;

  @Input() public camera: CameraComponentParams = {
    position: {
      y: 10,
      z: 50
    },
  };

  @Input() public rendering = {
    bgColor: 0x162129,
    renderer: {
      antialias: true,
      shadowmap: {
        type: THREE.PCFSoftShadowMap,
      },
    }
  };

  constructor(private element: ElementRef) {}

  private createContainer() {
    this._container = new App([
      new WHS.ElementModule(this.element.nativeElement),
      new WHS.SceneModule(),
      new WHS.CameraModule({
        position: {
          y: 10,
          z: 50
        }
      }),
      new WHS.RenderingModule(this.rendering, {shadow: true}),
      new WHS.OrbitControlsModule(),
      new WHS.ResizeModule()
    ]);
  }

  public build() {
    // Sphere
    const sphere = new WHS.Sphere({ // Create sphere comonent.
      geometry: {
        radius: 5,
        widthSegments: 32,
        heightSegments: 32
      },

      material: new THREE.MeshPhongMaterial({
        color: 0xF2F2F2
      }),

      position: new THREE.Vector3(0, 5, 0)
    });
    sphere.addTo(this._container);
    // Plane
    new WHS.Plane({
      geometry: {
        width: 100,
        height: 100
      },

      material: new THREE.MeshPhongMaterial({color: 0x447F8B}),

      rotation: {
        x: -Math.PI / 2
      }
    }).addTo(this._container);
    // Lights
    new WHS.PointLight({
      light: {
        intensity: 0.5,
        distance: 100
      },

      shadow: {
        fov: 90
      },

      position: new THREE.Vector3(0, 10, 10)
    }).addTo(this._container);

    new WHS.AmbientLight({
      light: {
        intensity: 0.4
      }
    }).addTo(this._container);

    // Start the app
    this._container.start();
  }

  ngOnInit() {
    console.log(this.element.nativeElement.querySelector('.world'));
    this.createContainer();
    this.build();
  }

  ngOnChanges() {
  }
}
<!--  app.component.html -->
<whs-container></whs-container>

It`s available.
image

The above code is not clean.In [email protected], there are some different api between typescript version of whs and javascript version of whs .

Hirako says: Sorry about that. If you raise an issue with the APIs not matching, I will make sure to fix the types definitions to match APIs.

At last, there wil be some examples about Angular in ng-whs

@meronbrouwer
Copy link
Author

Sorry for the thumbs down.... meant to only select the thumbs up...

@looading
Copy link

@meronbrouwer It dosn`t matter.

In fact, I don`t recommend the above method. In project ng-whs, I will take another more appropriate method.However, it will take some time to complete.

@meronbrouwer
Copy link
Author

@looading Thanks. I'll have a look at that project. Btw, note that is seems the convention to give Angular2+ projects an ngx prefix, so it would be ngx-whs.

@looading
Copy link

@meronbrouwer Yes, your are right. I will rename ng-whs to ngx-whs.

@meronbrouwer
Copy link
Author

@looading In your example, you use the CameraModule, did you create the typings for those yourself? They are missing in 2.1.8

@looading
Copy link

@meronbrouwer I mentioned this before.
In [email protected], there are some different api between typescript version of whs and javascript version of whs .
I didn`t create the typing for CameraModule. I use the CameraModule directly the impact of typescript.

import * as WHS from 'whs/build/whs';  // .js file umd

@hirako2000
Copy link
Collaborator

hirako2000 commented Sep 29, 2017

Please raise an Issue for any whs type definition that diverge from the whs API (matching version of course).
Those should be addressed, I just never had time to look back and exercise every single component interfaces in typescript. Just did a few.

About the oddity of types looking like they are not present, in say whs 2.1.8, you could also raise an issue with more details as to what's going on. I never had this issue, at least never had that issue with the typescript boilerplate app we published as an example of project using whs/three.js with TS.

@hirako2000
Copy link
Collaborator

Let's relate the whs modules interface struggle to #298

@sasha240100
Copy link
Member

@looading What's the state of the project?

@looading
Copy link

looading commented Mar 6, 2018

@sasha240100
Sorry, the project on hold for such a long time.I've been very busy this period of time.
A part of the unfinished:

  • Some examples of pending
  • To improve performance

@sasha240100
Copy link
Member

sasha240100 commented Mar 10, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants