Ejemplo n.º 1
0
    def test_remove(self):
        root = scsdk_native.Node()
        root.name = "root"

        child1 = scsdk_native.Node()
        child1.name = "child1"

        child2 = scsdk_native.Node()
        child2.name = "child2"

        grandchild2 = scsdk_native.Node()
        grandchild2.name = "grandchild2"

        root.appendChild(child1)
        root.appendChild(child2)

        child2.appendChild(grandchild2)

        child2.removeChild(grandchild2)

        self.assertEqual(child2.numChildren(), 0)

        scsdk_native.Node.remove(root, child1)
        self.assertEqual(root.numChildren(), 1)

        children = list(root.children())
        self.assertEqual(children[0], child2)
Ejemplo n.º 2
0
    def test_visibility(self):
        n = scsdk_native.Node()
        n.visibility = False
        self.assertEqual(n.visibility, False)

        n.visibility = True
        self.assertEqual(n.visibility, True)
Ejemplo n.º 3
0
    def test_transform(self):
        n = scsdk_native.Node()

        n.transform = np.array([[2, 0, 0, 0.9], [0, 9, 0, 0.1],
                                [0, 0, 13, 0.3]])
        self.assertTrue(
            np.allclose(
                n.transform,
                np.array([[2, 0, 0, 0.9], [0, 9, 0, 0.1], [0, 0, 13, 0.3]])))
Ejemplo n.º 4
0
    def test_material(self):
        n = scsdk_native.Node()

        n.material.objectColor = np.array([1.0, 0.2, 0.3])
        n.material.materialModel = scsdk_native.MaterialModel.Phong

        self.assertEqual(n.material.materialModel,
                         scsdk_native.MaterialModel.Phong)
        self.assertTrue(
            np.allclose(n.material.objectColor, np.array([1.0, 0.2, 0.3])))
Ejemplo n.º 5
0
    def test_all(self):
        root = scsdk_native.Node()
        root.name = "root"

        filename = tempfile.NamedTemporaryFile(mode='w', delete=True)
        scsdk_native.WriteSceneGraphToGltf(root, filename.name)

        with open(filename.name, 'r') as file:
            data = file.read().replace('\n', '')

            readRoot = scsdk_native.ReadSceneGraphFromGltf(data)[0]
            self.assertEqual(readRoot.name, "root")
Ejemplo n.º 6
0
    def test_child(self):
        root = scsdk_native.Node()
        root.name = "root"

        child1 = scsdk_native.Node()
        child1.name = "child1"

        child2 = scsdk_native.Node()
        child2.name = "child2"

        grandchild2 = scsdk_native.Node()
        grandchild2.name = "grandchild2"

        self.assertTrue(root.appendChild(child1))
        self.assertTrue(root.appendChild(child2))

        self.assertTrue(child2.appendChild(grandchild2))

        self.assertEqual(root.numChildren(), 2)
        self.assertEqual(child1.numChildren(), 0)
        self.assertEqual(child2.numChildren(), 1)
        self.assertEqual(grandchild2.numChildren(), 0)

        children = list(root.children())

        self.assertEqual(children[0], child1)
        self.assertEqual(children[1], child2)

        children = list(child2.children())
        self.assertEqual(children[0], grandchild2)

        children = list(root.children())

        self.assertEqual(children[0], child1)
        self.assertEqual(children[1], child2)

        children = list(child2.children())
        self.assertEqual(children[0], grandchild2)
Ejemplo n.º 7
0
 def test_name(self):
     n = scsdk_native.Node()
     n.name = "foo"
     self.assertEqual(n.name, "foo")
Ejemplo n.º 8
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

import numpy as np
from scsdk import scsdk_native as scsdk
from PIL import Image

# This script demonstrates a bunch of the different node types in a SceneGraph

root = scsdk.Node()
root.name = "root"

# geometry node, that repsents a geometry that is a single triangle.
child1 = scsdk.GeometryNode()
child1.name = "triangle1"
child1.geometry.positions = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]])
child1.geometry.normals = np.array([[0, 0, 1], [0, 0, 1], [0, 0, 1]])
child1.geometry.colors = np.array([[1, 0, 0], [1, 0, 0], [0, 1, 0]])
child1.geometry.faces = np.array([[0, 1, 2]])
child1.transform = np.array([[1, 0, 0, -3.0], [0, 1, 0, 0], [0, 0, 1, 0]])
root.appendChild(child1)

# geometry node, that repsents a geometry that is a point cloud.
# since no faces are specified, it is considered a point cloud.
pointcloud = scsdk.GeometryNode()
Ejemplo n.º 9
0
import sys
import numpy as np
from scsdk import scsdk_native
import pywavefront

# This script convert the Stanford bunny into a SceneGraph

# root node
root = scsdk_native.Node()
root.name = "root"

# geometry node.
childNode = scsdk_native.GeometryNode()
root.appendChild(childNode)
childNode.name = "bunny"

x_position = 0.3
y_position = 1.2
z_position = 0.7
childNode.transform = np.array([[1, 0, 0, x_position], [0, 1, 0, y_position],
                                [0, 0, 1, z_position]])

rabbitObj = pywavefront.Wavefront('./bunny.obj')

for name, material in rabbitObj.materials.items():
    assert ("N3F_V3F" == material.vertex_format)

    numVertices = int(len(material.vertices) / 6)
    numFaces = int(numVertices / 3)

    positions = np.zeros((numVertices, 3))