예제 #1
0
파일: simple.py 프로젝트: KingAbbott/devsyn
  def draw_leaf(self, position, vector_list, scale = 0.125):
    # use the vectors that describe the direction the branch grows
    # to make the right rotation matrix
    new_cs = Mat4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
    new_cs.setRow(0, vector_list[2]) # right
    new_cs.setRow(1, vector_list[1]) # up
    new_cs.setRow(2, vector_list[0]) # forward
    new_cs.setRow(3, Vec3(0, 0, 0))
    new_cs.setCol(3, Vec4(0, 0, 0, 1))

    axis_adjustment = Mat4.scaleMat(scale) * new_cs * Mat4.translateMat(position)

    leaf_model = base.loader.loadModelCopy(APP_PATH + 'media/models/shrubbery')
    leaf_texture = base.loader.loadTexture(APP_PATH + 'media/models/material-10-cl.png')

    leaf_model.reparentTo(self.get_model())
    leaf_model.setTexture(leaf_texture, 1)
    leaf_model.setTransform(TransformState.makeMat(axis_adjustment))
def drawLeaf(nodePath,vdata,pos=Vec3(0,0,0),vecList=[Vec3(0,0,1), Vec3(1,0,0),Vec3(0,-1,0)], scale=0.125):
	
	#use the vectors that describe the direction the branch grows to make the right 
		#rotation matrix
	newCs=Mat4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
	newCs.setRow(0, vecList[2]) #right
	newCs.setRow(1, vecList[1]) #up
	newCs.setRow(2, vecList[0]) #forward
	newCs.setRow(3, Vec3(0,0,0))
	newCs.setCol(3,Vec4(0,0,0,1))

	axisAdj=Mat4.scaleMat(scale)*newCs*Mat4.translateMat(pos)	
	
	#orginlly made the leaf out of geometry but that didnt look good
	#I also think there should be a better way to handle the leaf texture other than
	#hardcoding the filename
	leafModel=loader.loadModelCopy('models/shrubbery')
	leafTexture=loader.loadTexture('models/material-10-cl.png')


	leafModel.reparentTo(nodePath)
	leafModel.setTexture(leafTexture,1)
	leafModel.setTransform(TransformState.makeMat(axisAdj))