createcamera() {
this.scene.createDefaultCamera(true, true, true);
this.camera = new ArcRotateCamera("Camera", this.modalpaperInfo.model_alpha, this.modalpaperInfo.model_beta, this.modalpaperInfo.model_radius, new Vector3(0, 0, 0), this.scene);
// this.camera.setPosition(new Vector3(200, 200, 150));
this.camera.setTarget(Vector3.Zero());
this.camera.attachControl(this.threedpreview.nativeElement, true)
}
SceneEnvironment(){
if(this.modalpaperInfo.evntexture === undefined){
this.evntexture = environment[global.env].RESOURCE_URL_AMAZON + environment[global.env].RESOURCE_CONTAINER + environment[global.env].oemCode + "/preview/" + "env-default.env";
console.log(this.evntexture)
}else{
this.evntexture = environment[global.env].RESOURCE_URL_AMAZON + environment[global.env].RESOURCE_CONTAINER + environment[global.env].oemCode + "/preview/" + this.modalpaperInfo.evntexture;
}
const envTexture = CubeTexture.CreateFromPrefilteredData(
// "./assets/environment/studio.env"
this.evntexture
,this.scene)
this.scene.environmentTexture = envTexture;
this.scene.environmentIntensity = 0.7;
var blur = 0.6;
this.skybox = this.scene.createDefaultSkybox(envTexture, true, 10000, blur, true);
}
CreateScene(scene: Scene, canvas: HTMLCanvasElement) {
this.createcamera();
this.light = new HemisphericLight(“light”, new Vector3(0, -1, 0), scene);
this.light.intensity = 0.7;
this.SceneEnvironment();
// scene.registerBeforeRender(function () {
// // myskybox.rotation._y = 44;
// // myskybox.rotation._x = 55;
// // myskybox.rotation._z = 5;
// });
this.modelLoad()
scene.clearCachedVertexData();
scene.cleanCachedTextureBuffer();
return scene;
}
startTime = performance.now();
async modelLoad() {
var self = this;
self.meshUrl = this.productDetail.productCode + ".glb"
self.modalPath = environment[global.env].RESOURCE_URL_AMAZON + environment[global.env].RESOURCE_CONTAINER + environment[global.env].oemCode + "/preview/" + this.productDetail.productCode + '.glb';
self.bumptexure = environment[global.env].RESOURCE_URL_AMAZON + environment[global.env].RESOURCE_CONTAINER + environment[global.env].oemCode + "/preview/" + this.modalpaperInfo.bumptexture;
console.log(self.bumptexure);
console.log(this.modalPath);
SceneLoader.ImportMesh("",
// "./assets/models/",
self.modalPath,
"",
this.scene, async (frame, particleSystems, skeletons, animationGroups) => {
this.meshes = frame;
this.animationgroups = animationGroups;
this.ifcardanimatedproduct = this.handleCardAnimatedProduct(this.animationgroups);
this.ifanimatedproduct = this.handleAnimatedProduct(this.animationgroups);
this.scene.createDefaultCamera(true, true, true);
await this.updateMaskedArea(0, true);
if (this.selectedPaper) {
this.showPaperColorOption(this.selectedPaper);
}
this.setcameraposition();
this.engine.hideLoadingUI();
});
const endTime = performance.now();
const loadTime = endTime - this.startTime;
// // Output the load time to the console
console.log('Model load time: ' + loadTime + ' milliseconds');
setTimeout(() => {
this.cdr.detectChanges();
}, 1);
}
scrclick() {
var self = this;
let promise = new Promise(function (resolve, reject) {
const originalEnvironmentTexture = self.scene.environmentTexture;
const originalClearColor = self.scene.clearColor.clone();
self.skybox.dispose();
self.scene.clearColor = new Color4(0, 0, 0, 0);
function customCamera() {
self.setcameraposition();
return self.camera;
}
Tools.CreateScreenshotUsingRenderTarget(self.engine, customCamera(), { width: 3840, height: 3840 }, (data) => {
const img = document.createElement("img");
img.src = data;
console.log(img.src);
// document.body.appendChild(img);
// self.scene.environmentTexture = originalEnvironmentTexture;
// self.scene.clearColor = originalClearColor;
// const envTexture = CubeTexture.CreateFromPrefilteredData(self.evntexture, self.scene)
// self.scene.environmentTexture = envTexture;
// self.scene.environmentIntensity = 1;
// var blur = 0.8;
// self.scene.createDefaultSkybox(envTexture, true, 10000, blur, true);
// const metal = new PBRMaterial("metal", self.scene);
// metal.reflectionTexture = originalEnvironmentTexture;
// metal.microSurface = 0.96;
// metal.reflectivityColor = new Color3(0.81, 0.81, 0.8,);
// metal.albedoColor = new Color3(0.01, 0.01, 0.01);
// self.meshes[0].material = metal;
resolve(data);
});
self.scene.clearColor = originalClearColor;
self.SceneEnvironment();
// self.setcameraposition();
});
return promise;
} setcameraposition = function () {
this.camera = this.scene.cameras.pop();
this.scene.cameras.push(this.camera);
this.camera.inputs.attached.keyboard.angularSpeed = .002;
this.camera.inputs.attached.pointers.panningSensibility = 10000;
this.camera.inputs.attached.mousewheel.wheelPrecisionY = 100;
this.camera.panningSensibility = 10000;
this.camera.pinchDeltaPercentage = 0.003;
console.log(this.modalpaperInfo.isAutorotate != undefined);
if (this.modalpaperInfo.isAutorotate != undefined) {
this.ischecked = true;
this.autoRotationBehavior = this.modalpaperInfo.isAutorotate;
this.speed = this.modalpaperInfo.speed;
this.camera.useAutoRotationBehavior = this.autoRotationBehavior;
this.camera.autoRotationBehavior.idleRotationSpeed = 0.2;
} else {
this.camera.useAutoRotationBehavior = this.autoRotationBehavior;
}
//console.log(this.autoRotationBehavior);
//console.log(this.speed);
this.camera.alpha = this.modalpaperInfo.model_alpha;
this.camera.beta = this.modalpaperInfo.model_beta;
this.camera.radius = this.modalpaperInfo.model_radius;
// this.meshes[0].position.y = -0.30;
const meshpostionVector = this.modalpaperInfo.vector3;
const [x, y, z] = meshpostionVector.split(",")
this.meshes[0].position = new Vector3(x, y, z);
console.log(this.meshes[0].position);
setTimeout(() => {
this.cdr.detectChanges();
}, 1); that is code