Webkit 3D 透视错误

发布于 2024-12-27 06:17:22 字数 3428 浏览 0 评论 0原文

我最近在玩浏览器,现在我正在与 3D 战斗。 WebGL 太棒了,我也可以用 CSS3 做 3D 吗?甚至更好!好的,所以我的愿景是使用嵌套变换(使用 keep-3d)创建浮动 3D 对象。

HTML

<div class="scene">
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
</div>

CSS(我使用的是 prefixfree)

.scene {
    perspective: 3500;
    perspective-origin: 25% 100%;
    animation: spin 15s infinite linear;
    transform-style: preserve-3d;
    width: 960px;
    height: 350px;
    margin: 80px auto;
}

.box {
    width: 150px;
    height: 180px; 
    position: absolute;
    transform-style: preserve-3d;  
    top: 40px;  
}
.box div {
    width: 150px;
    height: 180px;
    opacity: 0.75;
    background-color: #bada55;
    position: absolute;    
}
.box .side_1   { 
    transform: rotateY(   0deg ) translateZ( 75px );     
    background-color: #FF0;
}
.box .side_2   { 
    transform: rotateX( 180deg ) translateZ( 75px ); 
    background-color: #F00;
}
.box .side_3   { 
    transform: rotateY(  90deg ) translateZ( 75px );    
    background-color: #CCC; }
.box .side_4   {
    transform: rotateY( -90deg ) translateZ( 75px ); 
    background-color: #000;
}
.box .side_5   { 
    height: 150px;
    width: 150px;
    background-color: #00a2ff;
    transform: rotateX(  90deg ) translateZ( 75px ); }
.box .side_6   { 
    height: 150px;
    background-color: #00a2ff;
    width: 150px;
    transform: rotateX( -90deg ) translateZ( 105px ); }
.box:first-child {
    position: absolute;
    top: 40px;
}
.box:last-child {
    right: 0;
}
.box:nth-child(2) {
    background: url(../img/dot.jpg) repeat-y center center transparent;
    transform: translateZ( -600px );
    left: 480px;
}
.box:nth-child(3) {
    background: url(../img/dot.jpg) repeat-y center center transparent;
    transform: translateZ( 600px );
    left: 480px;
}

@keyframes spin {
    0%   { transform: rotateY(0); }    
    100%   { transform: rotateY(360deg); }
}

一切都已设置完毕,并且可以正常工作。但是等等,发生了什么事?为什么远处的物体比近处的物体大?我不明白。是 webkit bug 还是我遗漏了什么?

http://stretchbox.org/projects/Nextgen/floaters.php - 这里你有一个例子。

I'm playing around with browsers lately, and now I'm fighting with 3D. WebGL is awesome, and I can do 3D in CSS3 too? Even better! Ok, so my vision was to create floating 3D objects using nested transformations (with preserve-3d).

HTML

<div class="scene">
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
    <div class="box">
        <div class="side_1"></div>
        <div class="side_2"></div>
        <div class="side_3"></div>
        <div class="side_4"></div>
        <div class="side_5"></div>
        <div class="side_6"></div>
    </div>
</div>

CSS (I'm using prefixfree)

.scene {
    perspective: 3500;
    perspective-origin: 25% 100%;
    animation: spin 15s infinite linear;
    transform-style: preserve-3d;
    width: 960px;
    height: 350px;
    margin: 80px auto;
}

.box {
    width: 150px;
    height: 180px; 
    position: absolute;
    transform-style: preserve-3d;  
    top: 40px;  
}
.box div {
    width: 150px;
    height: 180px;
    opacity: 0.75;
    background-color: #bada55;
    position: absolute;    
}
.box .side_1   { 
    transform: rotateY(   0deg ) translateZ( 75px );     
    background-color: #FF0;
}
.box .side_2   { 
    transform: rotateX( 180deg ) translateZ( 75px ); 
    background-color: #F00;
}
.box .side_3   { 
    transform: rotateY(  90deg ) translateZ( 75px );    
    background-color: #CCC; }
.box .side_4   {
    transform: rotateY( -90deg ) translateZ( 75px ); 
    background-color: #000;
}
.box .side_5   { 
    height: 150px;
    width: 150px;
    background-color: #00a2ff;
    transform: rotateX(  90deg ) translateZ( 75px ); }
.box .side_6   { 
    height: 150px;
    background-color: #00a2ff;
    width: 150px;
    transform: rotateX( -90deg ) translateZ( 105px ); }
.box:first-child {
    position: absolute;
    top: 40px;
}
.box:last-child {
    right: 0;
}
.box:nth-child(2) {
    background: url(../img/dot.jpg) repeat-y center center transparent;
    transform: translateZ( -600px );
    left: 480px;
}
.box:nth-child(3) {
    background: url(../img/dot.jpg) repeat-y center center transparent;
    transform: translateZ( 600px );
    left: 480px;
}

@keyframes spin {
    0%   { transform: rotateY(0); }    
    100%   { transform: rotateY(360deg); }
}

Everything is set up, and works. But wait, what is happening? Why does the far object is bigger than close one? I don't understand. Is it webkit bug, or I'm missing something?

http://stretchbox.org/projects/Nextgen/floaters.php - here you have an example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2025-01-03 06:17:22

.scene 也在旋转,因此您需要将透视图和透视图原点应用到其父级(在您的情况下将是主体)。

body {
    perspective: 3500;
    perspective-origin: 25% 100%;
} 

您可以在此处查看演示:

http://jsfiddle.net/dw58P/embedded/result/

顺便说一句,不错的项目!

.scene is also rotating, so you need to apply the perspective and perspective-origin on its parent, which in your case would be body.

body {
    perspective: 3500;
    perspective-origin: 25% 100%;
} 

You can see a demo here:

http://jsfiddle.net/dw58P/embedded/result/

Nice project by the way!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文