Hi ,
I am Bhanu, I have issue importing a .OBJ file into Angular 8 Project . The Normal Babylon js works but importing
`import ‘babylonjs-loaders’ is causing some issues
Can some one provide an example to Import and OBJ file to Angular 8 application
I have tried using the following code
import { Component, OnInit } from '@angular/core';
//import * as babylon from 'babylonjs';
//import { Scene, Engine } from 'babylonjs';
import * as BABYLON from 'babylonjs';
//import '../../assets/js/babylon.loader.js'
//import '../../assets/js/babylon.js'
//import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader";
//import 'babylonjs-loaders';
//import { GLTFLoader} from "@babylonjs/loaders/glTF";
//import "@babylonjs/loaders/OBJ";
//
@Component({
selector: 'app-babylon',
templateUrl: './babylon.component.html',
styleUrls: ['./babylon.component.scss']
})
export class BabylonComponent implements OnInit {
y: number = 1;
lightX: number = 0;
red: number = 0.7;
canvas: any;
engine: any;
world: any;
sphere: any;
skybox: any;
ngOnInit() {
this.canvas = document.getElementById('renderCanvas');
this.engine = new BABYLON.Engine(this.canvas, true, { preserveDrawingBuffer: true, stencil: true });
var createScene = function () {
var scene = new BABYLON.Scene(this.engine);
var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5, -10), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.attachControl(this.canvas, false);
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(this.lightX, 1, 0), scene);
/* this.skybox = BABYLON.Mesh.CreateBox('skyBox', 100, scene, true);
var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
skyboxMaterial.backFaceCulling = false;
skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("https://www.tonytextures.com/free-texture-gallery/sky/Sky_Clouds_Photo_Texture_A_P4192452", scene);
skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
this.skybox.material = skyboxMaterial;*/
this.sphere = BABYLON.Mesh.CreateSphere('sphere1', 16, 2, scene, false, BABYLON.Mesh.FRONTSIDE);
var myMaterial = new BABYLON.StandardMaterial("blue", scene);
myMaterial.diffuseColor = new BABYLON.Color3(.5, 0, 1);
myMaterial.specularColor = new BABYLON.Color3(this.red, 0.6, 0.87);
this.sphere.material = myMaterial;
this.sphere.position.y = this.y;
//-----------------------------------------------------------
//Added box for testing
/*var myBox = BABYLON.MeshBuilder.CreateBox("myBox", {height: 5, width: 2, depth: 0.5}, scene);
var myMaterial = new BABYLON.StandardMaterial("blue", scene);
myMaterial.diffuseColor = new BABYLON.Color3(.5, 0, 1);
myMaterial.specularColor = new BABYLON.Color3(this.red, 0.6, 0.87);
myBox.material = myMaterial;
myBox.position.y = 3;*/
//Here try to import 3d model
BABYLON.SceneLoader.ImportMesh(
"",
"https://models.babylonjs.com/Marble/marble/",
"marble.gltf",
this.scene,
function(m) {
console.log(m);
}
);
/* var loader = new BABYLON.AssetsManager(scene);
var pile = loader.addMeshTask("pile", "", "http://development.stockpilereports.com:3000/public/assets/", "1.obj");
*/
//this.
BABYLON.SceneLoader.ImportMesh(
'',
'http://development.stockpilereports.com:3000/public/assets/',
'1.obj',
scene,
(meshes)=> {
console.log(meshes)
}
);
//-----------------------------------------------------------------
var ground = BABYLON.Mesh.CreateGround('ground1', 6, 6, 2, scene, false);
var myMaterial = new BABYLON.StandardMaterial("green", scene);
myMaterial.diffuseColor = new BABYLON.Color3(0, .8, 0);
myMaterial.specularColor = new BABYLON.Color3(0.7, 0.6, 0.87);
ground.material = myMaterial;
// Return the created scene
return scene;
}.bind(this);
var scene = createScene();
this.world = scene;
// run the render loop
this.engine.runRenderLoop(function () {
scene.render();
});
window.addEventListener('resize', function () {
scene.resize();
});
}
}
//// ENd of Code
This is my console.