Error in ThreeJS: Unable to execute material.customProgramCacheKey

I encountered an issue

TypeError: material.customProgramCacheKey is not a function

The error pops up when I invoke the function this.animate(). However, no error occurs when the URL is empty. Where could this error be originating from since I don't utilize material or customProgramCacheKey.

Could it be due to the absence of material object? I even referred to the three.js documentation in search of a resolution but couldn't find one.

export class CanvasComponent implements OnInit, AfterViewInit {

  private loader: THREEFULL.OBJLoader;
  private scene : THREE.Scene = new THREE.Scene()
  private renderer: THREE.WebGLRenderer = new THREE.WebGLRenderer( {antialias: true})
  private width =  window.innerWidth/1.5
  private height = window.innerHeight/1.7
  private objects = [];
  private camera: THREE.Camera = null
  @ViewChild('canvas') canvas : ElementRef;
  object = localStorage.getItem('obj');
  mtl = localStorage.getItem('mtl');
  constructor() { }
  
  ngOnInit() {
    
   this.showObject(); 
       
    this.basic();
  }
  ngAfterViewInit() {
    this.canvas.nativeElement.appendChild(this.renderer.domElement)
    this.renderer.setSize(this.width,this.height)
    this.renderer.setClearColor(new THREE.Color(0xeeeeee))
  }
  showObject(){

    this.camera = new THREE.PerspectiveCamera(90,this.width/this.height, 1, 15000)
    this.camera.position.set(100,10,100)
    this.camera.lookAt(this.scene.position)

    let light = new THREE.PointLight()
    light.position.set(10000,10000,10000)
    this.scene.add(light)

    
    light = new THREE.PointLight(0xffffff, 0.8, 18);
    light.position.set(-3,6,-3);
    light.castShadow = true;
    light.shadow.camera.near = 0.1;
    light.shadow.camera.far = 25;
    this.scene.add(light);
    this.scene.add(new THREE.AxesHelper(5000))

    const byteNumbers = new Array(this.object.length);
      for (let i = 0; i < this.object.length; i++) {
       byteNumbers[i] = this.object.charCodeAt(i);
      }
      const byteArray = new Uint8Array(byteNumbers);
      const url = URL.createObjectURL(new Blob([byteArray], {type: 'model/obj'}));
    

    this.loader = new THREEFULL.OBJLoader()
    this.loader.load(url,obj=>{
      this.scene.add(obj);
      (obj as THREE.Group).children.forEach(o => this.objects.push(o));
    
     this.animate(obj,0.01) 
    })
  }
  private animate(obj: THREE.Object3D, angle:number) {
    obj.scale.x = 3
    obj.scale.y = 3
    obj.scale.z = 3
    obj.translateOnAxis(new THREE.Vector3(0,2,-10),0.2)

    this.render();
    requestAnimationFrame(() => this.animate(obj,angle))
  }
  private render() {
    this.renderer.render(this.scene, this.camera)
  }
}

Answer №1

personalized loader:THREEFULL.OBJLoader;

Avoid importing OBJLoader from external repositories. Instead, import it directly from the three npm package like you would the core library. The ES6 import statement should look something like this:

import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js';

//

this.loader = new OBJLoader();

If you are utilizing other classes from THREEFULL, follow the same import method described above.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unlock hidden Google secrets within your Angular application using Google Secret Manager

Can the Google Secret Manager API be accessed with a simple API call using an API key? https://secretmanager.googleapis.com/v1/projects/*/secrets/*?key=mykey returns a 401 unauthenticated error. While the Node.js server powering the Angular app uses the c ...

Oops! Property 'month' cannot be set on undefined value due to a TypeError

Despite not receiving any errors from Visual Studio Code, I’m encountering an error in Chrome's console. Below is the code snippet from my interfaces.ts file: export interface Data1{ month: string; employeeName: string; date: string; employmentSta ...

Jest's it.each method is throwing an error: "This expression is not callable. Type 'String' has no call signatures."

I've been attempting to utilize the describe.eachtable feature with TypeScript, but I keep running into an error message stating: "error TS2349: This expression is not callable. Type 'String' has no call signatures." Below is my code snippe ...

The power of Ionic 2 combined with the Web Audio API

