Skip to content

Commit f089f3e

Browse files
authored
Merge pull request #402 from limzykenneth/main
Add missing translation
2 parents bdb74c9 + 8c3ce15 commit f089f3e

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
---
2+
title: texture
3+
module: 3D
4+
submodule: 材质
5+
file: src/webgl/material.js
6+
description: >
7+
<p>设置将用于形状的纹理。</p>
8+
9+
<p>纹理就像是包裹在形状周围的皮肤。<code>texture()</code> 函数可用于内置的形状,例如 <a href="/reference/p5/square">square()</a> 和 <a href="/reference/p5/sphere">sphere()</a>,以及使用 <a href="/reference/p5/buildGeometry">buildGeometry()</a> 等函数创建的自定义形状。要对使用 <a href="/reference/p5/beginShape">beginShape()</a> 创建的几何体进行纹理化,必须为每个 <a href="/reference/p5/vertex">vertex()</a> 调用传递 uv 坐标。</p>
10+
11+
<p>参数 <code>tex</code> 是要应用的纹理。<code>texture()</code> 可以使用包括图像、视频和离屏渲染器等来源,例如 <a href="/reference/p5/p5.Graphics">p5.Graphics</a> 和 <a href="/reference/p5/p5.Framebuffer">p5.Framebuffer</a> 对象。</p>
12+
13+
<p>要对使用 <a href="/reference/p5/beginShape">beginShape()</a> 创建的几何体进行纹理化,你需要在 <a href="/reference/p5/vertex">vertex()</a> 中指定 uv 坐标。</p>
14+
15+
<p>注意:<code>texture()</code> 只能在 WebGL 模式下使用。</p>
16+
line: 861
17+
isConstructor: false
18+
itemtype: method
19+
example:
20+
- |-
21+
22+
<div>
23+
<code>
24+
let img;
25+
26+
// 加载一张图片并创建一个 p5.Image 对象。
27+
function preload() {
28+
img = loadImage('/assets/laDefense.jpg');
29+
}
30+
31+
function setup() {
32+
createCanvas(100, 100, WEBGL);
33+
34+
describe('A spinning cube with an image of a ceiling on each face.');
35+
}
36+
37+
function draw() {
38+
background(0);
39+
40+
// 绕 x 轴、y 轴和 z 轴旋转。
41+
rotateZ(frameCount * 0.01);
42+
rotateX(frameCount * 0.01);
43+
rotateY(frameCount * 0.01);
44+
45+
// 将图片应用为纹理。
46+
texture(img);
47+
48+
// 绘制立方体。
49+
box(50);
50+
}
51+
</code>
52+
</div>
53+
54+
<div>
55+
<code>
56+
let pg;
57+
58+
function setup() {
59+
createCanvas(100, 100, WEBGL);
60+
61+
// 创建一个 p5.Graphics 对象。
62+
pg = createGraphics(100, 100);
63+
64+
// 在 p5.Graphics 对象上绘制一个圆形。
65+
pg.background(200);
66+
pg.circle(50, 50, 30);
67+
68+
describe('A spinning cube with circle at the center of each face.');
69+
}
70+
71+
function draw() {
72+
background(0);
73+
74+
// 绕 x 轴、y 轴和 z 轴旋转。
75+
rotateZ(frameCount * 0.01);
76+
rotateX(frameCount * 0.01);
77+
rotateY(frameCount * 0.01);
78+
79+
// 将 p5.Graphics 对象应用为纹理。
80+
texture(pg);
81+
82+
// 绘制立方体。
83+
box(50);
84+
}
85+
</code>
86+
</div>
87+
88+
<div>
89+
<code>
90+
let vid;
91+
92+
// 加载一个视频并创建一个 p5.MediaElement 对象。
93+
function preload() {
94+
vid = createVideo('/assets/fingers.mov');
95+
}
96+
97+
function setup() {
98+
createCanvas(100, 100, WEBGL);
99+
100+
// 隐藏视频。
101+
vid.hide();
102+
103+
// 设置视频循环播放。
104+
vid.loop();
105+
106+
describe('A rectangle with video as texture');
107+
}
108+
109+
function draw() {
110+
background(0);
111+
112+
// 绕 y 轴旋转。
113+
rotateY(frameCount * 0.01);
114+
115+
// 将视频应用为纹理。
116+
texture(vid);
117+
118+
// 绘制矩形。
119+
rect(-40, -40, 80, 80);
120+
}
121+
</code>
122+
</div>
123+
124+
<div>
125+
<code>
126+
let vid;
127+
128+
// 加载一个视频并创建一个 p5.MediaElement 对象。
129+
function preload() {
130+
vid = createVideo('/assets/fingers.mov');
131+
}
132+
133+
function setup() {
134+
createCanvas(100, 100, WEBGL);
135+
136+
// 隐藏视频。
137+
vid.hide();
138+
139+
// 设置视频循环播放。
140+
vid.loop();
141+
142+
describe('A rectangle with video as texture');
143+
}
144+
145+
function draw() {
146+
background(0);
147+
148+
// 绕 y 轴旋转。
149+
rotateY(frameCount * 0.01);
150+
151+
// 设置纹理模式。
152+
textureMode(NORMAL);
153+
154+
// 将视频应用为纹理。
155+
texture(vid);
156+
157+
// 使用 uv 坐标绘制自定义形状。
158+
beginShape();
159+
vertex(-40, -40, 0, 0);
160+
vertex(40, -40, 1, 0);
161+
vertex(40, 40, 1, 1);
162+
vertex(-40, 40, 0, 1);
163+
endShape();
164+
}
165+
</code>
166+
</div>
167+
class: p5
168+
params:
169+
- name: tex
170+
description: |
171+
<p>将媒体用作纹理。</p>
172+
type: >-
173+
p5.Image|p5.MediaElement|p5.Graphics|p5.Texture|p5.Framebuffer|p5.FramebufferTexture
174+
chainable: true
175+
---
176+
177+
178+
# texture

0 commit comments

Comments
 (0)