代码之家  ›  专栏  ›  技术社区  ›  blue

无法更改材质的纹理-SparkAR v89?

  •  0
  • blue  · 技术社区  · 6 年前

    在SparkAR v89和以前的版本中,使用脚本以编程方式更改材质的纹理,这将起到以下作用:

    const Materials = require('Materials');
    const Textures = require('Textures');
    
    Promise.all([
    
        Scene.root.findFirst('plane4'),
    
    ]).then(function (results) {
    
        const plane4 = results[0];
    
        const ipadPerfect = Scene.root.findFirst('ipad-perfect');
        const iphonePerfect = Scene.root.findFirst('iphone-perfect');
        const computerPerfect = Scene.root.findFirst('computer-perfect');
    
        // Get the timer ready
        start();
    
        function start() {
    
          const bgMat = Materials.findFirst('bg');
          const mutableScreen = Materials.findFirst('mutablescreen');
    
          var texture = Textures.findFirst('unnamed-min');
    
          bgMat.diffuse = texture;
          bgMat.emission = texture;
          mutableScreen.diffuse = texture;
          mutableScreen.emission = texture;
    

    甚至换了findFirst和 get findAll ,这不会产生任何结果。现在如何更改材质的纹理?

    0 回复  |  直到 6 年前
        1
  •  1
  •   Igor Zhurba    6 年前

    请求纹理、材质和场景对象需要一些时间。从v85版本开始,对于这些事情,您需要使用如下方法 findFirst Promise.All 块只需将对纹理和材质的请求转移到您请求的同一块 plane4

    const Materials = require('Materials');
    const Textures = require('Textures');
    const Scene = require('Scene');
    
    Promise.all([
    
        Scene.root.findFirst('plane4'),
        Scene.root.findFirst('ipad-perfect'),
        Scene.root.findFirst('iphone-perfect'),
        Scene.root.findFirst('computer-perfect'),
        Materials.findFirst('bg'),
        Materials.findFirst('mutablescreen'),
        Textures.findFirst('unnamed-min')
    
    
    ]).then(function (results) {
    
        const plane4 = results[0];
    
        const ipadPerfect = results[1];
        const iphonePerfect = results[2];
        const computerPerfect = results[3];
        const bgMat = results[4];
        const mutableScreen = results[5];
        const texture = results [6];
    
        // Get the timer ready
        start();
    
        function start() {
    
    
          bgMat.diffuse = texture;
          bgMat.emission = texture;
          mutableScreen.diffuse = texture;
          mutableScreen.emission = texture;