SCNMaterialProperty.contents
的文檔聲明它是一個動畫屬性,實際上我可以在兩種顏色之間執行交叉淡入淡出。不過,我無法在兩張圖像之間交叉淡入淡出。SceneKit - 交叉淡化材質屬性紋理
所以我開始懷疑這是否可能,或者如果我需要爲此創建自定義着色器?
我試過一個隱含的動畫,在這種情況下,它會立即顯示 '後' 的形象:
node.geometry.firstMaterial.diffuse.contents = [UIImage imageNamed:@"before"];
[SCNTransaction begin];
[SCNTransaction setAnimationDuration:5];
node.geometry.firstMaterial.diffuse.contents = [UIImage imageNamed:@"after"];
[SCNTransaction commit];
一個明確的動畫,它什麼都不做:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"contents"];
animation.fromValue = (__bridge id)[UIImage imageNamed:@"before"].CGImage;
animation.toValue = (__bridge id)[UIImage imageNamed:@"after"].CGImage;
animation.duration = 5;
[node.geometry.firstMaterial.diffuse addAnimation:animation forKey:nil];
以及通過CALayer
,它什麼都不做:
CALayer *textureLayer = [CALayer layer];
textureLayer.frame = CGRectMake(0, 0, 793, 1006);
textureLayer.contents = (__bridge id)[UIImage imageNamed:@"before"].CGImage;
node.geometry.firstMaterial.diffuse.contents = textureLayer;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"contents"];
animation.fromValue = (__bridge id)[UIImage imageNamed:@"before"].CGImage;
animation.toValue = (__bridge id)[UIImage imageNamed:@"after"].CGImage;
animation.duration = 5;
[textureLayer addAnimation:animation forKey:nil];
您是否嘗試過在兩種材質之間改變動畫,而不是在相同材質屬性的兩個內容值之間進行更改? – rickster