I am currently developing an Ionic 2 application that requires access to the user's microphone. When working on a web platform, I would typically use the following code snippet to obtain microphone access. navigator.getUserMedia = (navigator['ge ...

Custom Type Guard Leads to Intersection Type Outcome

Recently, I've been experimenting with Typescript and decided to explore the creation of an innovative Either type that could distinguish between success and failure scenarios. Utilizing a user-defined type guard, I managed to precisely narrow down th ...

Tips for correctly decorating constructors in TypeScript

When a class is wrapped with a decorator, the superclasses lose access to that classes' properties. But why does this happen? I've got some code that demonstrates the issue: First, a decorator is created which replaces the constructor of a cla ...

Having trouble linking the date object with the default value of the date input field

Exploring how to set the default value of a date type input using property binding. Initially, I attempted to create a new date object in app.component.ts and then bind the [value] attribute of the date input to the currentDate property within app.compone ...

Ways to dynamically update button properties in Angular 2

Customized Template, <div *ngFor="let item of items" class = "col-sm-12 nopadding"> <a class="button buttonaquacss button-mini button-aqua text-right pull-right" [ngClass]="{activec: isActive}" (click)='updateStatus(item)& ...

Managing database downtime with TypeORM

In the event that my MSSQL server experiences a crash and an app client makes a request to the API, the current behavior is for it to endlessly spin until Express times out the unanswered request. By enabling logging in TypeORM, I am able to observe the e ...

Utilizing ngFor to iterate over items within an Observable array serving as unique identifiers

Just starting out with Angular and I'm really impressed with its power so far. I'm using the angularfire2 library to fetch two separate lists from firebase (*.ts): this.list1= this.db.list("list1").valueChanges(); this.list2= this.db.list("list2 ...

Can you explain the meaning of this TypeScript code snippet?

interface Configuration { [input: string]: any; } This is really puzzling to me, the 'input' is declared as a string type with any value? Appreciate your help. ...

What is the best way to transform HeadersInit into an Object<string,string> data type?

In short, I am faced with the task of converting the headers of a RequestInit into a format that another library can comprehend. This particular library requires the headers to be in the format of Object<string, string>. Initially, I attempted someth ...

Exploring the power of a mapped type within a tuple

Can TypeScript ensure the validity of key-value tuples in this function? function arrayToObject(array, mapper) { const result = {}; for(const item of array) { const [key, value] = mapper(item); result[key] = value; } return ...

Parsing values from deeply nested objects and arrays

I've come across this issue before, but I'm having difficulty navigating through a nested structure. I can't seem to find any guidance in the right direction. Here is the object I'm attempting to parse: const nestedArray = { id ...

Angular 2 decorators grant access to private class members

Take a look at this piece of code: export class Character { constructor(private id: number, private name: string) {} } @Component({ selector: 'my-app', template: '<h1>{{title}}</h1><h2>{{character.name}} detai ...

Transferring various sets of information into a single array

In an attempt to generate JSON data in an array for passing to another component, I followed a method outlined below. However, being relatively new to this field, my execution may not have been optimal as expected. employeeMoney: any[] = []; employeeId: an ...

Determining changes in an object with Angular 2 and Ionic 2

Q) How can I detect changes in an object with multiple properties bound to form fields without adding blur events to each individual field? I want to avoid cluttering the page with too many event listeners, especially since it's already heavy. For e ...

Having trouble showing the fa-folders icon in Vuetify?

Utilizing both Vuetify and font-awesome icons has been a successful combination for my project. However, I am facing an issue where the 'fa-folders' icon is not displaying as expected: In the .ts file: import { library } from '@fortawesome/ ...

Guide on automatically inserting a colon (:) after every pair of characters in Angular

I am looking to automatically insert a colon (:) after every 2 characters in my input field: HTML <input nz-input type="text" appLimitInput="textAndNumbers" name="mac" formControlName="mac" (keydown.space)=&qu ...

Exploring the potential of TypeScript with native dynamic ES2020 modules, all without the need for Node.js, while also enhancing

I have a TypeScript application that utilizes es16 modules, with most being statically imported. I am now looking to incorporate a (validator) module that is only imported in debug mode. Everything seems to be functioning properly, but I am struggling to f ...