我想为gltf中不同的mesh赋予不同的材质,但是我创建两个mesh后,后面的mesh会不显示
请大牛们帮忙解答
下面是python代码,用的pygltflib包
import numpy as np
import pygltflib
from pygltflib.utils import ImageFormat, Image
# Define mesh using numpy:
points = np.array(
[
[0, 0, 0],
[10, 0, 0],
[0, 10, 0],
[0, 0, 10],
[0, 0, 10],
[10, 0, 10],
[0, 10, 10],
[0, 0, 20],
],
dtype="float32",
)
points1 = np.array(
[
[0, 0, 0],
[10, 0, 0],
[0, 10, 0],
[0, 0, 10],
],
dtype="float32",
)
points2 = np.array(
[
[0, 0, 10],
[10, 0, 10],
[0, 10, 10],
[0, 0, 20],
],
dtype="float32",
)
triangles = np.array(
[
[0, 2, 1],
[0, 3, 2],
[0, 1, 3],
[1, 2, 3],
[4, 6, 5],
[4, 7, 6],
[4, 5, 7],
[5, 6, 7]
],
dtype="uint8",
)
triangles1 = np.array(
[
[0, 2, 1],
[0, 3, 2],
[0, 1, 3],
[1, 2, 3],
],
dtype="uint8",
)
triangles2 = np.array(
[
[4, 6, 5],
[4, 7, 6],
[4, 5, 7],
[5, 6, 7]
],
dtype="uint8",
)
# Create glb-style GLTF2 with single scene, single node and single mesh from arrays of points and triangles:
triangles_binary_blob = triangles.flatten().tobytes()
triangles1_binary_blob = triangles1.flatten().tobytes()
triangles2_binary_blob = triangles2.flatten().tobytes()
points_binary_blob = points.tobytes()
points1_binary_blob = points1.tobytes()
points2_binary_blob = points2.tobytes()
gltf = pygltflib.GLTF2(
scene=0,
scenes=[pygltflib.Scene(nodes=[0])],
nodes=[pygltflib.Node(mesh=0)],
meshes=[
pygltflib.Mesh(
primitives=[
pygltflib.Primitive(
attributes=pygltflib.Attributes(POSITION=1), indices=0
),
pygltflib.Primitive(
attributes=pygltflib.Attributes(POSITION=3), indices=2
)
],
)
],
accessors=[
pygltflib.Accessor(
bufferView=0,
componentType=pygltflib.UNSIGNED_BYTE,
count=triangles1.size,
type=pygltflib.SCALAR,
max=[int(triangles1.max())],
min=[int(triangles1.min())],
),
pygltflib.Accessor(
bufferView=1,
componentType=pygltflib.FLOAT,
count=len(points1),
type=pygltflib.VEC3,
max=points1.max(axis=0).tolist(),
min=points1.min(axis=0).tolist(),
),
pygltflib.Accessor(
bufferView=0,
componentType=pygltflib.UNSIGNED_BYTE,
byteOffset=len(triangles1_binary_blob),
count=triangles2.size,
type=pygltflib.SCALAR,
max=[int(triangles2.max())],
min=[int(triangles2.min())],
),
pygltflib.Accessor(
bufferView=1,
componentType=pygltflib.FLOAT,
byteOffset=len(points1_binary_blob),
count=len(points2),
type=pygltflib.VEC3,
max=points2.max(axis=0).tolist(),
min=points2.min(axis=0).tolist(),
),
],
bufferViews=[
pygltflib.BufferView(
buffer=0,
byteLength=len(triangles_binary_blob),
target=pygltflib.ELEMENT_ARRAY_BUFFER,
),
pygltflib.BufferView(
buffer=0,
byteOffset=len(triangles_binary_blob),
byteLength=len(points_binary_blob),
target=pygltflib.ARRAY_BUFFER,
),
],
buffers=[
pygltflib.Buffer(
byteLength=len(triangles_binary_blob) + len(points_binary_blob)
)
],
)
gltf.set_binary_blob(triangles_binary_blob + points_binary_blob)
gltf.save("test07.gltf")



