scale_collada.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (c) 2019, 2020 Naoki Hiraoka
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. Neither the name of the Kei Okada nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 
30 from collada import *
31 from urdf_parser_py.urdf import *
32 from tf.transformations import *
33 import copy
34 import os
35 import sys
36 import math
37 import numpy
38 import argparse
39 
40 
41 def scale_node(node, scale):
42  transforms = node.transforms
43  node.transforms = []
44  for transform in transforms:
45  transform.matrix[:3, 3] *= scale
46  node.transforms.append(scene.MatrixTransform(transform.matrix.reshape(16, 1)))
47  node.matrix = numpy.identity(4, dtype=numpy.float32)
48  for t in node.transforms:
49  node.matrix = numpy.dot(node.matrix, t.matrix)
50 
51  for child in node.children:
52  if isinstance(child, scene.Node):
53  scale_node(child, scale)
54 
55 
56 def scale_geometry(geometry, scale):
57  position_ids = set()
58  for primitive in geometry.primitives:
59  for _input in primitive.getInputList().getList():
60  if _input[1] == "VERTEX":
61  position_ids.add(_input[2][1:]) # remove '#'
62  for position_id in position_ids:
63  geometry.sourceById[position_id].data *= scale
64 
65 
66 def scale_collada(mesh_, scale):
67  scale_node(mesh_.scene.nodes[0], scale)
68  for geometry in mesh_.geometries:
69  scale_geometry(geometry, scale)
70 
71  mesh_.assetInfo.unitname = 'meter'
72  mesh_.assetInfo.unitmeter = 1.0
73  mesh_.save()
def scale_geometry(geometry, scale)
def scale_collada(mesh_, scale)
def scale_node(node, scale)


gundam_rx78_description
Author(s): Association GUNDAM GLOBAL CHALLENGE, Kei Okada , Naoki Hiraoka
autogenerated on Wed Sep 2 2020 03:33:36