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

Steps for creating a dynamic validation using a new form control

I have an item that needs to generate a form const textBox = { fontColor: 'blue', fontSize: '18', placeholder: 'email', name: 'input email', label: 'john', validation: { required: false } ...

Why won't T.chain chain properly in Effect-ts?

I have a simple program that I've been working on: import * as T from "@effect-ts/core/Effect"; import { pipe } from "@effect-ts/core/Function"; import { tag } from "@effect-ts/core/Has"; interface ConsoleModule { log: ...

Creating a consolidated System.config mapping for @angular modules using a single .js file

Currently in the process of developing an Angular 2 application, with the specific requirement to consolidate all resulting Javascript files into a single .js file called output.js. Now, the challenge is to incorporate map configuration within System.conf ...

The data set in a setTimeout is not causing the Angular4 view to update as expected

I am currently working on updating a progress bar while importing data. To achieve this, I have implemented a delay of one second for each record during the import process. Although this may not be the most efficient method, it serves its purpose since thi ...

An issue occurred while compiling the 'ToastContainer' template. Decorators do not support function calls, and the call to 'trigger' caused an error

When I run ng serve and ng build, there are no errors. However, when I run ng build --prod, I encounter this error. Can anyone help me fix it? ERROR in Error during template compile of 'ToastContainer' Function calls are not supported in decor ...

Transform a row in an ng Smart table to a routerlink using Angular 2

I've been exploring ng2 Smart Table and I'm looking to convert a row (or even cell data) into a clickable link using routerlink. The current method I'm employing to retrieve some of my row's data is as follows: onUserRowSelect(event) ...

Having trouble with Angular 2 not properly sending POST requests?

Having some trouble with a POST request using Angular 2 HTTP? Check out the code snippet below: import { Injectable } from '@angular/core'; import { Http, Response, Headers, RequestOptions } from '@angular/http'; import 'rxjs/add ...

Utilize Three.js to project an object onto a designated distance

I am working with a rectangle defined by 4 points and I need to move it to the left or right by a specific distance. The result should be a parallel rectangle that, when lines are drawn through corresponding points, forms a rectangular cuboid. I have the ...

Restricting a checkbox to a maximum of 5 checkmarks

In a multi-column table, each column is represented by a checkmark. I want to limit the ability to tick a checkmark to only 5 checkmarks. Here is the code that has been implemented: <tbody> <ng-container *ngFor="let col of testData" ...

What is the purpose of the 'unique' keyword in TypeScript?

While coding in the TypeScript playground, I stumbled upon a situation where the term unique seems to be reserved. However, I haven't been able to find any official documentation regarding this. https://i.stack.imgur.com/eQq5b.png Does anyone know i ...

All constructors at the base level must share a common return type

I am looking to convert my JSX code to TSX. I have a snippet that refactors a method from the react-bootstrap library: import {Panel} from 'react-bootstrap'; class CustomPanel extends Panel { constructor(props, context) { super(props ...

Limit the range of potential inputs for the function parameter

class Coordinate { constructor(readonly x: number, readonly y: number) {} } const Up = new Coordinate(0, -1); const Right = new Coordinate(1, 0); const Down = new Coordinate(0, 1); const Left = new Coordinate(-1, 0); // How can we restrict the directio ...

Issue accessing member value in inherited class constructor in Typescript

My situation involves a class named A, with another class named B that is inherited from it. class A { constructor(){ this.init(); } init(){} } class B extends A { private myMember = {value:1}; constructor(){ super(); ...

The alpha value is not functioning correctly in the fragment shader with gl_FragColor

Currently in my Three.js project, I am utilizing a ShaderMaterial to render Points Geometry with a Fragment Shader. My goal is to give each point a blurred edge, but I am facing an issue with the alpha channel as it just turns white instead. I tried disc ...

Tips for managing numerous nested subscriptions

Looking to extract the id parameter from the route, fetch the corresponding task, and then its parent if applicable. Angular CLI: 7.1.4 Node: 11.6.0 OS: linux x64 Angular: 7.1.4 @angular-devkit/architect 0.11.4 @angula ...

Is there a source where I can locate type definitions for Promise objects?

In the process of creating a straightforward class called Primrose, I am extending the global Promise object in order to include additional methods like resolve and reject. export class Primrose<Resolution> extends Promise<Resolution>{ priv ...

Employing an unchanging Map format for observation

I'm currently working on implementing a synchronization mechanism using observable and Map structures from Immutable.js. However, I'm encountering an issue where the Map is unable to function as an observable or perhaps I might be approaching it ...

React component's state is not being correctly refreshed on key events

Currently facing an issue that's puzzling me. While creating a Wordle replica, I've noticed that the state updates correctly on some occasions but not on others. I'm struggling to pinpoint the exact reason behind this discrepancy. Included ...

Guidelines on encoding query parameters for a tRPC query with the fetch function

As stated in the tRPCs official documentation, the query parameters must adhere to this specific format: myQuery?input=${encodeURIComponent(JSON.stringify(input))} Here is an example of a procedure: hello: publicProcedure .input(z.object({ text: z.s ...

Error: When trying to run the `ng build` command in Git Bash, TypeScript module cannot be

When attempting to execute ng build using Git Bash, I encountered this error message, even though I had previously executed npm install -g typescript. Where should I place the typescript installation so that Git can detect it? Error $ npm install -g typ ...